Skip to content

Commit

Permalink
Merge pull request #45 from Bernardo-MG/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Bernardo-MG committed May 12, 2015
2 parents 8db15bf + f8467bb commit bd9fd21
Show file tree
Hide file tree
Showing 32 changed files with 842 additions and 57 deletions.
2 changes: 1 addition & 1 deletion cwr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
:license: MIT, see LICENSE for more details.
"""

__version__ = '0.0.15'
__version__ = '0.0.16'
__license__ = 'MIT'
10 changes: 10 additions & 0 deletions cwr/acknowledgement.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,16 @@ def __init__(self, ack, agr=None, nwr=None, rev=None, exc=None, messages=None):
else:
self._messages = messages

def __str__(self):
return '%s [agr=%r, nwr=%r, rev=%r, exc=%r, messages=%r]' % (
'Acnowledgement Transaction', self._agr,
self._nwr, self._rev, self._exc, self._messages)

def __repr__(self):
return '<class %s>(agr=%r, nwr=%r, rev=%r, exc=%r, messages=%r)' % (
self.__class__.__name__, self._agr,
self._nwr, self._rev, self._exc, self._messages)

@property
def ack(self):
"""
Expand Down
11 changes: 6 additions & 5 deletions cwr/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def __str__(self):

def __repr__(self):
return '<class %s>(tag=%r, transmission=%r)' % (
'CWRFile', self._tag,
self.__class__.__name__, self._tag,
self._transmission)

@property
Expand Down Expand Up @@ -118,10 +118,11 @@ def __str__(self):
self._version)

def __repr__(self):
return '<class %s>(year=%s, sequence_n=%r, sender=%r, receiver=%r, version=%r)' % ('FileTag', self._year,
self._sequence_n,
self._sender, self._receiver,
self._version)
return '<class %s>(year=%s, sequence_n=%r, sender=%r, receiver=%r, version=%r)' % (
self.__class__.__name__, self._year,
self._sequence_n,
self._sender, self._receiver,
self._version)

@property
def year(self):
Expand Down
100 changes: 95 additions & 5 deletions cwr/grammar/factory/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@
"""
CWR fields grammar adapters.
These classes allow the factories to create rules in an homogeneous way.
These classes allow the factories to create rules in an homogeneous way, by setting a basic interface which will wrap
around field rules, giving a basic common method through which rules can be created.
This interface is the FieldAdapter, having only the get_field method, which will receive a series of parameters, all
of them optional, and generate a field rule from them. The concrete rule will depend on the implementation.
Additionally, it offers the wrap_as_optional method, which allows setting a field as optional. It is meant to be used
with a field created by the adapter, so it can be overriden for specific fields.
"""

__author__ = 'Bernardo Martínez Garrido'
Expand All @@ -19,9 +26,10 @@

class FieldAdapter(object):
"""
Instances of this class generate field rules.
Interface for adapting field rules creation to the parser factory requirements.
This serves as an adapter so the different field rules use the same parameters.
This is meant to receive always the same, or similar, groups of values, and then generate a specific field rule
from them.
"""
__metaclass__ = ABCMeta

