Package zope :: Package i18nmessageid :: Module message :: Class Message
[show private | hide private]
[frames | no frames]

Type Message

object --+        
         |        
basestring --+    
             |    
       unicode --+
                 |
                Message


Message (Python implementation)

This is a string used as a message. It has a domain attribute that is its source domain, and a default attribute that is its default text to display when there is no translation. domain may be None meaning there is no translation domain. default may also be None, in which case the message id itself implicitly serves as the default text.

These are the doc tests from message.txt. Note that we have to create the message manually since MessageFactory would return the C implementation.

>>> from zope.i18nmessageid.message import pyMessage as Message
>>> robot = Message(u"robot-message", 'futurama', u"${name} is a robot.")
>>> robot
u'robot-message'
>>> isinstance(robot, unicode)
True
>>> robot.default
u'${name} is a robot.'
>>> robot.mapping
>>> 

Only the python implementation has a _readonly attribute >>> robot._readonly True

>>> robot.domain = "planetexpress"
Traceback (most recent call last):
...
TypeError: readonly attribute
>>> robot.default = u"${name} is not a robot."
Traceback (most recent call last):
...
TypeError: readonly attribute
>>> robot.mapping = {u'name': u'Bender'}
Traceback (most recent call last):
...
TypeError: readonly attribute
>>> new_robot = Message(robot, mapping={u'name': u'Bender'})
>>> new_robot
u'robot-message'
>>> new_robot.domain
'futurama'
>>> new_robot.default
u'${name} is a robot.'
>>> new_robot.mapping
{u'name': u'Bender'}
>>> callable, args = new_robot.__reduce__()
>>> callable is Message
True
>>> args
(u'robot-message', 'futurama', u'${name} is a robot.', {u'name': u'Bender'})
>>> fembot = Message(u'fembot')
>>> callable, args = fembot.__reduce__()
>>> callable is Message
True
>>> args
(u'fembot', None, None, None)

Change classes for pickle tests >>> import zope.i18nmessageid.message >>> oldMessage = zope.i18nmessageid.message.Message >>> zope.i18nmessageid.message.Message = Message

At first check if pickling and unpicklung from pyMessage to pyMessage works >>> from pickle import dumps, loads >>> pystate = dumps(new_robot) >>> pickle_bot = loads(pystate) >>> pickle_bot, pickle_bot.domain, pickle_bot.default, pickle_bot.mapping (u'robot-message', 'futurama', u'${name} is a robot.', {u'name': u'Bender'}) >>> pickle_bot._readonly True >>> from zope.i18nmessageid.message import pyMessage >>> pickle_bot.__reduce__()[0] is pyMessage True >>> del pickle_bot

At second check if cMessage is able to load the state of a pyMessage >>> from _zope_i18nmessageid_message import Message >>> zope.i18nmessageid.message.Message = Message >>> c_bot = loads(pystate) >>> c_bot, c_bot.domain, c_bot.default, c_bot.mapping (u'robot-message', 'futurama', u'${name} is a robot.', {u'name': u'Bender'}) >>> c_bot._readonly Traceback (most recent call last): AttributeError: 'zope.i18nmessageid.message.Message' object has no attribute '_readonly' >>> from _zope_i18nmessageid_message import Message as cMessage >>> c_bot.__reduce__()[0] is cMessage True

At last check if pyMessage can load a state of cMessage >>> cstate = dumps(c_bot) >>> del c_bot >>> from zope.i18nmessageid.message import pyMessage as Message >>> zope.i18nmessageid.message.Message = Message >>> py_bot = loads(cstate) >>> py_bot, py_bot.domain, py_bot.default, py_bot.mapping (u'robot-message', 'futurama', u'${name} is a robot.', {u'name': u'Bender'}) >>> py_bot._readonly True >>> py_bot.__reduce__()[0] is pyMessage True

Both pickle states should be equal >>> pystate == cstate True

Finally restore classes for other unit tests >>> zope.i18nmessageid.message.Message = oldMessage


Method Summary
  __getstate__(self)
  __new__(cls, ustr, domain, default, mapping)
(Static method)
  __reduce__(self)
  __setattr__(self, key, value)
Message is immutable
    Inherited from unicode
  __add__(x, y)
x.__add__(y) <==> x+y
  __cmp__(x, y)
x.__cmp__(y) <==> cmp(x,y)
  __contains__(x, y)
x.__contains__(y) <==> y in x
  __getattribute__(...)
x.__getattribute__('name') <==> x.name
  __getitem__(x, y)
x.__getitem__(y) <==> x[y]
  __getnewargs__(...)
  __getslice__(x, i, j)
Use of negative indices is not supported.
  __hash__(x)
x.__hash__() <==> hash(x)
  __len__(x)
x.__len__() <==> len(x)
  __mod__(x, y)
x.__mod__(y) <==> x%y
  __mul__(x, n)
x.__mul__(n) <==> x*n
  __repr__(x)
