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

In [3]:
references = {}
dda = 'lda'
line = """0260 1 #AX-PARAM-VAL-ANT (P13,2) INIT<'CONFIRMA S/N:'>"""
#line = """02601 #AX-PARAM-VAL-ANT (P13,2)"""
#line = """02601 #AX-PARAM-VAL-ANT  """
line = """0520  2 #CAMPO-PE-2                    (1:5)"""
match = DataPatterns.row_pattern.match(l480(line).strip())
match.groupdict()


Out[3]:
{'init': None,
 'length': None,
 'level': '2',
 'name': '#CAMPO-PE-2',
 'occurs': '5',
 'scale': None,
 'two_dimension': None,
 'type': None}

In [ ]:
attrb = {}
dicattr = {}                                                                                       
dicattr['def'] = """{}['{}']""".format(dda, match['name'])                                         
dicattr['type'] = ' ' if not match.get('type', None) else match['type']                            
dicattr['length'] = 0 if not match.get('length', 0) else int(match['length'])                      
dicattr['scale'] = 0 if not match.get('scale', 0) else int(match['scale'])                         
dicattr['occurs'] = 0 if not match.get('occurs', 0) else int(match['occurs'])                      
dicattr['two_dimension'] = 0 if not match.get('two_dimension', 0) else int(match['two_dimension']) 
dicattr['init'] = ' ' if not match.get('init', None) else match['init']                            
attrb[match['name']] = dicattr                                                                     

print attrb

In [ ]:
references.update(attrb)
print references

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

print ">",init,"<"

In [ ]:
line = """0050 1 #ATR                           (C)"""
match = DataPatterns.row_pattern.match(l472(line).lstrip())
match = match.groupdict()
match

In [ ]:
line = """0060 1 #ATR1                          (C/1:5)"""
match = DataPatterns.row_pattern.match(l472(line).lstrip())
match = match.groupdict()
match

In [ ]:
line = """0070 1 #ATR2                          (C/1:5,1:5)"""
match = DataPatterns.row_pattern.match(l472(line).lstrip())
match = match.groupdict()
match

In [ ]:
line = " 1 #TX-PFS                        (A48) INIT<'PF8 - AVANCA'>"
#match = DataPatterns.row_pattern.match(l472(line).lstrip())
match = DataPatterns.row_pattern.match(line.lstrip())
match = match.groupdict()
match

In [ ]:
line = """07201 #AX-DET-CTT     (A78/1:30)"""
match = DataPatterns.row_pattern.match(l472(line))
match = match.groupdict()
match

In [ ]:
DF = {'#AX-DET-CTT':['str1'
                    ,'str2'
                    ,'str3']   
     ,'#AX-DET-CTU':['stru1'
                    ,'stru2'
                    ,'stru3']   
 
     }
DF['#AX-DET-CTU'][2] = DF['#AX-DET-CTT'][2] 
DF['#AX-DET-CTT'][2] = 'strr'
DF['#AX-DET-CTU'][2]

In [ ]:
line = '06201 REDEFINE #AX-PARAM-DT-SAI8'
match = DataPatterns.row_pattern_redefine.match(l472(line))
match = match.groupdict()
match['redefine']

In [ ]:
G11111AA = {'#TAB-TXT-TELA': ['TELA DE INCLUSAO DE DADOS',
                              'TELA DE CONSULTA DE DADOS' ,
                              'TELA DE ALTERACAO DE DADOS',
                              'TELA DE EXCLUSAO DE DADOS'
                             ]
           }                                            
G11111AA['#TAB-TXT-TELA'][3]

In [ ]:
#line = """0520  2 #CAMPO-PE-2                    (1:5,1:7)"""
line = """0150  2 REDEFINE                       #CAMPO-NUM"""
match = DataPatterns.row_pattern.match(l472(line).lstrip())
match = match.groupdict()
match

In [ ]:
line = """0150  2 REDEFINE                       #CAMPO-NUM"""
match = DataPatterns.row_pattern_redefine.match(l472(line).lstrip())
match = match.groupdict()
match['name']=match['redefine']
match

In [ ]:
import re
line = """0160    3 FILLER                       5X"""
filler = 0 
filler+=1
line = re.sub('FILLER', 'FILLER_{:02}'.format(filler), line)
pattern = re.search('(?P<length>\d+)X', line)
print pattern
match = pattern.groupdict()
sub = ' (A{})'.format(match['length'])
line = re.sub('\s+\d+X', sub, line)
line

In [ ]:
import re
cpf = '045.075.058-28'
f = re.compile(r'\d{3}(\.\d{3}){2}-\d{2}')
f.match(cpf)

In [ ]:
cpf = '04507505828'
'{}{}{}.{}{}{}.{}{}{}-{}{}'.format(*cpf)