Пример #1
0
def filename_version(values, name=None):
    field = lookup(values, name)

    default_version = CWRConfiguration().default_version()

    # Parse action
    field.addParseAction(lambda n: default_version)

    return field
Пример #2
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)
Пример #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
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
    )
Пример #5
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
    )
Пример #6
0
from cwr.grammar.factory.rule import FieldRuleFactory
from config_cwr.accessor import CWRConfiguration
from cwr.grammar.field.record import record_prefix
from cwr.parser.decoder.file import default_adapters

"""
CWR file Record parsing tests.
"""

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

# Acquires data sources
_config = CWRConfiguration()
_common_factory = FieldRuleFactory(_config.load_field_config('common'),
                                   default_adapters())


class TestParseTransactionRecordPrefixValid(unittest.TestCase):
    """
    Tests that RecordPrefixDecoder decodes correctly formatted strings
    """

    def setUp(self):
        self.grammar = record_prefix('HDR', _common_factory)

    def test_valid(self):
        """
        Tests that RecordPrefixDecoder decodes correctly formatted record prefixes.
Пример #7
0
def example_acknowledge_file(sequence_n, reciver):
    config = CWRConfiguration()
    return AcknowledgeFile(config.load_acknowledge_config('example'),
                           sequence_n, reciver)
Пример #8
0
from cwr.grammar.field import basic
from config_cwr.accessor import CWRConfiguration
from data_cwr.accessor import CWRTables
"""
Grammar for special cases and other fields.

These are miscellany fields and nodes, such as line limiters, or the character
encoding field.
"""

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

# Acquires data sources
_config = CWRConfiguration()

# GENERAL GRAMMAR

lineStart = pp.lineStart.suppress()
lineStart.setName("Start of line")

lineEnd = pp.lineEnd.suppress()
lineEnd.setName("End of line")

# CONCRETE CASES FIELDS


def ipi_base_number(name=None):
    """
    IPI Base Number field.
Пример #9
0
from pyparsing import ParseException

from cwr.grammar.factory.rule import FieldRuleFactory
from config_cwr.accessor import CWRConfiguration
from cwr.grammar.field.record import record_prefix
from cwr.parser.decoder.file import default_adapters
"""
CWR file Record parsing tests.
"""

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

# Acquires data sources
_config = CWRConfiguration()
_common_factory = FieldRuleFactory(_config.load_field_config('common'),
                                   default_adapters())


class TestParseTransactionRecordPrefixValid(unittest.TestCase):
    """
    Tests that RecordPrefixDecoder decodes correctly formatted strings
    """
    def setUp(self):
        self.grammar = record_prefix('HDR', _common_factory)

    def test_valid(self):
        """
        Tests that RecordPrefixDecoder decodes correctly formatted record prefixes.
        """