Module polib :: Class _BaseFile
[hide private]
[frames] | no frames]

Class _BaseFile

source code

object --+    
         |    
      list --+
             |
            _BaseFile
Known Subclasses:

Common parent class for POFile and MOFile classes. This class must **not** be instanciated directly.

Instance Methods [hide private]
new list
__init__(self, fpath=None, wrapwidth=78, encoding='utf-8')
Constructor.
source code
 
__str__(self)
String representation of the file.
source code
 
__repr__(self)
Return the official string representation of the object.
source code
 
metadata_as_entry(self)
Return the metadata as an entry
source code
 
save(self, fpath=None, repr_method='__str__')
Save the po file to file *fpath* if no file handle exists for the object.
source code
 
find(self, st, by='msgid')
Find entry which msgid (or property identified by the *by* attribute) matches the string *st*.
source code
 
ordered_metadata(self)
Convenience method that return the metadata ordered.
source code
 
to_binary(self)
Return the mofile binary representation.
source code

Inherited from list: __add__, __contains__, __delitem__, __delslice__, __eq__, __ge__, __getattribute__, __getitem__, __getslice__, __gt__, __iadd__, __imul__, __iter__, __le__, __len__, __lt__, __mul__, __ne__, __new__, __reversed__, __rmul__, __setitem__, __setslice__, __sizeof__, append, count, extend, index, insert, pop, remove, reverse, sort

Inherited from object: __delattr__, __format__, __reduce__, __reduce_ex__, __setattr__, __subclasshook__

Class Variables [hide private]

Inherited from list: __hash__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, fpath=None, wrapwidth=78, encoding='utf-8')
(Constructor)

source code 

Constructor.

**Keyword arguments**:

  • *fpath*: string, path to po or mo file
  • *wrapwidth*: integer, the wrap width, only useful when -w option was passed to xgettext to generate the po file that was used to format the mo file, default to 78 (optional).
Returns: new list
Overrides: object.__init__

__str__(self)
(Informal representation operator)

source code 

String representation of the file.

Overrides: object.__str__

__repr__(self)
(Representation operator)

source code 

Return the official string representation of the object.

Overrides: object.__repr__

save(self, fpath=None, repr_method='__str__')

source code 

Save the po file to file *fpath* if no file handle exists for the object. If there's already an open file and no fpath is provided, then the existing file is rewritten with the modified data.

**Keyword arguments**:

  • *fpath*: string, full or relative path to the file.
  • *repr_method*: string, the method to use for output.

find(self, st, by='msgid')

source code 

Find entry which msgid (or property identified by the *by* attribute) matches the string *st*.

**Keyword arguments**:

  • *st*: string, the string to search for
  • *by*: string, the comparison attribute

**Examples**:

>>> po = pofile('tests/test_utf8.po')
>>> entry = po.find('Thursday')
>>> entry.msgstr
u'Jueves'
>>> entry = po.find('Some unexistant msgid')
>>> entry is None
True
>>> entry = po.find('Jueves', 'msgstr')
>>> entry.msgid
u'Thursday'

ordered_metadata(self)

source code 

Convenience method that return the metadata ordered. The return value is list of tuples (metadata name, metadata_value).