Package pology :: Module header :: Class Header

Class Header

         object --+    
                  |    
monitored.Monitored --+
                      |
                     Header

Header entry in PO catalogs.

The PO header is syntactically just another entry in the catalog, but with different semantics. Therefore, instead operating on it using Message, this class provides a different set of interface attributes and methods.

Like Message, this class implements monitoring; the starred-types (e.g. list*) are according to the same convention as for messages, and also the strings are assumed unicode unless otherwise noted.

There is no lightweight alternative to the monitored header, like that of MessageUnsafe for messages, because no performance demand is expected for the headers only.


See Also: Message

Instance Methods
 
__init__(self, init=None)
Initializes the header by the given message or header.
 
__getattr__(self, att)
Attribute getter.
 
get(self, att, default=None)
Get attribute value.
bool
__eq__(self, ohdr)
Reports wheter headers are equal in all apparent parts.
bool
__ne__(self, ohdr)
Reports wheter headers are not equal in some apparent parts.
the type that initialized the object
to_msg(self, force=False)
Convert the header into ordinary message object.
 
to_lines(self, wrapf=<function wrap_field at 0x7f7182815320>, force=False)
The line-representation of the header.
 
to_string(self, wrapf=<function wrap_field at 0x7f7182815320>, force=False)
The string-representation of the header.
list of pairs*
select_fields(self, name)
Find header fields with the given name.
string or default
get_field_value(self, name, default=None)
Get the value of the given header field.
bool
replace_field_value(self, name, new_value, nth=0)
Replace the value of the n-th occurence of the named header field.
int
set_field(self, name, value, after=None, before=None, reorder=False)
Set a header field to a value.
int
remove_field(self, name)
Remove header fields with the given name, if it exists.

Inherited from monitored.Monitored: __setattr__, assert_spec_getattr, assert_spec_getitem, assert_spec_init, assert_spec_setattr, assert_spec_setitem, data

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __sizeof__, __str__, __subclasshook__

Instance Variables
list* of strings author
comment lines stating translators who worked on this catalog
list* of strings comment
the free comment lines, being none of the specific ones
string copyright
comment line with the copyright statement
list* of pairs* field
parsed header fields as key-value string pairs
bool initialized
(read-only) whether the header is fully initialized
string license
comment line with the license statement
list* of strings title
comment lines giving the title
Properties

Inherited from object: __class__

Method Details

__init__(self, init=None)
(Constructor)

 

Initializes the header by the given message or header.

Parameters:
  • init (subclass of Message_base, or Header) - the PO entry containing the header, or another header
Overrides: object.__init__

__getattr__(self, att)
(Qualification operator)

 

Attribute getter.

Processes read-only attributes, and sends others to the base class.

Parameters:
  • att - name of the attribute to get
Returns:
attribute value
Overrides: monitored.Monitored.__getattr__

get(self, att, default=None)

 

Get attribute value.

Allows accessing the header like a dictionary.

Parameters:
  • att (string) - name of the attribute to get
  • default - value to return if the attribute does not exist
Returns:
value of the attribute or the default value

__eq__(self, ohdr)
(Equality operator)

 

Reports wheter headers 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 headers are equal in apparent parts
Overrides: monitored.Monitored.__eq__

__ne__(self, ohdr)

 

Reports wheter headers are not equal in some apparent parts.

Equivalent to not (self == ohdr).

Returns: bool
False if headers are equal in all apparent parts
Overrides: monitored.Monitored.__ne__

to_msg(self, force=False)

 

Convert the header into ordinary message object.

The message object returned may be the modification of the one passed to the constructor. In that case, and if the message object has monitoring features, the force parameter will tell whether to modify all message elements, or to try to keep the changes minimal.

Parameters:
  • force (bool) - whether to recreate all message elements
Returns: the type that initialized the object
header as message

to_lines(self, wrapf=<function wrap_field at 0x7f7182815320>, force=False)

 

The line-representation of the header.

Equivalent to the same-named method of message classes.

See Also: Message_base

to_string(self, wrapf=<function wrap_field at 0x7f7182815320>, force=False)

 

The string-representation of the header.

Equivalent to the same-named method of message classes.

See Also: Message_base

select_fields(self, name)

 

Find header fields with the given name.

Header fields need not be unique.

Parameters:
  • name (string) - look for the fields with this name
Returns: list of pairs*
references to name-value pairs matching the field name

get_field_value(self, name, default=None)

 

Get the value of the given header field.

If there are several fields with the same name, it is undefined which of them will supply the value; this method should be used only for fields which are expected to be unique. If there are no fields named as requested, default is returned.

Parameters:
  • name (string) - field name
  • default (as given) - value returned if there is no such field
Returns: string or default
field value

replace_field_value(self, name, new_value, nth=0)

 

Replace the value of the n-th occurence of the named header field.

Header fields need not be unique, hence the n-th qualification.

Parameters:
  • name (string) - name of the header field
  • new_value (string) - new value for the field
  • nth (int) - replace the value of this field among same-named fields
Returns: bool
True if the requested field was found, False otherwise

set_field(self, name, value, after=None, before=None, reorder=False)

 

Set a header field to a value.

If the field already exists, its value is replaced with the given one. If there are several same-named fields, it is undefined which one and how many of them are going to have their values replaced; this method should be used only for fields expected to be unique. If there is no such field yet, it is inserted into the header; after the field after or before the field before if given and existing, or appended to the end otherwise. If the field already exists, but not in the position according to after or before, reordering can be requested too.

Parameters:
  • name (unicode) - name of the header field
  • value (unicode) - new value for the field
  • after (string) - the field to insert after
  • before (string) - the field to insert before
  • reorder (bool) - whether to move an existing field into better position
Returns: int
position where the field was modified or inserted

remove_field(self, name)

 

Remove header fields with the given name, if it exists.

Parameters:
  • name (string) - remove fields with this name
Returns: int
number of removed fields