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

Class _BaseFile

source code

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

Common base class for the :class:`~polib.POFile` and :class:`~polib.MOFile` classes. This class should **not** be instanciated directly.

Instance Methods [hide private]
new empty list
__init__(self, *args, **kwargs)
Constructor, accepts the following keyword arguments:
source code
 
__unicode__(self)
Returns the unicode representation of the file.
source code
 
__str__(self)
Returns the string representation of the file.
source code
 
__contains__(self, entry)
Overriden ``list`` method to implement the membership test (in and not in).
source code
 
__eq__(self, other)
x==y
source code
 
append(self, entry)
Overriden method to check for duplicates entries, if a user tries to add an entry that is already in the file, the method will raise a ``ValueError`` exception.
source code
 
insert(self, index, entry)
Overriden method to check for duplicates entries, if a user tries to add an entry that is already in the file, the method will raise a ``ValueError`` exception.
source code
 
metadata_as_entry(self)
Returns the file metadata as a :class:`~polib.POFile` instance.
source code
 
save(self, fpath=None, repr_method='__unicode__')
Saves the po file to ``fpath``.
source code
 
find(self, st, by='msgid', include_obsolete_entries=False, msgctxt=False)
Find the entry which msgid (or property identified by the ``by`` argument) matches the string ``st``.
source code
 
ordered_metadata(self)
Convenience method that returns an ordered version of the metadata dictionary.
source code
 
to_binary(self)
Return the binary representation of the file.
source code
 
_encode(self, mixed)
Encodes the given ``mixed`` argument with the file encoding if and only if it's an unicode string and returns the encoded string.
source code

Inherited from list: __add__, __delitem__, __delslice__, __ge__, __getattribute__, __getitem__, __getslice__, __gt__, __iadd__, __imul__, __iter__, __le__, __len__, __lt__, __mul__, __ne__, __new__, __repr__, __reversed__, __rmul__, __setitem__, __setslice__, __sizeof__, count, extend, index, 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, *args, **kwargs)
(Constructor)

source code 

Constructor, accepts the following keyword arguments:

``pofile``
    string, the path to the po or mo file, or its content as a string.

``wrapwidth``
    integer, the wrap width, only useful when the ``-w`` option was
    passed to xgettext (optional, default: ``78``).

``encoding``
    string, the encoding to use, defaults to ``default_encoding``
    global variable (optional).

``check_for_duplicates``
    whether to check for duplicate entries when adding entries to the
    file, (optional, default: ``False``).

Returns: new empty list
Overrides: object.__init__

__str__(self)
(Informal representation operator)

source code 

Returns the string representation of the file.

Overrides: object.__str__

__contains__(self, entry)
(In operator)

source code 

Overriden ``list`` method to implement the membership test (in and
not in).
The method considers that an entry is in the file if it finds an entry
that has the same msgid (the test is **case sensitive**) and the same
msgctxt (or none for both entries).

Argument:

``entry``
    an instance of :class:`~polib._BaseEntry`.

Overrides: list.__contains__

__eq__(self, other)
(Equality operator)

source code 

x==y

Overrides: list.__eq__
(inherited documentation)

append(self, entry)

source code 

Overriden method to check for duplicates entries, if a user tries to
add an entry that is already in the file, the method will raise a
``ValueError`` exception.

Argument:

``entry``
    an instance of :class:`~polib._BaseEntry`.

Overrides: list.append

insert(self, index, entry)

source code 

Overriden method to check for duplicates entries, if a user tries to
add an entry that is already in the file, the method will raise a
``ValueError`` exception.

Arguments:

``index``
    index at which the entry should be inserted.

``entry``
    an instance of :class:`~polib._BaseEntry`.

Overrides: list.insert

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

source code 

Saves the po file to ``fpath``.
If it is an existing 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', include_obsolete_entries=False, msgctxt=False)

source code 

Find the entry which msgid (or property identified by the ``by``
argument) matches the string ``st``.

Keyword arguments:

``st``
    string, the string to search for.

``by``
    string, the property to use for comparison (default: ``msgid``).

``include_obsolete_entries``
    boolean, whether to also search in entries that are obsolete.

``msgctxt``
    string, allows to specify a specific message context for the
    search.

ordered_metadata(self)

source code 

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