Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(5)  |  Call(4)  |  Derive(0)  |  Import(1)
Parse an extraction method mapping from a file-like object.

>>> buf = BytesIO(b'''
... [extractors]
... custom = mypackage.module:myfunc
...
... # Python source files
... [python: **.py]
...
... # Genshi templates(more...)

        def parse_mapping(fileobj, filename=None):
    """Parse an extraction method mapping from a file-like object.

    >>> buf = BytesIO(b'''
    ... [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`
    """
    extractors = {}
    method_map = []
    options_map = {}

    parser = RawConfigParser()
    parser._sections = odict(parser._sections) # We need ordered sections
    parser.readfp(fileobj, filename)
    for section in parser.sections():
        if section == 'extractors':
            extractors = dict(parser.items(section))
        else:
            method, pattern = [part.strip() for part in section.split(':', 1)]
            method_map.append((pattern, method))
            options_map[pattern] = dict(parser.items(section))

    if extractors:
        for idx, (pattern, method) in enumerate(method_map):
            if method in extractors:
                method = extractors[method]
            method_map[idx] = (pattern, method)

    return (method_map, options_map)
        


src/j/i/jinjet-HEAD/jinjet.py   jinjet(Download)
from datetime import datetime
from babel import dates, numbers, support, Locale
from babel.messages.frontend import parse_mapping
from babel.util import pathmatch
 
def build():
 
    try:
        mappings, _ = parse_mapping(open(cli.babelconf))
    except IOError:

src/f/j/fjord-HEAD/vendor/packages/Babel/tests/messages/test_frontend.py   fjord(Download)
        '[custom: **/custom/*.*]\n')
 
    method_map, options_map = frontend.parse_mapping(buf)
    assert len(method_map) == 4
 

src/z/e/ZenPacks.zenoss.OpenStack-HEAD/src/Babel-1.3/tests/messages/test_frontend.py   ZenPacks.zenoss.OpenStack(Download)
        '[custom: **/custom/*.*]\n')
 
    method_map, options_map = frontend.parse_mapping(buf)
    assert len(method_map) == 4
 

src/b/a/Babel-1.3/tests/messages/test_frontend.py   Babel(Download)
        '[custom: **/custom/*.*]\n')
 
    method_map, options_map = frontend.parse_mapping(buf)
    assert len(method_map) == 4