Skip to content
This repository has been archived by the owner on Nov 2, 2024. It is now read-only.

Commit

Permalink
Changed super and fixed property
Browse files Browse the repository at this point in the history
  • Loading branch information
danimaribeiro committed Aug 25, 2015
1 parent aa4b858 commit a07934a
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 27 deletions.
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-

from setuptools import setup, find_packages
from setuptools.command.test import test as test_command
from sped import __version__
Expand Down
6 changes: 3 additions & 3 deletions sped/arquivos.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ def read_registro(self, line):
bloco.add(registro)

def write_to(self, buffer):
buffer.write(self._registro_abertura.as_line() + '\r\n')
buffer.write(self._registro_abertura.as_line() + u'\r\n')
reg_count = 2
for key in self._blocos.keys():
bloco = self._blocos[key]
reg_count += len(bloco.registros)
for r in bloco.registros:
buffer.write(r.as_line() + '\r\n')
buffer.write(r.as_line() + u'\r\n')

self._registro_fechamento[2] = reg_count

buffer.write(self._registro_fechamento.as_line() + '\r\n')
buffer.write(self._registro_fechamento.as_line() + u'\r\n')

def getstring(self):
buffer = StringIO()
Expand Down
28 changes: 14 additions & 14 deletions sped/campos.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class CampoFixo(Campo):
'0000'
"""
def __init__(self, indice, nome, valor):
super().__init__(indice, nome, True)
super(CampoFixo, self).__init__(indice, nome, True)
self._valor = valor

@property
Expand All @@ -99,7 +99,7 @@ def set(self, registro, valor):

class CampoAlfanumerico(Campo):
def __init__(self, indice, nome, obrigatorio=False, tamanho=255):
super().__init__(indice, nome, obrigatorio)
super(CampoAlfanumerico, self).__init__(indice, nome, obrigatorio)
self._tamanho = tamanho

@property
Expand All @@ -109,12 +109,12 @@ def tamanho(self):
def set(self, registro, valor):
valor = valor or ''
valor = valor[:self._tamanho]
super().set(registro, valor)
super(CampoAlfanumerico, self).set(registro, valor)


class CampoNumerico(Campo):
def __init__(self, indice, nome, obrigatorio=False, precisao=0, minimo=0, maximo=1000):
super().__init__(indice, nome, obrigatorio)
super(CampoNumerico, self).__init__(indice, nome, obrigatorio)
self._precisao = precisao
self._minimo = minimo
self._maximo = maximo
Expand All @@ -132,49 +132,49 @@ def maximo(self):
return self._maximo

def get(self, registro):
valor = super().get(registro)
valor = super(CampoNumerico, self).get(registro)
if not valor:
return None
return Decimal(valor.replace(',', '.'))

def set(self, registro, valor):
if isinstance(valor, Decimal) or isinstance(valor, float):
super().set(registro, (('%.' + str(self._precisao) + 'f') % valor).replace('.', ','))
super(CampoNumerico, self).set(registro, (('%.' + str(self._precisao) + 'f') % valor).replace('.', ','))
elif isinstance(valor, int):
super().set(registro, str(valor))
super(CampoNumerico, self).set(registro, str(valor))
elif not valor:
super().set(registro, '0')
super(CampoNumerico, self).set(registro, '0')
else:
raise FormatoInvalidoError(registro, self.nome)


class CampoData(Campo):
def __init__(self, indice, nome, obrigatorio=False):
super().__init__(indice, nome, obrigatorio)
super(CampoData, self).__init__(indice, nome, obrigatorio)

def get(self, registro):
valor = super().get(registro)
valor = super(CampoData, self).get(registro)
if not valor:
return None
return datetime.strptime(valor, '%d%m%Y').date()

def set(self, registro, valor):
if isinstance(valor, date):
super().set(registro, valor.strftime('%d%m%Y'))
super(CampoData, self).set(registro, valor.strftime('%d%m%Y'))
elif not valor:
super().set(registro, None)
super(CampoData, self).set(registro, None)
else:
raise FormatoInvalidoError(registro, self.nome)


class CampoRegex(Campo):
def __init__(self, indice, nome, obrigatorio=False, regex=None):
super().__init__(indice, nome, obrigatorio)
super(CampoRegex, self).__init__(indice, nome, obrigatorio)
self._regex = re.compile('^' + regex + '$')

def set(self, registro, valor):
if not valor or self._regex.match(valor):
super().set(registro, valor)
super(CampoRegex, self).set(registro, valor)
else:
raise FormatoInvalidoError(registro, self.nome)

Expand Down
2 changes: 1 addition & 1 deletion sped/ecd/arquivos.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ArquivoDigital(ArquivoDigital):
blocos = blocos

def __init__(self):
super().__init__()
super(ArquivoDigital, self).__init__()
self._blocos['0'] = Bloco0()
self._blocos['I'] = BlocoI()
self._blocos['J'] = BlocoJ()
Expand Down
4 changes: 2 additions & 2 deletions sped/ecd/blocos.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Bloco0(Bloco):

@property
def fechamento(self):
registro = super().fechamento
registro = Bloco.fechamento.fget(self)
registro[2] += 1
return registro

Expand Down Expand Up @@ -50,6 +50,6 @@ class Bloco9(Bloco):

@property
def fechamento(self):
registro = super().fechamento
registro = super(Bloco9, self).fechamento
registro[2] += 1
return registro
2 changes: 1 addition & 1 deletion sped/ecf/arquivos.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ArquivoDigital(ArquivoDigital):
blocos = blocos

def __init__(self):
super().__init__()
super(ArquivoDigital, self).__init__()
self._blocos['0'] = Bloco0()
self._blocos['C'] = BlocoC()
self._blocos['E'] = BlocoE()
Expand Down
2 changes: 1 addition & 1 deletion sped/efd/icms_ipi/arquivos.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ArquivoDigital(ArquivoDigital):
blocos = blocos

def __init__(self):
super().__init__()
super(ArquivoDigital, self).__init__()
self._blocos['0'] = Bloco0()
self._blocos['C'] = BlocoC()
self._blocos['D'] = BlocoD()
Expand Down
2 changes: 1 addition & 1 deletion sped/efd/pis_cofins/arquivos.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ArquivoDigital(ArquivoDigital):
blocos = blocos

def __init__(self):
super().__init__()
super(ArquivoDigital, self).__init__()
self._blocos['0'] = Bloco0()
self._blocos['A'] = BlocoA()
self._blocos['C'] = BlocoC()
Expand Down
6 changes: 3 additions & 3 deletions sped/erros.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ def __init__(self, registro):
self._registro = registro

def __str__(self):
return '{0}'.format(self._registro)
return u'{0}'.format(self._registro)


class CampoError(RegistroError):
def __init__(self, registro, campo):
super().__init__(registro)
super(CampoError, self).__init__(registro)
self._campo = campo

def __str__(self):
return '{0} -> {1}'.format(self._registro.__class__.__name__, self._campo)
return u'{0} -> {1}'.format(self._registro.__class__.__name__, self._campo)


class CampoFixoError(CampoError):
Expand Down
2 changes: 1 addition & 1 deletion sped/registros.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,4 @@ def __setattr__(self, name, value):
campo.set(self, value)

def as_line(self):
return '|'.join(self._valores)
return u'|'.join(self._valores)

0 comments on commit a07934a

Please sign in to comment.