Skip to content

Fix a few more Python3 errors #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Feb 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.pyc
dist/
.vscode/
*.egg-info/
MANIFEST
13 changes: 7 additions & 6 deletions PyFePA/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,15 @@ def validate(self, value):
elif not (self.minlen and self.maxlen ):
valid = True
elif self.minlen and not self.maxlen :
valid = self.minlen <= len(str(value))
valid = self.minlen <= len(value)
elif self.maxlen and not self.minlen:
valid = len(str(value)) <= self.maxlen
valid = len(value) <= self.maxlen
else:
valid = self.minlen <= len(str(value)) <= self.maxlen
valid = self.minlen <= len(value) <= self.maxlen


if valid:
return value if isinstance(value,str) else str(value)
return value if isinstance(value,str) else value.decode('utf8')
else:
return valid

Expand Down Expand Up @@ -144,7 +145,7 @@ def validate(self, value):
elif self.minlen <= len('{:.2f}'.format(float(value))) <= self.maxlen:
return Decimal(value).quantize(Decimal('.01'))
except(ValueError, TypeError):
print('DEBUG- ', value)
print(('DEBUG- ', value))
return False

def __init__(self, **kwargs):
Expand All @@ -156,7 +157,7 @@ def __init__(self, **kwargs):

@classmethod
def tostring(cls,value):
return unicode(Decimal(value).quantize(Decimal('.01')))
return str(Decimal(value).quantize(Decimal('.01')))


class FieldDate(FieldType):
Expand Down
10 changes: 5 additions & 5 deletions PyFePA/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ def validate(invoice_part):
elif v['value'] is not None and v['conflict'] is not None:
for d in v['conflict']:
if taglist[d]['value'] is not None:
raise ValidateException('{0} Conflict whit {1}'.format(v['tag'],v['conflict']))
raise ValidateException('Cannot specify both {0} and {1} at the same time'.format(v['tag'],v['conflict']))
elif v['value'] is None and v['conflict'] is not None and v['required']:
for d in v['conflict']:
if taglist[d]['value'] is None:
raise ValidateException('{0} or {1} mast be specify'.format(v['tag'],v['conflict']))
raise ValidateException('Either {0} or {1} is missing. Alternatively they could both be specified, which is not allowed.'.format(v['tag'],v['conflict']))

return taglist

Expand Down Expand Up @@ -98,7 +98,7 @@ def globalvalidation(fattura):
raise ValidateException('Denominazione Azienda Mancante')
for feb in fattura.FatturaElettronicaBody:
if feb.DatiGenerali.DatiGeneraliDocumento.Data > datetime.date.today():
print(feb.DatiGenerali.DatiGeneraliDocumento.Data, '- TODAY -', datetime.date.today())
print((feb.DatiGenerali.DatiGeneraliDocumento.Data, '- TODAY -', datetime.date.today()))
raise ValidateException('00403 - Data Fattura non puo essere nel futuro')
for ln in feb.DatiBeniServizi.DettaglioLinee:
if ln.Ritenuta and not feb.DatiGenerali.DatiGeneraliDocumento.DatiRitenuta:
Expand Down Expand Up @@ -146,8 +146,8 @@ def serializexml(invoice_part,tagname):
for t in taglist[k]['value']:
fe.append(serializexml(t, taglist[k]['tag']))
elif taglist[k]['type'] == 'S' and taglist[k]['value'] is not None:
if type(taglist[k]['value']) != unicode:
taglist[k]['value'] = unicode(taglist[k]['value'])
if type(taglist[k]['value']) != str:
taglist[k]['value'] = str(taglist[k]['value'])
(ElementTree.SubElement(fe, taglist[k]['tag'])).text = taglist[k]['value']
elif taglist[k]['type'] == 'O' and taglist[k]['value'] is not None:
fe.append(serializexml(taglist[k]['value'],taglist[k]['tag']))
Expand Down
2 changes: 1 addition & 1 deletion PyFePA/test/build_fatturapa.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,4 @@ def allegati(self):
if __name__ == "__main__":
fatturapa = FatturaPA()
fpa = fatturapa.get_fatturapa()
print(serializer(fpa,'xml'))
print((serializer(fpa,'xml')))
4 changes: 2 additions & 2 deletions runit.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
with open(DPATH+'/PyFePA/test/IT01234567890_11001.xml', 'rt') as f:
tree = ElementTree.parse(f)
fe = serializer.deserialize(element=tree)
print(serializer.serializer(fe,'xml'))
print((serializer.serializer(fe,'xml')))

testdata_list = [testdata,testdata,testdata]
print(siamm.serialize(testdata_list))
print((siamm.serialize(testdata_list)))
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
setup(
name = 'PyFePA',
packages = ['PyFePA'],
version = '1.2.1b',
version = '1.2.2b',
description = 'Python object of italian FatturaPA, serialize, deserialize and verify',
author = 'Luigi Di Naro',
author_email = 'Luigi.DiNaro@ktec.it',
Expand Down