Skip to content

Ported API to python 3, keeping backward compatibility with python2 #5

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ ysApi.egg-info
build
dist
config/config.ini
*.py[co]
*.sw[po]
4 changes: 2 additions & 2 deletions examples/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@

try :
res = c.archive(file)
print res
print(res)
except suds.WebFault as detail:
print detail
print(detail)
4 changes: 2 additions & 2 deletions examples/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
8 changes: 4 additions & 4 deletions examples/getArchive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
8 changes: 4 additions & 4 deletions examples/getCompleteArchive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
6 changes: 3 additions & 3 deletions examples/signature_alert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
6 changes: 3 additions & 3 deletions examples/signature_cancel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
print(detail)
8 changes: 4 additions & 4 deletions examples/signature_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

8 changes: 4 additions & 4 deletions examples/signature_downloadFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
14 changes: 7 additions & 7 deletions examples/signature_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)) :
Expand Down Expand Up @@ -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)
6 changes: 3 additions & 3 deletions examples/signature_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
print(detail)
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
#packages=setuptools.find_packages(),
# Project uses suds
# installed or upgraded on the target machine
install_requires = ['suds>=0.4']
)
install_requires = ['suds-jurko>=0.4']
)
7 changes: 3 additions & 4 deletions ysApi/__init__.py
Original file line number Diff line number Diff line change
@@ -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']
12 changes: 8 additions & 4 deletions ysApi/apiClient.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -33,15 +36,16 @@ 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.
Specified parameters are username, password and the API key.
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')

Expand Down Expand Up @@ -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)
return getattr(self._archClient.service,'getCompleteArchive')( iua = iua)
4 changes: 2 additions & 2 deletions ysApi/fileToSign.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,4 +31,4 @@ def __init__(self, visibleSignaturePage=1, isVisibleSignature=True, visibleRecta
self["visibleSignaturePage"] = visibleSignaturePage
self["isVisibleSignature"] = isVisibleSignature
self["visibleRectangleSignature"] = visibleRectangleSignature
self["mail"] = mail
self["mail"] = mail