x.__repr__() <==> repr(x)
  __rmod__(x, y)
x.__rmod__(y) <==> y%x
  __rmul__(x, n)
x.__rmul__(n) <==> n*x
  __str__(x)
x.__str__() <==> str(x)
  capitalize(S)
Return a capitalized version of S, i.e.
  center(S, width, fillchar)
Return S centered in a Unicode string of length width.
  count(S, sub, start, end)
Return the number of occurrences of substring sub in Unicode string S[start:end].
  decode(S, encoding, errors)
Decodes S using the codec registered for encoding.
  encode(S, encoding, errors)
Encodes S using the codec registered for encoding.
  endswith(S, suffix, start, end)
Return True if S ends with the specified suffix, False otherwise.
  expandtabs(S, tabsize)
Return a copy of S where all tab characters are expanded using spaces.
  find(S, sub, start, end)
Return the lowest index in S where substring sub is found, such that sub is contained within s[start,end].
  index(S, sub, start, end)
Like S.find() but raise ValueError when the substring is not found.
  isalnum(S)
Return True if all characters in S are alphanumeric and there is at least one character in S, False otherwise.
  isalpha(S)
Return True if all characters in S are alphabetic and there is at least one character in S, False otherwise.
  isdecimal(S)
Return True if there are only decimal characters in S, False otherwise.
  isdigit(S)
Return True if all characters in S are digits and there is at least one character in S, False otherwise.
  islower(S)
Return True if all cased characters in S are lowercase and there is at least one cased character in S, False otherwise.
  isnumeric(S)
Return True if there are only numeric characters in S, False otherwise.
  isspace(S)
Return True if all characters in S are whitespace and there is at least one character in S, False otherwise.
  istitle(S)
Return True if S is a titlecased string and there is at least one character in S, i.e.
  isupper(S)
Return True if all cased characters in S are uppercase and there is at least one cased character in S, False otherwise.
  join(S, sequence)
Return a string which is the concatenation of the strings in the sequence.
  ljust(S, width, fillchar)
Return S left justified in a Unicode string of length width.
  lower(S)
Return a copy of the string S converted to lowercase.
  lstrip(S, chars)
Return a copy of the string S with leading whitespace removed.
  replace(...)
S.replace (old, new[, maxsplit]) -> unicode
  rfind(S, sub, start, end)
Return the highest index in S where substring sub is found, such that sub is contained within s[start,end].
  rindex(S, sub, start, end)
Like S.rfind() but raise ValueError when the substring is not found.
  rjust(S, width, fillchar)
Return S right justified in a Unicode string of length width.
  rsplit(S, sep, maxsplit)
Return a list of the words in S, using sep as the delimiter string, starting at the end of the string and working to the front.
  rstrip(S, chars)
Return a copy of the string S with trailing whitespace removed.
  split(S, sep, maxsplit)
Return a list of the words in S, using sep as the delimiter string.
  splitlines(...)
S.splitlines([keepends]]) -> list of strings
  startswith(S, prefix, start, end)
Return True if S starts with the specified prefix, False otherwise.
  strip(S, chars)
Return a copy of the string S with leading and trailing whitespace removed.
  swapcase(S)
Return a copy of S with uppercase characters converted to lowercase and vice versa.
  title(S)
Return a titlecased version of S, i.e.
  translate(S, table)
Return a copy of the string S, where all characters have been mapped through the given translation table, which must be a mapping of Unicode ordinals to Unicode ordinals, Unicode strings or None.
  upper(S)
Return a copy of S converted to uppercase.
  zfill(S, width)
Pad a numeric string x with zeros on the left, to fill a field of the specified width.
    Inherited from object
  __init__(...)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
  __delattr__(...)
x.__delattr__('name') <==> del x.name
  __reduce_ex__(...)
helper for pickle

Class Variable Summary
tuple __slots__ = ('domain', 'default', 'mapping', '_readonly'...
member_descriptor default = <member 'default' of 'Message' objects>
member_descriptor domain = <member 'domain' of 'Message' objects>
member_descriptor mapping = <member 'mapping' of 'Message' objects>
member_descriptor _readonly = <member '_readonly' of 'Message' objects>

Instance Method Details

__setattr__(self, key, value)

Message is immutable

It cannot be changed once the message id is created.

Overrides:
__builtin__.object.__setattr__

Class Variable Details

__slots__

Type:
tuple
Value:
('domain', 'default', 'mapping', '_readonly')                          

default

Type:
member_descriptor
Value:
<member 'default' of 'Message' objects>                                

domain

Type:
member_descriptor
Value:
<member 'domain' of 'Message' objects>                                 

mapping

Type:
member_descriptor
Value:
<member 'mapping' of 'Message' objects>                                

_readonly

Type:
member_descriptor
Value:
<member '_readonly' of 'Message' objects>                              

Generated by Epydoc 2.1 on Fri Jun 24 12:01:23 2005 http://epydoc.sf.net