pology.message.Message_base

Package pology :: Module message :: Class Message_base |

# Class Message_base

    object --+
             |
            Message_base

Known Subclasses:
  - Message
  - , MessageUnsafe

Abstract base class for entries in PO catalogs.

Elements of the message are accessed through instance attributes. Some of them are read-only, typically those that are derived from the normal read-write attributes and cannot be set independently.

The precise type of each attribute depends on the subclass through which it is accessed, but has a general behavior of one of the standard types. E.g. when the behavior is that of a list, the type is stated as `list*`. All strings are assumed unicode, except where noted otherwise.

Regardless of the exact composition of the message, each message object will have all the instance attributes listed. In case the message actually does not have an element corresponding to an instance attribute, that attribute will have an appropriate null value.

Only the read-only attributes are provided by this base class, while the read-write attributes are to be provided by its subclasses. All are listed here, however, as the interface that all subclasses should implement.

See Also:
  Message, MessageUnsafe

Instance Methods
__init__(self, getsetattr) Internal constructor for subclasses' usage. |
__getattr__(self, att) Attribute getter. |
get(self, att, default=None) Get attribute value. |
__setattr__(self, att, val) Attribute setter. |
bool |
__eq__(self, omsg) Reports whether messages are equal in all apparent parts. |
bool |
__ne__(self, omsg) Reports whether messages are not equal in some apparent parts. |
list of strings |
to_lines(self, wrapf=<function wrap_field at 0x2b887d0>, force=False, colorize=0) The line-representation of the message. |
to_string(self, wrapf=<function wrap_field at 0x2b887d0>, force=False, colorize=0) The string-representation of the message. |
unfuzzy(self) Thoroughly unfuzzy the message. |
clear(self, keepmanc=False, msgstrlen=None) Revert message to pristine untranslated state. |
string |
state(self) Coded description of the translation state of the message. |
set(self, omsg) Copy all parts from the other message. |
set_key(self, omsg) Copy all key parts from the other message. |
set_fmt(self, omsg) Copy all format parts from the other message. |
set_inv(self, omsg) Copy extraction-invariant parts from the other message. |
Inherited from `object`: `__delattr__`, `__format__`, `__getattribute__`, `__hash__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__repr__`, `__sizeof__`, `__str__`, `__subclasshook__`

