module documentation

babel.messages.frontend ~~~~~~~~~~~~~~~~~~~~~~~ Frontends for the message extraction functionality. :copyright: (c) 2013-2023 by the Babel Team. :license: BSD, see LICENSE for more details.

Class Command Undocumented
Class CommandLineInterface 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.
Variable log Undocumented
Function _make_directory_filter Build a directory_filter function based on a list of ignore patterns.
def check_message_extractors(dist, name, value): (source)

Validate the ``message_extractors`` keyword argument to ``setup()``. :param dist: the distutils/setuptools ``Distribution`` object :param name: the name of the keyword argument (should always be "message_extractors") :param value: the value of the keyword argument :raise `DistutilsSetupError`: if the value is not valid

def listify_value(arg, split=None): (source)

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'] :param arg: A string or a list of strings :param split: The argument to pass to `str.split()`. :return:

def main(): (source)

Undocumented

def parse_keywords(strings: Iterable[str] = ()): (source)

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): (source)

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/*.*'] {} :param fileobj: a readable file-like object containing the configuration text to parse :see: `extract_from_directory`

Undocumented

def _make_directory_filter(ignore_patterns): (source)

Build a directory_filter function based on a list of ignore patterns.