コード例 #1
0
def sid_to_dict(sid):

    templates = []

    for name, pattern in six.iteritems(sid_templates):
        template = Template(
            name,
            pattern,
            anchor=lucidity.Template.ANCHOR_BOTH,
            default_placeholder_expression=
            '[^/]*',  # allows for empty keys // should it be '[^|]*' ?
            duplicate_placeholder_mode=lucidity.Template.STRICT)
        # template.template_resolver = resolvers
        templates.append(template)

    try:
        """
        if len(sid.split('/')) >= 8:
            data = []
            for ext in sid.split('/')[-1].split(','):
                sid_copy = sid
                sid_copy = sid_copy.replace(sid_copy.split('/')[-1], ext)
                data.extend(lucidity.parse(str(sid_copy), templates)[0])
        else:
        """
        data, template = lucidity.parse(str(sid), templates)

        # print 'found', data, template
    except Exception as e:
        warn(e)
        return None

    if not data:
        return None
    '''
    for key in list(data.keys()):
        if key not in shot_keys + asset_keys:
            data.pop(key)
    '''
    # return template.name, data  # need the name ?
    return data
コード例 #2
0
def path_to_dict(path):

    path = str(path)
    # path = os.path.normcase(path)
    path = path.replace(os.sep, '/')

    templates = []
    for name, pattern in six.iteritems(path_templates):
        template = Template(
            name,
            pattern,
            anchor=lucidity.Template.ANCHOR_BOTH,
            default_placeholder_expression=
            '[^/]*',  # needed to use '#' for a path
            duplicate_placeholder_mode=lucidity.Template.STRICT)
        template.template_resolver = resolvers

        templates.append(template)

    try:
        data, template = lucidity.parse(path, templates)
        # print 'found', data, template
    except Exception as e:
        warn(e)
        return None, None

    if not data:
        return None, None
    for key, value in six.iteritems(data):
        if path_mapping.get(key):
            value = path_mapping.get(key).get(value, value)
            data[key] = value

    for key in list(data.keys()):
        if key not in shot_keys + asset_keys:
            data.pop(key)

    return template.name, data  # need the name ?
コード例 #3
0
ファイル: test_lucidity.py プロジェクト: 4degrees/lucidity
def test_unsuccessfull_parse(templates):
    '''Unsuccessful parse of path against multiple candidate templates.'''
    with pytest.raises(lucidity.ParseError):
        lucidity.parse('/not/matching', templates)
コード例 #4
0
ファイル: test_lucidity.py プロジェクト: 4degrees/lucidity
def test_successfull_parse(path, expected, templates):
    '''Parse path successfully against multiple candidate templates.'''
    data, template = lucidity.parse(path, templates)
    assert data == expected
コード例 #5
0
def test_unsuccessfull_parse(templates):
    '''Unsuccessful parse of path against multiple candidate templates.'''
    with pytest.raises(lucidity.ParseError):
        lucidity.parse('/not/matching', templates)
コード例 #6
0
def test_successfull_parse(path, expected, templates):
    '''Parse path successfully against multiple candidate templates.'''
    data, template = lucidity.parse(path, templates)
    assert data == expected