Skip to content

Commit

Permalink
General improvments
Browse files Browse the repository at this point in the history
  • Loading branch information
hkupty committed Aug 20, 2014
1 parent 3bac7b9 commit c8cb4d2
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions cnab240/registro.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ def __new__(cls, **kwargs):

_c = ((None, None),)


for Campo in cls._campos_cls.values():
campo = Campo()
x = ((campo.nome, campo), )
Expand Down Expand Up @@ -202,12 +201,11 @@ def __init__(self, specs_dirpath):
# default (zeros se numerico ou brancos se alfa)
registro_filepath_list = iglob(os.path.join(specs_dirpath, '*.json'))

_make_class = self.criar_classe_registro
for registro_filepath in registro_filepath_list:
registro_file = open(registro_filepath)
spec = json.load(registro_file)
registro_file.close()

setattr(self, spec.get('nome'), self.criar_classe_registro(spec))
with open(registro_filepath) as registro_file:
spec = json.load(registro_file)
setattr(self, spec.get('nome'), _make_class(spec))


def criar_classe_registro(self, spec):
Expand All @@ -216,10 +214,15 @@ def criar_classe_registro(self, spec):
cls_name = spec.get('nome').encode('utf8')

campo_specs = spec.get('campos', {})

_c = ((None, None),)

for key in sorted(campo_specs.iterkeys()):
Campo = criar_classe_campo(campo_specs[key])
entrada = {Campo.nome: Campo}
entrada = ((Campo.nome, Campo), )

_c += entrada

campos.update(entrada)
campos.update(_c[1:])

return type(cls_name, (RegistroBase, ), attrs)

0 comments on commit c8cb4d2

Please sign in to comment.