Expand All @@ -36,7 +44,7 @@ def get_field(self, name=None, columns=None, values=None):
:param name: the name of the field
:param columns: number of columns
:param values: allowed values for the field
:return: the rules for the field
:return: the rule for the field
"""
raise NotImplementedError("The get_field method is not implemented")

Expand Down Expand Up @@ -114,6 +122,12 @@ def get_field(self, name=None, columns=None, values=None):


class NumericAdapter(FieldAdapter):
"""
Creates the grammar for a Numeric (N) field, accepting only the specified number of characters.
This version only allows integers.
"""

def __init__(self):
super(NumericAdapter, self).__init__()

Expand All @@ -122,6 +136,10 @@ def get_field(self, name=None, columns=None, values=None):


class BooleanAdapter(FieldAdapter):
"""
Creates the grammar for a Boolean (B) field, accepting only 'Y' or 'N'
"""

def __init__(self):
super(BooleanAdapter, self).__init__()

Expand All @@ -130,6 +148,10 @@ def get_field(self, name=None, columns=None, values=None):


class FlagAdapter(FieldAdapter):
"""
Creates the grammar for a Flag (F) field, accepting only 'Y', 'N' or 'U'.
"""

def __init__(self):
super(FlagAdapter, self).__init__()

Expand All @@ -138,6 +160,10 @@ def get_field(self, name=None, columns=None, values=None):


class DateAdapter(FieldAdapter):
"""
Creates the grammar for a Date (D) field, accepting only numbers in a certain pattern.
"""

def __init__(self):
super(DateAdapter, self).__init__()

Expand Down Expand Up @@ -180,6 +206,10 @@ def wrap_as_optional(self, field, name, columns):


class TimeAdapter(FieldAdapter):
"""
Creates the grammar for a Time (D) field, accepting only numbers in a certain pattern.
"""

def __init__(self):
super(TimeAdapter, self).__init__()

Expand All @@ -188,6 +218,11 @@ def get_field(self, name=None, columns=None, values=None):


class DateTimeAdapter(FieldAdapter):
"""
Creates the grammar for a date and time field, which is a combination of the Date (D) and Time or Duration field (T)
.
"""

def __init__(self):
super(DateTimeAdapter, self).__init__()

Expand All @@ -196,6 +231,12 @@ def get_field(self, name=None, columns=None, values=None):


class BlankAdapter(FieldAdapter):
"""
Creates the grammar for a blank field.
These are for constant empty strings which should be ignored, as they are used just as fillers.
"""

def __init__(self):
super(BlankAdapter, self).__init__()

Expand All @@ -204,14 +245,22 @@ def get_field(self, name=None, columns=None, values=None):


class LookupAdapter(FieldAdapter):
"""
Creates the grammar for a Lookup (L) field, accepting only values from a list.
"""

def __init__(self):
super(LookupAdapter, self).__init__()

def get_field(self, name=None, columns=None, values=None):
return basic.lookup(values, columns, name)
return basic.lookup(values, name)


class ISWCAdapter(FieldAdapter):
"""
ISWC field.
"""

def __init__(self):
super(ISWCAdapter, self).__init__()

Expand All @@ -220,6 +269,10 @@ def get_field(self, name=None, columns=None, values=None):


class IPIBaseNumberAdapter(FieldAdapter):
"""
IPI Base Number field.
"""

def __init__(self):
super(IPIBaseNumberAdapter, self).__init__()

Expand All @@ -228,6 +281,10 @@ def get_field(self, name=None, columns=None, values=None):


class IPINameNumberAdapter(FieldAdapter):
"""
IPI Name Number field.
"""

def __init__(self):
super(IPINameNumberAdapter, self).__init__()

Expand All @@ -236,6 +293,11 @@ def get_field(self, name=None, columns=None, values=None):


class PercentageAdapter(FieldAdapter):
"""
Creates the grammar for a Numeric (N) field storing a percentage and accepting only the specified number of
characters.
"""

def __init__(self):
super(PercentageAdapter, self).__init__()

Expand All @@ -249,6 +311,10 @@ def get_field(self, name=None, columns=None, values=None):


class EAN13Adapter(FieldAdapter):
"""
Creates the grammar for an EAN 13 code.
"""

def __init__(self):
super(EAN13Adapter, self).__init__()

Expand All @@ -257,6 +323,10 @@ def get_field(self, name=None, columns=None, values=None):


class ISRCAdapter(FieldAdapter):
"""
Creates the grammar for an ISRC code.
"""

def __init__(self):
super(ISRCAdapter, self).__init__()

Expand All @@ -265,6 +335,10 @@ def get_field(self, name=None, columns=None, values=None):


class VISANAdapter(FieldAdapter):
"""
Creates the grammar for a V-ISAN code.
"""

def __init__(self):
super(VISANAdapter, self).__init__()

Expand All @@ -273,6 +347,10 @@ def get_field(self, name=None, columns=None, values=None):


class AudioVisualKeydapter(FieldAdapter):
"""
Creates the grammar for an Audio Visual Key code.
"""

def __init__(self):
super(AudioVisualKeydapter, self).__init__()

Expand All @@ -281,6 +359,10 @@ def get_field(self, name=None, columns=None, values=None):


class CharSetAdapter(FieldAdapter):
"""
Character set code field.
"""

def __init__(self):
super(CharSetAdapter, self).__init__()

Expand All @@ -289,6 +371,10 @@ def get_field(self, name=None, columns=None, values=None):


class VariableAlphanumAdapter(FieldAdapter):
"""
Creates the grammar for an alphanumeric code where the size ranges between two values.
"""

def __init__(self):
super(VariableAlphanumAdapter, self).__init__()

Expand All @@ -302,6 +388,10 @@ def get_field(self, name=None, columns=None, values=None):


class NumericFloatAdapter(FieldAdapter):
"""
Creates the grammar for a Numeric (N) field, accepting only the specified number of characters.
"""

def __init__(self):
super(NumericFloatAdapter, self).__init__()

Expand Down
12 changes: 7 additions & 5 deletions cwr/grammar/factory/decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@


"""
Record fields factories.
Decorators for the grammar rules.
These serve to adapt a basic set of rules for a certain type of work. For example, for converting a group of rules
into the rule for a record.
This works through the basic interface RuleDecorator, which will receive the rule, and any required additional data, and
return the adapted rule.
"""

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

"""
Configuration classes.
"""


class RuleDecorator(object):
__metaclass__ = ABCMeta
Expand Down
4 changes: 0 additions & 4 deletions cwr/grammar/factory/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
__license__ = 'MIT'
__status__ = 'Development'

"""
Configuration classes.
"""


class FieldTerminalRuleFactory(TerminalRuleFactory):
"""
Expand Down
14 changes: 3 additions & 11 deletions cwr/grammar/field/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,6 @@ def numeric(columns, name=None):
This version only allows integers.
This can be a compulsory field, in which case the zero is disallowed.
:param columns: number of columns for this field
:param name: name for the field
:return: grammar for the integer numeric field
Expand Down Expand Up @@ -268,7 +266,7 @@ def _check_above_value_float(string, minimum):

def boolean(name=None):
"""
Creates the grammar for a Boolean (F) field, accepting only 'Y' or 'N'
Creates the grammar for a Boolean (B) field, accepting only 'Y' or 'N'
:param name: name for the field
:return: grammar for the flag field
Expand Down Expand Up @@ -378,8 +376,6 @@ def date(name=None):
"""
Creates the grammar for a Date (D) field, accepting only numbers in a certain pattern.
The field can be compulsory, in which case the empty date, composed only of zeros, is disallowed.
:param name: name for the field
:return: grammar for the date field
"""
Expand Down Expand Up @@ -417,7 +413,7 @@ def date(name=None):

def time(name=None):
"""
Creates the grammar for a Time (D) field, accepting only numbers in a certain pattern.
Creates the grammar for a Time or Duration (T) field, accepting only numbers in a certain pattern.
:param name: name for the field
:return: grammar for the date field
Expand Down Expand Up @@ -449,16 +445,12 @@ def time(name=None):
"""


def lookup(values, columns=1, name=None):
def lookup(values, name=None):
"""
Creates the grammar for a Lookup (L) field, accepting only values from a list.
The 'columns' parameter is used only in the case the field is optional. It will be used to indicate the number
of whitespaces this field can take.
Like in the Alphanumeric field, the result will be stripped of all heading and trailing whitespaces.
:param columns: number of columns, for the case this field is left empty
:param name: name for the field
:return: grammar for the lookup field
"""
Expand Down
Loading

0 comments on commit bd9fd21

Please sign in to comment.