diff --git a/.gitignore b/.gitignore index f0fc736..9b6c802 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ ysApi.egg-info build dist config/config.ini +*.py[co] +*.sw[po] diff --git a/examples/archive.py b/examples/archive.py index 899e1a8..291c084 100644 --- a/examples/archive.py +++ b/examples/archive.py @@ -32,6 +32,6 @@ try : res = c.archive(file) - print res + print(res) except suds.WebFault as detail: - print detail + print(detail) diff --git a/examples/connection.py b/examples/connection.py index d4871ac..36a8c6b 100644 --- a/examples/connection.py +++ b/examples/connection.py @@ -20,6 +20,6 @@ # "apikey", # "environment") try : - print "Successful authentication" if c.connect() else "Authentication failed" + print("Successful authentication" if c.connect() else "Authentication failed") except suds.WebFault as detail: - print detail + print(detail) diff --git a/examples/getArchive.py b/examples/getArchive.py index a33ca88..a1a98b8 100644 --- a/examples/getArchive.py +++ b/examples/getArchive.py @@ -30,8 +30,8 @@ def id_generator(size=5, chars= string.ascii_lowercase + string.digits): archFile = open(pathFile, 'w') archFile.write(base64.b64decode(content)) - print 'Archive saved in : '+os.getcwd()+'/'+pathFile - print 'Response from Yousign API ...' - print res + print('Archive saved in : '+os.getcwd()+'/'+pathFile) + print('Response from Yousign API ...') + print(res) except suds.WebFault as detail: - print detail + print(detail) diff --git a/examples/getCompleteArchive.py b/examples/getCompleteArchive.py index fbcb323..053c1d8 100644 --- a/examples/getCompleteArchive.py +++ b/examples/getCompleteArchive.py @@ -24,8 +24,8 @@ archFile = open(pathZip, 'w') archFile.write(base64.b64decode(zipContent)) - print 'Archive saved in : '+os.getcwd()+'/'+pathZip - print 'Response from Yousign API ...' - print res + print('Archive saved in : '+os.getcwd()+'/'+pathZip) + print('Response from Yousign API ...') + print(res) except suds.WebFault as detail: - print detail + print(detail) diff --git a/examples/signature_alert.py b/examples/signature_alert.py index 2abff34..accfb32 100644 --- a/examples/signature_alert.py +++ b/examples/signature_alert.py @@ -13,14 +13,14 @@ try: - print "Alerting the Signers ..." + print("Alerting the Signers ...") # For the last signature last = c.getListSign(count=1) idDemand = last[0]['cosignatureEvent'] res = c.alertSigners(idDemand) - print res + print(res) except suds.WebFault as detail: - print detail + print(detail) diff --git a/examples/signature_cancel.py b/examples/signature_cancel.py index 5c867c7..2b86b47 100644 --- a/examples/signature_cancel.py +++ b/examples/signature_cancel.py @@ -13,14 +13,14 @@ try: - print "Cancelling the Signature ... " + print("Cancelling the Signature ... ") # For the last signature last = c.getListSign(count=1) idDemand = last[0]['cosignatureEvent'] res = c.cancelSignatureDemand(idDemand) - print res + print(res) except suds.WebFault as detail: - print detail \ No newline at end of file + print(detail) \ No newline at end of file diff --git a/examples/signature_details.py b/examples/signature_details.py index 4085b10..144ad8d 100644 --- a/examples/signature_details.py +++ b/examples/signature_details.py @@ -15,11 +15,11 @@ try: res = c.getListSign(count=1) if res == []: - print "Signature not yet created " + print("Signature not yet created ") idDemand = res[0]['cosignatureEvent'] res = c.getInfosFromSignatureDemand(idDemand) - print " Details from the signature with the id : %d" %(idDemand) - print res + print(" Details from the signature with the id : %d" %(idDemand)) + print(res) except suds.WebFault as detail: - print detail + print(detail) diff --git a/examples/signature_downloadFile.py b/examples/signature_downloadFile.py index 00ce806..f7ff17e 100644 --- a/examples/signature_downloadFile.py +++ b/examples/signature_downloadFile.py @@ -18,7 +18,7 @@ def id_generator(size=5, chars= string.ascii_lowercase + string.digits): return ''.join(random.choice(chars) for _ in range(size)) - print "Getting Signed file(s) ..." + print("Getting Signed file(s) ...") try : # For the last signature @@ -40,10 +40,10 @@ def id_generator(size=5, chars= string.ascii_lowercase + string.digits): # Write contents associated to each file for el in fileName : pathFile= 'documents/'+id_generator()+'_'+fileName[fileName.index(el)] - print pathFile + print(pathFile) signedFile = open(pathFile, 'w') signedFile.write(base64.b64decode(file[fileName.index(el)])) - print 'Signed file saved in : '+os.getcwd()+'/'+pathFile + print('Signed file saved in : '+os.getcwd()+'/'+pathFile) except suds.WebFault as detail: - print detail + print(detail) diff --git a/examples/signature_init.py b/examples/signature_init.py index c592837..bb29cb1 100644 --- a/examples/signature_init.py +++ b/examples/signature_init.py @@ -50,12 +50,12 @@ # Verify that each file is associated with its options. if len(lstFile)!=len(options): - print "Files and options numbers must be identical" + print("Files and options numbers must be identical") # Verify that each signer is associated with his signature options. for op in options: if len(op)!=len(listSignersInfos): - print "Make sure that all signers are associated with signature options [Not fatal]" + print("Make sure that all signers are associated with signature options [Not fatal]") # Associate each file to its options and its password if it exists. for i in range (len(lstFile)) : @@ -85,13 +85,13 @@ mail.append(el['mail']) # To display url associated with each email address (signers) - print "Access Links to documents to sign :" + print("Access Links to documents to sign :") for el in mail: ind = mail.index(el) - print "Link for the signer "+el+" : "+c.url_iFrame+'public/ext/cosignature/'+token[ind] + print("Link for the signer "+el+" : "+c.url_iFrame+'public/ext/cosignature/'+token[ind]) # To display all information about the signatures - print "Response from Yousign API :" - print res + print("Response from Yousign API :") + print(res) except suds.WebFault as detail: - print detail + print(detail) diff --git a/examples/signature_list.py b/examples/signature_list.py index 49d7725..3c9c31e 100644 --- a/examples/signature_list.py +++ b/examples/signature_list.py @@ -12,11 +12,11 @@ # "environment") - print "Getting List ... " + print("Getting List ... ") # The last ten signatures for this example try: res = c.getListSign('', 0, count = 10) - print res + print(res) except suds.WebFault as detail: - print detail \ No newline at end of file + print(detail) \ No newline at end of file diff --git a/setup.py b/setup.py index 272ef64..8380eec 100644 --- a/setup.py +++ b/setup.py @@ -9,5 +9,5 @@ #packages=setuptools.find_packages(), # Project uses suds # installed or upgraded on the target machine - install_requires = ['suds>=0.4'] -) \ No newline at end of file + install_requires = ['suds-jurko>=0.4'] +) diff --git a/ysApi/__init__.py b/ysApi/__init__.py index e3bd36e..749f1c6 100644 --- a/ysApi/__init__.py +++ b/ysApi/__init__.py @@ -1,5 +1,4 @@ -from apiClient import ApiClient -from fileToSign import FileToSign, Signer, VisibleOptions -__all__ = ['ApiClient', 'FileToSign', 'Signer', 'VisibleOptions'] - +from .apiClient import ApiClient +from .fileToSign import FileToSign, Signer, VisibleOptions +__all__ = ['ApiClient', 'FileToSign', 'Signer', 'VisibleOptions'] diff --git a/ysApi/apiClient.py b/ysApi/apiClient.py index ba2ab23..c86a39e 100644 --- a/ysApi/apiClient.py +++ b/ysApi/apiClient.py @@ -1,7 +1,10 @@ # -*- coding: utf-8 -*- import hashlib import os -import ConfigParser +try: + from configparser import ConfigParser +except ImportError: + from ConfigParser import RawConfigParser as ConfigParser import logging from suds.client import Client from suds.sax.element import Element @@ -33,7 +36,8 @@ def WSDL_ARCH_URL(self): "Method used to hash(encrypt) the password" @staticmethod def hashPassword(password): - return hashlib.sha1(hashlib.sha1(password).hexdigest()+ hashlib.sha1(password).hexdigest()).hexdigest() + password = hashlib.sha1(password.encode('utf-8')).hexdigest().encode('ascii') + return hashlib.sha1(password + password).hexdigest() """ Method used to load user configuration (in order to establish a connection)from a file. @@ -41,7 +45,7 @@ def hashPassword(password): User can choose to put (or no) an encrypted password. """ def parseConf(self, pathParameters): - config = ConfigParser.RawConfigParser() + config = ConfigParser() config.read(pathParameters) self.username = config.get('client', 'username') @@ -160,4 +164,4 @@ def getArchive(self, iua): "Get complete archive file identified by its iua. " "It includes all proof informations about archive : descriptive metadatas, applicative metadatas, sealing datas and the initial archive file" def getCompleteArchive(self,iua): - return getattr(self._archClient.service,'getCompleteArchive')( iua = iua) \ No newline at end of file + return getattr(self._archClient.service,'getCompleteArchive')( iua = iua) diff --git a/ysApi/fileToSign.py b/ysApi/fileToSign.py index 909cc43..21a26b6 100644 --- a/ysApi/fileToSign.py +++ b/ysApi/fileToSign.py @@ -9,7 +9,7 @@ def __init__(self, name, visibleOptions, password, **kwargs): f = dirName+os.path.basename(name) self["name"] = os.path.basename(f) with open(f, "rb") as test_file: - content = base64.b64encode(test_file.read()) + content = base64.b64encode(test_file.read()).decode('ascii') self["content"] = content self["visibleOptions"] = visibleOptions self["pdfPassword"] = password @@ -31,4 +31,4 @@ def __init__(self, visibleSignaturePage=1, isVisibleSignature=True, visibleRecta self["visibleSignaturePage"] = visibleSignaturePage self["isVisibleSignature"] = isVisibleSignature self["visibleRectangleSignature"] = visibleRectangleSignature - self["mail"] = mail \ No newline at end of file + self["mail"] = mail