예제 #1
0
def _isrc_short(name=None):
    """
    Creates the grammar for a short ISRC code.

    ISRC stands for International Standard Recording Code, which is the
    standard ISO 3901. This stores information identifying a particular
    recording.

    This variant contains separator for the parts, and follows the pattern:
    CC-XXX-YY-NN

    Where each code means:
    - CC: country code
    - XXX: registrant
    - YY: year
    - NN: work id

    :param name: name for the field
    :return: grammar for an ISRC field
    """

    config = CWRTables()

    if name is None:
        name = 'ISRC Field'

    # separator = pp.Literal('-')
    country = config.get_data('isrc_country_code')
    # registrant = basic.alphanum(3)
    # year = pp.Regex('[0-9]{2}')
    # work_id = pp.Regex('[0-9]{2}')

    country_regex = ''
    for c in country:
        if len(country_regex) > 0:
            country_regex += '|'
        country_regex += c
    country_regex = '(' + country_regex + ')'

    # field = pp.Regex(country_regex + '-.{3}-[0-9]{2}-[0-9]{2}')
    field = pp.Regex('[A-Z0-9]{2}-.{3}[0-9]{2}-[0-9]{5}')
    # field = pp.Regex('[^ ]+')

    # country.setName('ISO-2 Country Code')
    # registrant.setName('Registrant')
    # year.setName('Year')
    # work_id.setName('Work ID')

    field.setName(name)

    return field.setResultsName('isrc')
예제 #2
0
def _isrc_short(name=None):
    """
    Creates the grammar for a short ISRC code.

    ISRC stands for International Standard Recording Code, which is the
    standard ISO 3901. This stores information identifying a particular
    recording.

    This variant contains separator for the parts, and follows the pattern:
    CC-XXX-YY-NN

    Where each code means:
    - CC: country code
    - XXX: registrant
    - YY: year
    - NN: work id

    :param name: name for the field
    :return: grammar for an ISRC field
    """

    config = CWRTables()

    if name is None:
        name = 'ISRC Field'

    # separator = pp.Literal('-')
    country = config.get_data('isrc_country_code')
    # registrant = basic.alphanum(3)
    # year = pp.Regex('[0-9]{2}')
    # work_id = pp.Regex('[0-9]{2}')

    country_regex = ''
    for c in country:
        if len(country_regex) > 0:
            country_regex += '|'
        country_regex += c
    country_regex = '(' + country_regex + ')'

    field = pp.Regex(country_regex + '-.{3}-[0-9]{2}-[0-9]{2}')

    # country.setName('ISO-2 Country Code')
    # registrant.setName('Registrant')
    # year.setName('Year')
    # work_id.setName('Work ID')

    field.setName(name)

    return field.setResultsName('isrc')
예제 #3
0
def default_file_encoder():
    """
    Get default encoder cwr file
    :return:
    """
    config = CWRConfiguration()
    field_configs = config.load_field_config('table')
    field_configs.update(config.load_field_config('common'))

    field_values = CWRTables()

    for entry in field_configs.values():
        if 'source' in entry:
            values_id = entry['source']
            entry['values'] = field_values.get_data(values_id)

    record_configs = config.load_record_config('common')
    return CwrFileEncoder(record_configs, field_configs)
예제 #4
0
파일: file.py 프로젝트: weso/CWR-DataApi
def default_file_encoder():
    """
    Get default encoder cwr file
    :return:
    """
    config = CWRConfiguration()
    field_configs = config.load_field_config('table')
    field_configs.update(config.load_field_config('common'))

    field_values = CWRTables()

    for entry in field_configs.values():
        if 'source' in entry:
            values_id = entry['source']
            entry['values'] = field_values.get_data(values_id)

    record_configs = config.load_record_config('common')
    return CwrFileEncoder(record_configs, field_configs)
예제 #5
0
def default_filename_grammar_factory():
    config = CWRConfiguration()

    data = config.load_field_config('filename')
    field_values = CWRTables()

    for entry in list(data.values()):
        if 'source' in entry:
            values_id = entry['source']
            entry['values'] = field_values.get_data(values_id)

    factory_field = FieldRuleFactory(data, default_adapters())

    optional_decorator = OptionalFieldRuleDecorator(data, default_adapters())

    return DefaultRuleFactory(
        _process_rules(config.load_record_config('filename')),
        factory_field,
        optional_decorator
    )
예제 #6
0
def _isrc_long(name=None):
    """
    Creates the grammar for a short ISRC code.

    ISRC stands for International Standard Recording Code, which is the
    standard ISO 3901. This stores information identifying a particular
    recording.

    This variant contain no separator for the parts, and follows the pattern:
    CCXXXYYNNNNN

    Where each code means:
    - CC: country code
    - XXX: registrant
    - YY: year
    - NNNNN: work id

    :param name: name for the field
    :return: grammar for an ISRC field
    """

    config = CWRTables()

    if name is None:
        name = 'ISRC Field'

    country = basic.lookup(config.get_data('isrc_country_code'))
    registrant = basic.alphanum(3)
    year = pp.Regex('[0-9]{2}')
    work_id = pp.Regex('[0-9]{5}')

    field = pp.Combine(country + registrant + year + work_id)

    country.setName('ISO-2 Country Code')
    registrant.setName('Registrant')
    year.setName('Year')
    work_id.setName('Work ID')

    field.setName(name)

    return field.setResultsName('isrc')
예제 #7
0
def default_grammar_factory():
    config = CWRConfiguration()

    data = config.load_field_config('table')
    data.update(config.load_field_config('common'))

    field_values = CWRTables()

    for entry in list(data.values()):
        if 'source' in entry:
            values_id = entry['source']
            entry['values'] = field_values.get_data(values_id)

    factory_field = FieldRuleFactory(data, default_adapters())

    optional_decorator = OptionalFieldRuleDecorator(data, default_adapters())

    rules = _process_rules(config.load_record_config('common'))
    rules.update(_process_rules(config.load_transaction_config('common')))
    rules.update(_process_rules(config.load_group_config('common')))

    decorators = {'transaction_record': TransactionRecordRuleDecorator(
        factory_field,
        _default_record_decoders()
    ),
        'record': RecordRuleDecorator(
            factory_field,
            _default_record_decoders()
        ),
        'group': GroupRuleDecorator(_default_group_decoders())}
    return DefaultRuleFactory(
        rules,
        factory_field,
        optional_decorator,
        decorators
    )
예제 #8
0
파일: table.py 프로젝트: ralic/CWR-DataApi
ASCII) apply.

All the values are read from the lists contained in the library, through the
CWRTables class.
"""

__author__ = 'Bernardo Martínez Garrido'
__license__ = 'MIT'
__status__ = 'Development'

"""
Configuration classes.
"""

# Acquires data sources
_tables = CWRTables()
_config = CWRConfiguration()

"""
Fields.
"""


def char_code(columns, name=None):
    """
    Character set code field.

    :param name: name for the field
    :return: an instance of the Character set code field rules
    """
    if name is None: