Skip to content

Commit 240ad28

Browse files
authored
Merge pull request #3 from zgypa/feature/python3_errors
2 parents 34d4d8f + 5740f93 commit 240ad28

File tree

6 files changed

+21
-15
lines changed

6 files changed

+21
-15
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*.pyc
2+
dist/
3+
.vscode/
4+
*.egg-info/
5+
MANIFEST

PyFePA/fields.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,15 @@ def validate(self, value):
5757
elif not (self.minlen and self.maxlen ):
5858
valid = True
5959
elif self.minlen and not self.maxlen :
60-
valid = self.minlen <= len(str(value))
60+
valid = self.minlen <= len(value)
6161
elif self.maxlen and not self.minlen:
62-
valid = len(str(value)) <= self.maxlen
62+
valid = len(value) <= self.maxlen
6363
else:
64-
valid = self.minlen <= len(str(value)) <= self.maxlen
64+
valid = self.minlen <= len(value) <= self.maxlen
65+
6566

6667
if valid:
67-
return value if isinstance(value,str) else str(value)
68+
return value if isinstance(value,str) else value.decode('utf8')
6869
else:
6970
return valid
7071

@@ -144,7 +145,7 @@ def validate(self, value):
144145
elif self.minlen <= len('{:.2f}'.format(float(value))) <= self.maxlen:
145146
return Decimal(value).quantize(Decimal('.01'))
146147
except(ValueError, TypeError):
147-
print('DEBUG- ', value)
148+
print(('DEBUG- ', value))
148149
return False
149150

150151
def __init__(self, **kwargs):
@@ -156,7 +157,7 @@ def __init__(self, **kwargs):
156157

157158
@classmethod
158159
def tostring(cls,value):
159-
return unicode(Decimal(value).quantize(Decimal('.01')))
160+
return str(Decimal(value).quantize(Decimal('.01')))
160161

161162

162163
class FieldDate(FieldType):

PyFePA/serializer.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ def validate(invoice_part):
5757
elif v['value'] is not None and v['conflict'] is not None:
5858
for d in v['conflict']:
5959
if taglist[d]['value'] is not None:
60-
raise ValidateException('{0} Conflict whit {1}'.format(v['tag'],v['conflict']))
60+
raise ValidateException('Cannot specify both {0} and {1} at the same time'.format(v['tag'],v['conflict']))
6161
elif v['value'] is None and v['conflict'] is not None and v['required']:
6262
for d in v['conflict']:
6363
if taglist[d]['value'] is None:
64-
raise ValidateException('{0} or {1} mast be specify'.format(v['tag'],v['conflict']))
64+
raise ValidateException('Either {0} or {1} is missing. Alternatively they could both be specified, which is not allowed.'.format(v['tag'],v['conflict']))
6565

6666
return taglist
6767

@@ -98,7 +98,7 @@ def globalvalidation(fattura):
9898
raise ValidateException('Denominazione Azienda Mancante')
9999
for feb in fattura.FatturaElettronicaBody:
100100
if feb.DatiGenerali.DatiGeneraliDocumento.Data > datetime.date.today():
101-
print(feb.DatiGenerali.DatiGeneraliDocumento.Data, '- TODAY -', datetime.date.today())
101+
print((feb.DatiGenerali.DatiGeneraliDocumento.Data, '- TODAY -', datetime.date.today()))
102102
raise ValidateException('00403 - Data Fattura non puo essere nel futuro')
103103
for ln in feb.DatiBeniServizi.DettaglioLinee:
104104
if ln.Ritenuta and not feb.DatiGenerali.DatiGeneraliDocumento.DatiRitenuta:
@@ -146,8 +146,8 @@ def serializexml(invoice_part,tagname):
146146
for t in taglist[k]['value']:
147147
fe.append(serializexml(t, taglist[k]['tag']))
148148
elif taglist[k]['type'] == 'S' and taglist[k]['value'] is not None:
149-
if type(taglist[k]['value']) != unicode:
150-
taglist[k]['value'] = unicode(taglist[k]['value'])
149+
if type(taglist[k]['value']) != str:
150+
taglist[k]['value'] = str(taglist[k]['value'])
151151
(ElementTree.SubElement(fe, taglist[k]['tag'])).text = taglist[k]['value']
152152
elif taglist[k]['type'] == 'O' and taglist[k]['value'] is not None:
153153
fe.append(serializexml(taglist[k]['value'],taglist[k]['tag']))

PyFePA/test/build_fatturapa.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,4 +221,4 @@ def allegati(self):
221221
if __name__ == "__main__":
222222
fatturapa = FatturaPA()
223223
fpa = fatturapa.get_fatturapa()
224-
print(serializer(fpa,'xml'))
224+
print((serializer(fpa,'xml')))

runit.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
with open(DPATH+'/PyFePA/test/IT01234567890_11001.xml', 'rt') as f:
3535
tree = ElementTree.parse(f)
3636
fe = serializer.deserialize(element=tree)
37-
print(serializer.serializer(fe,'xml'))
37+
print((serializer.serializer(fe,'xml')))
3838

3939
testdata_list = [testdata,testdata,testdata]
40-
print(siamm.serialize(testdata_list))
40+
print((siamm.serialize(testdata_list)))

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
setup(
2323
name = 'PyFePA',
2424
packages = ['PyFePA'],
25-
version = '1.2.1b',
25+
version = '1.2.2b',
2626
description = 'Python object of italian FatturaPA, serialize, deserialize and verify',
2727
author = 'Luigi Di Naro',
2828
author_email = 'Luigi.DiNaro@ktec.it',

0 commit comments

Comments
 (0)