Back to index

plone3  3.1.7
Public Member Functions | Public Attributes
statusmessages.message.Message Class Reference

List of all members.

Public Member Functions

def __init__
def __eq__
def encode

Public Attributes

 message
 type

Detailed Description

A single status message.

Let's make sure that this implementation actually fulfills the
'IMessage' API.

  >>> from zope.interface.verify import verifyClass
  >>> verifyClass(IMessage, Message)
  True

  >>> status = Message(u'this is a test', type=u'info')
  >>> status.message
  u'this is a test'

  >>> status.type
  u'info'

It is quite common to use MessageID's as status messages:

  >>> from zope.i18nmessageid import MessageFactory
  >>> from zope.i18nmessageid import Message as I18NMessage
  >>> msg_factory = MessageFactory('test')

  >>> msg = msg_factory(u'test_message', default=u'Default text')

  >>> status = Message(msg, type=u'warn')
  >>> status.type
  u'warn'

  >>> type(status.message) is I18NMessage
  True

  >>> status.message.default
  u'Default text'

  >>> status.message.domain
  'test'

Definition at line 19 of file message.py.


Constructor & Destructor Documentation

def statusmessages.message.Message.__init__ (   self,
  message,
  type = '' 
)

Definition at line 60 of file message.py.

00060 
00061     def __init__(self, message, type=''):
00062         self.message = message
00063         self.type = type


Member Function Documentation

def statusmessages.message.Message.__eq__ (   self,
  other 
)

Definition at line 64 of file message.py.

00064 
00065     def __eq__(self, other):
00066         if not isinstance(other, Message):
00067             return False
00068         if self.message == other.message and self.type == other.type:
00069             return True
00070         return False

Encode to a cookie friendly format.

The format consists of a two bytes length header of 11 bits for the
message length and 5 bits for the type length followed by two values.

Definition at line 71 of file message.py.

00071 
00072     def encode(self):
00073         """
00074         Encode to a cookie friendly format.
00075         
00076         The format consists of a two bytes length header of 11 bits for the
00077         message length and 5 bits for the type length followed by two values.
00078         """
00079         message = _utf8(self.message)[:0x3FF] # we can store 2^11 bytes
00080         type = _utf8(self.type)[:0x1F]        # we can store 2^5 bytes
00081         size = (len(message) << 5) + (len(type) & 31) # pack into 16 bits
00082         
00083         return struct.pack('!H%ds%ds' % (len(message), len(type)), 
00084                            size, message, type)

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 61 of file message.py.

Definition at line 62 of file message.py.


The documentation for this class was generated from the following file: