misc: migrate code to python 3 (#58944)
This commit is contained in:
parent
0f59994d80
commit
19ab05d59e
|
@ -20,8 +20,6 @@ import importlib
|
|||
import logging
|
||||
import pytz
|
||||
|
||||
import six
|
||||
|
||||
from .common import ( # noqa: F401
|
||||
URL, HTML, FORM, RECEIVED, ACCEPTED, PAID, DENIED,
|
||||
CANCELED, CANCELLED, ERROR, WAITING, EXPIRED, force_text,
|
||||
|
@ -31,10 +29,7 @@ from .common import ( # noqa: F401
|
|||
__all__ = ['Payment', 'URL', 'HTML', 'FORM', 'SIPS', 'SYSTEMPAY',
|
||||
'TIPI', 'DUMMY', 'get_backend', 'RECEIVED', 'ACCEPTED', 'PAID',
|
||||
'DENIED', 'CANCELED', 'CANCELLED', 'ERROR', 'WAITING',
|
||||
'EXPIRED', 'get_backends', 'PAYFIP_WS', 'SAGA']
|
||||
|
||||
if six.PY3:
|
||||
__all__.extend(['KEYWARE', 'MOLLIE'])
|
||||
'EXPIRED', 'get_backends', 'PAYFIP_WS', 'SAGA', 'KEYWARE', 'MOLLIE']
|
||||
|
||||
SIPS = 'sips'
|
||||
SIPS2 = 'sips2'
|
||||
|
|
|
@ -24,10 +24,7 @@ from decimal import ROUND_DOWN, Decimal
|
|||
|
||||
import six
|
||||
|
||||
if six.PY3:
|
||||
import html
|
||||
else:
|
||||
import cgi
|
||||
import html
|
||||
|
||||
|
||||
from gettext import gettext as _
|
||||
|
@ -68,15 +65,10 @@ def force_text(s, encoding='utf-8'):
|
|||
return s
|
||||
try:
|
||||
if not issubclass(type(s), six.string_types):
|
||||
if six.PY3:
|
||||
if isinstance(s, bytes):
|
||||
s = six.text_type(s, encoding)
|
||||
else:
|
||||
s = six.text_type(s)
|
||||
elif hasattr(s, '__unicode__'):
|
||||
s = six.text_type(s)
|
||||
if isinstance(s, bytes):
|
||||
s = six.text_type(s, encoding)
|
||||
else:
|
||||
s = six.text_type(bytes(s), encoding)
|
||||
s = six.text_type(s)
|
||||
else:
|
||||
s = s.decode(encoding)
|
||||
except UnicodeDecodeError:
|
||||
|
@ -217,10 +209,8 @@ class Form(object):
|
|||
return s
|
||||
|
||||
def escape(self, s):
|
||||
if six.PY3:
|
||||
return html.escape(force_text(s, self.encoding))
|
||||
else:
|
||||
return cgi.escape(force_text(s, self.encoding)).encode(self.encoding)
|
||||
return html.escape(force_text(s, self.encoding))
|
||||
|
||||
|
||||
def __str__(self):
|
||||
s = '<form method="%s" action="%s">' % (self.method, self.url)
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
from decimal import Decimal, ROUND_HALF_UP
|
||||
from six.moves.urllib import parse as urlparse
|
||||
import hashlib
|
||||
import six
|
||||
import uuid
|
||||
|
||||
from .common import (
|
||||
|
@ -578,10 +577,7 @@ class Payment(PaymentCommon):
|
|||
return complus, FORM, form
|
||||
|
||||
def response(self, query_string, **kwargs):
|
||||
if six.PY3:
|
||||
params = urlparse.parse_qs(query_string, True, encoding=self.encoding)
|
||||
else:
|
||||
params = urlparse.parse_qs(query_string, True)
|
||||
params = urlparse.parse_qs(query_string, True, encoding=self.encoding)
|
||||
params = dict((key.upper(), params[key][0]) for key in params)
|
||||
if not set(params) >= set(['ORDERID', 'PAYID', 'STATUS', 'NCERROR']):
|
||||
raise ResponseError('missing ORDERID, PAYID, STATUS or NCERROR')
|
||||
|
|
|
@ -31,7 +31,6 @@ from Crypto.Signature import PKCS1_v1_5
|
|||
from Crypto.PublicKey import RSA
|
||||
from Crypto.Hash import SHA
|
||||
|
||||
import six
|
||||
from six.moves.urllib import parse as urlparse
|
||||
from six.moves.urllib import parse as urllib
|
||||
|
||||
|
@ -352,10 +351,8 @@ class Payment(PaymentCommon):
|
|||
d['PBX_REPONDRE_A'] = force_text(automatic_return_url)
|
||||
d = d.items()
|
||||
|
||||
if six.PY3:
|
||||
shared_secret = codecs.decode(bytes(self.shared_secret, 'ascii'), 'hex')
|
||||
else:
|
||||
shared_secret = codecs.decode(bytes(self.shared_secret), 'hex')
|
||||
|
||||
shared_secret = codecs.decode(bytes(self.shared_secret, 'ascii'), 'hex')
|
||||
d = sign(d, shared_secret)
|
||||
url = URLS[self.platform]
|
||||
fields = []
|
||||
|
@ -446,8 +443,6 @@ class Payment(PaymentCommon):
|
|||
logger.debug('received %r', response.text)
|
||||
data = dict(urlparse.parse_qsl(response.text, True, True))
|
||||
if data.get('CODEREPONSE') != PAYBOX_DIRECT_SUCCESS_RESPONSE_CODE:
|
||||
if six.PY2:
|
||||
raise ResponseError(data['COMMENTAIRE'].encode('utf-8'))
|
||||
raise ResponseError(data['COMMENTAIRE'])
|
||||
return data
|
||||
|
||||
|
|
|
@ -23,7 +23,6 @@ import hmac
|
|||
import random
|
||||
import re
|
||||
import string
|
||||
import six
|
||||
from six.moves.urllib import parse as urlparse
|
||||
import warnings
|
||||
|
||||
|
@ -300,10 +299,8 @@ class Payment(PaymentCommon):
|
|||
# trans_id starting with 9 are reserved for the systempay backoffice
|
||||
# https://paiement.systempay.fr/doc/fr-FR/form-payment/reference/vads-trans-id.html
|
||||
gen = random.SystemRandom()
|
||||
if six.PY3:
|
||||
alphabet = string.ascii_letters + string.digits
|
||||
else:
|
||||
alphabet = string.letters + string.digits
|
||||
|
||||
alphabet = string.ascii_letters + string.digits
|
||||
first_letter_alphabet = alphabet.replace('9', '')
|
||||
vads_trans_id = (
|
||||
gen.choice(first_letter_alphabet)
|
||||
|
|
|
@ -18,14 +18,11 @@ import json
|
|||
|
||||
import pytest
|
||||
import requests
|
||||
import six
|
||||
from httmock import response, urlmatch, HTTMock, with_httmock, all_requests, remember_called
|
||||
|
||||
import eopayment
|
||||
from eopayment.keyware import Payment
|
||||
|
||||
pytestmark = pytest.mark.skipif(six.PY2, reason='this payment module only supports python3')
|
||||
|
||||
WEBHOOK_URL = 'https://callback.example.com'
|
||||
RETURN_URL = 'https://return.example.com'
|
||||
API_KEY = 'test'
|
||||
|
|
|
@ -17,15 +17,12 @@
|
|||
import json
|
||||
|
||||
import requests
|
||||
import six
|
||||
|
||||
import eopayment
|
||||
import pytest
|
||||
from eopayment.mollie import Payment
|
||||
from httmock import remember_called, response, urlmatch, with_httmock
|
||||
|
||||
pytestmark = pytest.mark.skipif(six.PY2, reason='this payment module only supports python3')
|
||||
|
||||
WEBHOOK_URL = 'https://callback.example.com'
|
||||
RETURN_URL = 'https://return.example.com'
|
||||
API_KEY = 'test'
|
||||
|
|
|
@ -21,7 +21,6 @@ from unittest import TestCase
|
|||
from decimal import Decimal
|
||||
import base64
|
||||
import mock
|
||||
import six
|
||||
from six.moves.urllib import parse as urllib
|
||||
from xml.etree import ElementTree as ET
|
||||
|
||||
|
@ -47,9 +46,6 @@ BACKEND_PARAMS = {
|
|||
|
||||
|
||||
class PayboxTests(TestCase):
|
||||
if six.PY2:
|
||||
def assertRaisesRegex(self, *args, **kwargs):
|
||||
return self.assertRaisesRegexp(*args, **kwargs)
|
||||
|
||||
def test_sign(self):
|
||||
key = (b'0123456789ABCDEF0123456789ABCDEF0123456789'
|
||||
|
|
Loading…
Reference in New Issue