0001-misc-migrate-code-to-python-3-58944.patch
eopayment/__init__.py | ||
---|---|---|
20 | 20 |
import logging |
21 | 21 |
import pytz |
22 | 22 | |
23 |
import six |
|
24 | ||
25 | 23 |
from .common import ( # noqa: F401 |
26 | 24 |
URL, HTML, FORM, RECEIVED, ACCEPTED, PAID, DENIED, |
27 | 25 |
CANCELED, CANCELLED, ERROR, WAITING, EXPIRED, force_text, |
... | ... | |
31 | 29 |
__all__ = ['Payment', 'URL', 'HTML', 'FORM', 'SIPS', 'SYSTEMPAY', |
32 | 30 |
'TIPI', 'DUMMY', 'get_backend', 'RECEIVED', 'ACCEPTED', 'PAID', |
33 | 31 |
'DENIED', 'CANCELED', 'CANCELLED', 'ERROR', 'WAITING', |
34 |
'EXPIRED', 'get_backends', 'PAYFIP_WS', 'SAGA'] |
|
35 | ||
36 |
if six.PY3: |
|
37 |
__all__.extend(['KEYWARE', 'MOLLIE']) |
|
32 |
'EXPIRED', 'get_backends', 'PAYFIP_WS', 'SAGA', 'KEYWARE', 'MOLLIE'] |
|
38 | 33 | |
39 | 34 |
SIPS = 'sips' |
40 | 35 |
SIPS2 = 'sips2' |
eopayment/common.py | ||
---|---|---|
24 | 24 | |
25 | 25 |
import six |
26 | 26 | |
27 |
if six.PY3: |
|
28 |
import html |
|
29 |
else: |
|
30 |
import cgi |
|
27 |
import html |
|
31 | 28 | |
32 | 29 | |
33 | 30 |
from gettext import gettext as _ |
... | ... | |
68 | 65 |
return s |
69 | 66 |
try: |
70 | 67 |
if not issubclass(type(s), six.string_types): |
71 |
if six.PY3: |
|
72 |
if isinstance(s, bytes): |
|
73 |
s = six.text_type(s, encoding) |
|
74 |
else: |
|
75 |
s = six.text_type(s) |
|
76 |
elif hasattr(s, '__unicode__'): |
|
77 |
s = six.text_type(s) |
|
68 |
if isinstance(s, bytes): |
|
69 |
s = six.text_type(s, encoding) |
|
78 | 70 |
else: |
79 |
s = six.text_type(bytes(s), encoding)
|
|
71 |
s = six.text_type(s)
|
|
80 | 72 |
else: |
81 | 73 |
s = s.decode(encoding) |
82 | 74 |
except UnicodeDecodeError: |
... | ... | |
217 | 209 |
return s |
218 | 210 | |
219 | 211 |
def escape(self, s): |
220 |
if six.PY3: |
|
221 |
return html.escape(force_text(s, self.encoding)) |
|
222 |
else: |
|
223 |
return cgi.escape(force_text(s, self.encoding)).encode(self.encoding) |
|
212 |
return html.escape(force_text(s, self.encoding)) |
|
213 | ||
224 | 214 | |
225 | 215 |
def __str__(self): |
226 | 216 |
s = '<form method="%s" action="%s">' % (self.method, self.url) |
eopayment/ogone.py | ||
---|---|---|
18 | 18 |
from decimal import Decimal, ROUND_HALF_UP |
19 | 19 |
from six.moves.urllib import parse as urlparse |
20 | 20 |
import hashlib |
21 |
import six |
|
22 | 21 |
import uuid |
23 | 22 | |
24 | 23 |
from .common import ( |
... | ... | |
578 | 577 |
return complus, FORM, form |
579 | 578 | |
580 | 579 |
def response(self, query_string, **kwargs): |
581 |
if six.PY3: |
|
582 |
params = urlparse.parse_qs(query_string, True, encoding=self.encoding) |
|
583 |
else: |
|
584 |
params = urlparse.parse_qs(query_string, True) |
|
580 |
params = urlparse.parse_qs(query_string, True, encoding=self.encoding) |
|
585 | 581 |
params = dict((key.upper(), params[key][0]) for key in params) |
586 | 582 |
if not set(params) >= set(['ORDERID', 'PAYID', 'STATUS', 'NCERROR']): |
587 | 583 |
raise ResponseError('missing ORDERID, PAYID, STATUS or NCERROR') |
eopayment/paybox.py | ||
---|---|---|
31 | 31 |
from Crypto.PublicKey import RSA |
32 | 32 |
from Crypto.Hash import SHA |
33 | 33 | |
34 |
import six |
|
35 | 34 |
from six.moves.urllib import parse as urlparse |
36 | 35 |
from six.moves.urllib import parse as urllib |
37 | 36 | |
... | ... | |
352 | 351 |
d['PBX_REPONDRE_A'] = force_text(automatic_return_url) |
353 | 352 |
d = d.items() |
354 | 353 | |
355 |
if six.PY3: |
|
356 |
shared_secret = codecs.decode(bytes(self.shared_secret, 'ascii'), 'hex') |
|
357 |
else: |
|
358 |
shared_secret = codecs.decode(bytes(self.shared_secret), 'hex') |
|
354 | ||
355 |
shared_secret = codecs.decode(bytes(self.shared_secret, 'ascii'), 'hex') |
|
359 | 356 |
d = sign(d, shared_secret) |
360 | 357 |
url = URLS[self.platform] |
361 | 358 |
fields = [] |
... | ... | |
446 | 443 |
logger.debug('received %r', response.text) |
447 | 444 |
data = dict(urlparse.parse_qsl(response.text, True, True)) |
448 | 445 |
if data.get('CODEREPONSE') != PAYBOX_DIRECT_SUCCESS_RESPONSE_CODE: |
449 |
if six.PY2: |
|
450 |
raise ResponseError(data['COMMENTAIRE'].encode('utf-8')) |
|
451 | 446 |
raise ResponseError(data['COMMENTAIRE']) |
452 | 447 |
return data |
453 | 448 |
eopayment/systempayv2.py | ||
---|---|---|
23 | 23 |
import random |
24 | 24 |
import re |
25 | 25 |
import string |
26 |
import six |
|
27 | 26 |
from six.moves.urllib import parse as urlparse |
28 | 27 |
import warnings |
29 | 28 | |
... | ... | |
300 | 299 |
# trans_id starting with 9 are reserved for the systempay backoffice |
301 | 300 |
# https://paiement.systempay.fr/doc/fr-FR/form-payment/reference/vads-trans-id.html |
302 | 301 |
gen = random.SystemRandom() |
303 |
if six.PY3: |
|
304 |
alphabet = string.ascii_letters + string.digits |
|
305 |
else: |
|
306 |
alphabet = string.letters + string.digits |
|
302 | ||
303 |
alphabet = string.ascii_letters + string.digits |
|
307 | 304 |
first_letter_alphabet = alphabet.replace('9', '') |
308 | 305 |
vads_trans_id = ( |
309 | 306 |
gen.choice(first_letter_alphabet) |
tests/test_keyware.py | ||
---|---|---|
18 | 18 | |
19 | 19 |
import pytest |
20 | 20 |
import requests |
21 |
import six |
|
22 | 21 |
from httmock import response, urlmatch, HTTMock, with_httmock, all_requests, remember_called |
23 | 22 | |
24 | 23 |
import eopayment |
25 | 24 |
from eopayment.keyware import Payment |
26 | 25 | |
27 |
pytestmark = pytest.mark.skipif(six.PY2, reason='this payment module only supports python3') |
|
28 | ||
29 | 26 |
WEBHOOK_URL = 'https://callback.example.com' |
30 | 27 |
RETURN_URL = 'https://return.example.com' |
31 | 28 |
API_KEY = 'test' |
tests/test_mollie.py | ||
---|---|---|
17 | 17 |
import json |
18 | 18 | |
19 | 19 |
import requests |
20 |
import six |
|
21 | 20 | |
22 | 21 |
import eopayment |
23 | 22 |
import pytest |
24 | 23 |
from eopayment.mollie import Payment |
25 | 24 |
from httmock import remember_called, response, urlmatch, with_httmock |
26 | 25 | |
27 |
pytestmark = pytest.mark.skipif(six.PY2, reason='this payment module only supports python3') |
|
28 | ||
29 | 26 |
WEBHOOK_URL = 'https://callback.example.com' |
30 | 27 |
RETURN_URL = 'https://return.example.com' |
31 | 28 |
API_KEY = 'test' |
tests/test_paybox.py | ||
---|---|---|
21 | 21 |
from decimal import Decimal |
22 | 22 |
import base64 |
23 | 23 |
import mock |
24 |
import six |
|
25 | 24 |
from six.moves.urllib import parse as urllib |
26 | 25 |
from xml.etree import ElementTree as ET |
27 | 26 | |
... | ... | |
47 | 46 | |
48 | 47 | |
49 | 48 |
class PayboxTests(TestCase): |
50 |
if six.PY2: |
|
51 |
def assertRaisesRegex(self, *args, **kwargs): |
|
52 |
return self.assertRaisesRegexp(*args, **kwargs) |
|
53 | 49 | |
54 | 50 |
def test_sign(self): |
55 | 51 |
key = (b'0123456789ABCDEF0123456789ABCDEF0123456789' |
56 |
- |