Instance Variables
bool | active (read-only) whether the translation of the message is used at destination (`False` for untranslated, fuzzy and obsolete messages)
list* of strings | auto_comment automatic (extracted) comments (`#. ...`)
set* of strings | flag message flags (`#, ...`)
string | fmt (read-only) format composition
string | format (read-only) the format flag of the message (e.g.
bool | fuzzy whether the message is fuzzy
string | inv (read-only) extraction-invariant composition
string | key (read-only) key composition
| key_previous (read-only) previous key composition
list* of strings | manual_comment manual (translator) comments (`# ...`)
string or None | msgctxt context field (`msgctxt "..."`)
string or None | msgctxt_previous previous context field (`#| msgctxt "..."`)
string | msgid message field (`msgid "..."`)
string or None | msgid_plural plural field (`msgid_plural "..."`)
string or None | msgid_plural_previous previous plural field (`#| msgid_plural "..."`)
string or None | msgid_previous previous message field (`#| msgid "..."`)
list* of strings | msgstr translation fields (`msgstr "..."`, `msgstr[n] "..."`)
bool | obsolete whether entry is obsolete (`#~ ...`)
int | refentry referent entry number of the message inside the catalog
int | refline referent line number of the message inside the catalog
list* of pairs* | source source references, as filepath:lineno pairs (`#: ...`)
bool | translated (read-only) whether the message is translated (False for fuzzy messages)
string | trn (read-only) translator-controlled composition
bool | untranslated (read-only) whether the message is untranslated (False for fuzzy messages)

Properties
Inherited from `object`: `__class__`

Method Details

### __init__(self, getsetattr) (Constructor) |
Internal constructor for subclasses' usage. Parameters: `getsetattr` - the object with `__getattr__` and `__setattr__` methods, as handler for unhandled instance attributes Overrides: object.__init__

### __getattr__(self, att) (Qualification operator) |
Attribute getter. Processes read-only attributes, and sends others to the getter given by the constructor. Parameters: `att` - name of the attribute to get Returns: attribute value

### get(self, att, default=None) |
Get attribute value. Allows accessing the message like a dictionary. Parameters: `att` (string) - name of the attribute to get `default` - value to return if attribute does not exist Returns: value of the attribute or the default value

### __setattr__(self, att, val) |
Attribute setter. May act upon some attributes (e.g. checks), but finally passes all of them to the setter given by the constructor. Parameters: `att` - name of the attribute to set `val` - value to set the attribute to Overrides: object.__setattr__

### __eq__(self, omsg) (Equality operator) |
Reports whether messages are equal in all apparent parts. "Apparent" parts include all those which are visible in the PO file. I.e. the check will ignore internal states, like line caches, etc. Returns: bool `True` if messages are equal in apparent parts

### __ne__(self, omsg) |
Reports whether messages are not equal in some apparent parts. Equivalent to `not (self == omsg)`. Returns: bool `False` if messages are equal in all apparent parts

### to_lines(self, wrapf=<function wrap_field at 0x2b887d0>, force=False, colorize=0) |
The line-representation of the message. Lines are returned with newlines included. Parameters: `wrapf` (string, string, string -> list of strings) - the function used for wrapping message fields (msgctxt, msgid, ...) As arguments the function should accept the field name, the field text, and the prefix to all lines, and return the list of wrapped lines (with newlines included). `force` (bool) - whether to force reformatting of all elements. Subclasses may keep a track of lines exactly as read from the PO file, and allow reformatting of only the modified elements of the message. `colorize` (int) - whether and how much to colorize the message. Typically useful when the message is output to terminal, HTML file, etc. as accompanying information to a user. If the value is 0, no colorization is applied; 1 gives conservative colorization, 2 and more full colorization. Returns: list of strings formatted lines See Also: pology.wrap

### to_string(self, wrapf=<function wrap_field at 0x2b887d0>, force=False, colorize=0) |
The string-representation of the message. Passes the arguments to to_lines and joins the resulting list. See Also: to_lines

### unfuzzy(self) |
Thoroughly unfuzzy the message. Strictly speaking, a message is fuzzy if it has the `fuzzy` flag set. Thus a message can be unfuzzied by removing this flag, either manually from the `flag` set, or through attribute `fuzzy`. But if there were previous fields (e.g. `msgid_previous`) added to the message when it was made fuzzy on merge, they will remain in the message after it has been unfuzzied in this way. This is normally not wanted, and in such cases this method may be used to thouroughly unfuzzy the message: remove `fuzzy` flag, set `fuzzy` attribute to `False`, and all `*_previous` attributes to `None`. If the message is not strictly fuzzy upon this call, it is undefined whether any present previous fields will be left untouched, or removed nontheless. Returns: True if the message was unfuzzied, false otherwise

### clear(self, keepmanc=False, msgstrlen=None) |
Revert message to pristine untranslated state. Reverting to untranslated state removes manual comments (by default), `fuzzy` flag, and previous fields, and clears `msgstr` fields. Parameters: `keepmanc` (bool) - do not remove manual comments `msgstrlen` (int) - the number of empty msgstr fields; if `None`, the existing number of fields is preserved

### state(self) |
Coded description of the translation state of the message. Code string can be one of: "T" (translated), "F" (fuzzy), "U" (untranslated), "OT" (obsolete translated), "OF" (obsolete fuzzy), "OU" (obsolete untranslated). Returns: string coded translation state

### set(self, omsg) |
Copy all parts from the other message. All mutable parts are deeply copied. Parameters: `omsg` (instance of Message_base) - the message from which to copy the parts Returns: self

### set_key(self, omsg) |
Copy all key parts from the other message. See key attribute for the description and list of key parts. All mutable parts are deeply copied. Parameters: `omsg` (instance of Message_base) - the message from which to copy the parts Returns: self

### set_fmt(self, omsg) |
Copy all format parts from the other message. See fmt attribute for the description and list of format parts. All mutable parts are deeply copied. Parameters: `omsg` (instance of Message_base) - the message from which to copy the parts Returns: self

### set_inv(self, omsg) |
Copy extraction-invariant parts from the other message. See inv attribute for the description and list of extraction-invariant parts. All mutable parts are deeply copied. Parameters: `omsg` (instance of Message_base) - the message from which to copy the parts Returns: self

Instance Variable Details

### fmt (read-only) format composition Format composition consists of all message parts which determine contents of compiled message in the MO file, including whether it is compiled at all. The value is an undefined serialization of: `msgctxt`, `msgid`, `msgid_plural`, `msgstr`, `fuzzy`, `obsolete`. Type: string

### format (read-only) the format flag of the message (e.g. `c-format`) or empty string Type: string

### fuzzy whether the message is fuzzy The state of fuzziness can be also checked and set by looking for and adding/removing the `fuzzy` flag from the set of flags, but this is needed frequently enough to deserve a standalone attribute. Note: To "thoroughly" unfuzzy the message, see method unfuzzy. Type: bool

### inv (read-only) extraction-invariant composition Extraction-invariant parts of the message are those that are not dependent on the placement and comments to the message in the code. In effect, these are the parts which are not eliminated when the message is obsoleted after merging. The value is an undefined serialization of: `msgctxt`, `msgid`, `msgid_plural`, `msgstr`, `fuzzy`, `obsolete`, `manual_comment`, `msgctxt_previous`, `msgid_previous`, `msgid_plural_previous`. Type: string

### key (read-only) key composition Message key is formed by the parts of the message which define unique entry in a catalog. The value is an undefined serialization of `msgctxt` and `msgid`. Type: string

### key_previous (read-only) previous key composition Like key, except this is for previous fields. If there are no previous fields, this is `None`. The value is an undefined serialization of `msgctxt_previous` and `msgid_previous`.

### refentry referent entry number of the message inside the catalog Valid only if there were no additions/removals of messages from the catalog, otherwise undefined (made valid again after syncing the catalog). Type: int

### refline referent line number of the message inside the catalog Valid only if there were no modifications to the catalog, otherwise undefined (made valid again after syncing the catalog). Normally this is the line number of `msgid` keyword, but not guaranteed to be so. Type: int

### trn (read-only) translator-controlled composition Translator-controlled parts of the message are those that are normally modified by a translator when working on a PO file. The value is an undefined serialization of: `msgstr`, `fuzzy`, `manual_comment`. Type: string