In [ ]:
from Util.HOFs import *
from Util.DataPatterns import *
from Util.warehouse import DATATYPES_NATURAL

In [ ]:
#line = """0120 1 #TELA"""
line = """0130  2 #CAMPO-ALFA                    (A78)"""
#line = """0430  2 #CAMPO-MULTIPLO                (A03/1:5)"""
match = DataPatterns.row_pattern.match(l472(line).lstrip())
match = match.groupdict()
match

In [ ]:
ancestors = []
def_lda = '''lda = {'''

In [ ]:
def set_init(match):
    type = None if not match.get('type', None) else match['type']
    init = None if not match.get('init', None) else match['init']
    if type:
        if not init:
            init = DATATYPES_NATURAL[type]['init']
    else:
        init = '{'
    return init

In [ ]:
init = None if not match.get('init', None) else match['init']
not init

In [ ]:
spc = ''

In [ ]:
def dictionarize(match, spc):
    init = set_init(match)
    ac1 = '[' if match['occurs'] else ''
    fc1 = ']' if match['occurs'] else ''
    ac2 = '[' if match['two_dimension'] else ''
    fc2 = ']' if match['two_dimension'] else ''
    comma = '' if init == '{' else ','
    attrb = """{}'{}': {}{}{}{}{}{}\n""".format(spc, match['name'], ac1, ac2, init, fc1, fc2, comma)
    return attrb, init

In [ ]:
dda = 'lda'
attrb, init = dictionarize(match, spc)
if init == '{':
    spc = ' ' * (len(match['name'])+12)
comp = 'def_{} += attrb'.format(dda)
exec compile(comp, '', 'exec')  
print def_lda

In [ ]:
def_lda = '''lda = {'''
attrb = """'#TELA': {"""
dda = 'lda'
comp = 'def_{} += attrb'.format(dda)
exec compile(comp, '', 'exec')
def_lda

In [ ]:
def get_ref(dda, ancestors, match):
    ancestors.append(match['name'])
    ref = dda + eval("""'{}'.format("['{}']" * len(ancestors))""").format(*ancestors)
    return ref

In [ ]:
match

In [ ]:
dda = 'lda'
ancestors = ['#TELA']
print get_ref(dda, ancestors, match)
ancestors.pop()
print ancestors

In [ ]:
ancestors = ['#TELA']
ancestors.append('#CAMPO-ALFA') 
ref = eval("""'{}'.format("['{}']" * len(ancestors))""").format(*ancestors)

In [ ]:
attrb = eval("""'{}'.format("['{}': " * len(ancestors))""").format(*ancestors)
attrb = attrb.replace('[','{').replace(']', '}')
attrb

In [ ]:
ref = eval("""'{}'.format("['{}']" * len(ancestors))""").format(*ancestors)
print ref

In [ ]:
lda = {'#TELA': {
                 '#CAMPO-ALFA': '',
                 '#CAMPO-MULTIPLO': ['CM1', 'CM2', 'CM3', '', 'CM5'],
                }   
       }
print lda['#TELA']['#CAMPO-MULTIPLO']
print lda['#TELA']['#CAMPO-MULTIPLO'][2]

In [ ]:
line = 'LOCAL using fffff'
words(line)
words(line)[1][2]

In [1]:
from Convertidos.pgmteste import *

In [3]:
lda


