module documentation

Frontends for the message extraction functionality.

Unknown Field: copyright
  1. 2013-2021 by the Babel Team.
Unknown Field: license
BSD, see LICENSE for more details.
Variable po​_file​_read​_mode Undocumented
Class ​Command Undocumented
Class ​Command​Line​Interface Command-line interface.
Class compile​_catalog Catalog compilation command for use in setup.py scripts.
Class extract​_messages Message extraction command for use in setup.py scripts.
Class init​_catalog New catalog initialization command for use in setup.py scripts.
Class update​_catalog Catalog merging command for use in setup.py scripts.
Function check​_message​_extractors Validate the message_extractors keyword argument to setup().
Function listify​_value Make a list out of an argument.
Function main Undocumented
Function parse​_keywords Parse keywords specifications from the given list of strings.
Function parse​_mapping Parse an extraction method mapping from a file-like object.
po_file_read_mode =

Undocumented

def check_message_extractors(dist, name, value):
Validate the message_extractors keyword argument to setup().
Parameters
distthe distutils/setuptools Distribution object
namethe name of the keyword argument (should always be "message_extractors")
valuethe value of the keyword argument
Raises
DistutilsSetupErrorif the value is not valid
def listify_value(arg, split=None):

Make a list out of an argument.

Values from distutils argument parsing are always single strings; values from optparse parsing may be lists of strings that may need to be further split.

No matter the input, this function returns a flat list of whitespace-trimmed strings, with None values filtered out.

>>> listify_value("foo bar")
['foo', 'bar']
>>> listify_value(["foo bar"])
['foo', 'bar']
>>> listify_value([["foo"], "bar"])
['foo', 'bar']
>>> listify_value([["foo"], ["bar", None, "foo"]])
['foo', 'bar', 'foo']
>>> listify_value("foo, bar, quux", ",")
['foo', 'bar', 'quux']
Parameters
argA string or a list of strings
splitThe argument to pass to str.split().
Returns
def main():

Undocumented

def parse_keywords(strings=[]):

Parse keywords specifications from the given list of strings.

>>> kw = sorted(parse_keywords(['_', 'dgettext:2', 'dngettext:2,3', 'pgettext:1c,2']).items())
>>> for keyword, indices in kw:
...     print((keyword, indices))
('_', None)
('dgettext', (2,))
('dngettext', (2, 3))
('pgettext', ((1, 'c'), 2))
def parse_mapping(fileobj, filename=None):

Parse an extraction method mapping from a file-like object.

>>> buf = StringIO('''
... [extractors]
... custom = mypackage.module:myfunc
...
... # Python source files
... [python: **.py]
...
... # Genshi templates
... [genshi: **/templates/**.html]
... include_attrs =
... [genshi: **/templates/**.txt]
... template_class = genshi.template:TextTemplate
... encoding = latin-1
...
... # Some custom extractor
... [custom: **/custom/*.*]
... ''')
>>> method_map, options_map = parse_mapping(buf)
>>> len(method_map)
4
>>> method_map[0]
('**.py', 'python')
>>> options_map['**.py']
{}
>>> method_map[1]
('**/templates/**.html', 'genshi')
>>> options_map['**/templates/**.html']['include_attrs']
''
>>> method_map[2]
('**/templates/**.txt', 'genshi')
>>> options_map['**/templates/**.txt']['template_class']
'genshi.template:TextTemplate'
>>> options_map['**/templates/**.txt']['encoding']
'latin-1'
>>> method_map[3]
('**/custom/*.*', 'mypackage.module:myfunc')
>>> options_map['**/custom/*.*']
{}
Parameters
fileobja readable file-like object containing the configuration text to parse
filenameUndocumented
See Also
extract_from_directory