Out[3]:
{'#ATR': '',
 '#ATR1': [''],
 '#ATR2': [['']],
 '#ATR3': '',
 '#ATR4': '',
 '#ATR5': '',
 '#ATR6': '',
 '#CAMPO-RETORNA': '',
 '#IND-TB': Decimal('0'),
 '#IND-TL': Decimal('0'),
 '#IND1': Decimal('0'),
 '#IND2': Decimal('0'),
 '#TB-RETORNA': [''],
 '#TELA': {'#CAMPO-ALFA': '',
  '#CAMPO-BIN': '',
  '#CAMPO-BIN-R1': {'#CAMPO-BIN-N': Decimal('0')},
  '#CAMPO-DATA-TELA': '',
  '#CAMPO-DATA-TELA-R1': {'#CAMPO-DT-NUM-ANO': '',
   '#CAMPO-DT-NUM-DIA': '',
   '#CAMPO-DT-NUM-MES': ''},
  '#CAMPO-DATA-TELA-R2': {'#CAMPO-DATA-TELA-N': Decimal('0')},
  '#CAMPO-MULTIPLO': [''],
  '#CAMPO-MULTIPLO-R1': {'#CAMPO-MULTIPLO-R': [Decimal('0')]},
  '#CAMPO-NUM': '',
  '#CAMPO-NUM-R1': {'#CAMPO-R-NU-TOT': Decimal('0'),
   '#CAMPO-R-NU-TOT-R1': {'#CAMPO-R-NU-DEC': Decimal('0')},
   'FILLER_01': ''},
  '#CAMPO-PACK': '',
  '#CAMPO-PACK-R1': {'#CAMPO-R-PACK-TOT': Decimal('0'),
   '#CAMPO-R-PACK-TOT-R1': {'#CAMPO-R-PACK-DEC': Decimal('0')},
   'FILLER_02': ''},
  '#CAMPO-PE-1': {'#CAMPO-PE-ALFA': '',
   '#CAMPO-PE-NUM': '',
   '#CAMPO-PE-NUM-R1': {'#CAMPO-PE-NUM-R': Decimal('0')}},
  '#CAMPO-PE-2': {'#CAMPO-PE2-ALFA': '',
   '#CAMPO-PE2-MULTIPLO': [''],
   '#CAMPO-PE2-MULTIPLO-R1': {'#CAMPO-PE2-MULTIPLO-R': [Decimal('0')]},
   '#CAMPO-PE2-NUM': '',
   '#CAMPO-PE2-NUM-R1': {'#CAMPO-PE2-NUM-R': Decimal('0')}},
  '#CAPO-HORA-TELA': '',
  '#CAPO-HORA-TELA-R1': {'#COMPO-HORA-HO': '',
   '#COMPO-HORA-MM': '',
   '#COMPO-HORA-SS': ''},
  '#CAPO-HORA-TELA-R2': {'#COMPO-HORA-HO-N': Decimal('0')},
  '#TL-CONFIRMA': ''},
 '#TL-DT-DATE': '',
 '#TL-HO-TIME': '',
 '#TL-REGISTRO': Decimal('0'),
 '#TL-TX-CONF': 'CONFIRMA S/N:',
 '#TL-TX-DATE': 'DATA DATE:',
 '#TL-TX-REGISTRO': 'REGISTRO ISN   :',
 '#TL-TX-TIME': 'HORA TIME:',
 '#TX-PFS': 'PF8 - AVANCA',
 'F255': {'CAMPO-ALFA': '',
  'CAMPO-BINARIO': 0,
  'CAMPO-DATE-DATA': datetime.date(1, 1, 1),
  'CAMPO-MULTIPLO': [0],
  'CAMPO-NUMERICO': 0.0,
  'CAMPO-NUMERICO-DATA': 0.0,
  'CAMPO-NUMERICO-HORA': 0.0,
  'CAMPO-PACK': 0.0,
  'CAMPO-TIME-HORA': datetime.time(1, 1, 1),
  'GP-COM-MULTIPLO': {'CAMPO-PE2-ALFA': [''],
   'CAMPO-PE2-MULTIPLO': [[0]],
   'CAMPO-PE2-NUM': [0]},
  'GP-SEM-MULTIPLO': {'CAMPO-PE-ALFA': [''], 'CAMPO-PE-NUM': [0]}}}

In [ ]:
from decimal import *
getcontext().prec = scale
d = Decimal(1)
d1 = Decimal(7)
d / d1