chore: remove uses of six.PY2 in codebase (#25062)
* remove uses of six.py2 in codebase * changes based on pr feedback * Update amazon_mws_api.py Co-authored-by: Ankush Menat <ankush@iwebnotes.com>
This commit is contained in:
parent
7b4a38c71e
commit
5457db0601
@ -7,6 +7,7 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import urllib
|
||||
from urllib.parse import quote
|
||||
import hashlib
|
||||
import hmac
|
||||
import base64
|
||||
@ -68,8 +69,9 @@ def calc_md5(string):
|
||||
"""
|
||||
md = hashlib.md5()
|
||||
md.update(string)
|
||||
return base64.encodestring(md.digest()).strip('\n') if six.PY2 \
|
||||
else base64.encodebytes(md.digest()).decode().strip()
|
||||
return base64.encodebytes(md.digest()).decode().strip()
|
||||
|
||||
|
||||
|
||||
def remove_empty(d):
|
||||
"""
|
||||
@ -177,7 +179,6 @@ class MWS(object):
|
||||
'SignatureMethod': 'HmacSHA256',
|
||||
}
|
||||
params.update(extra_data)
|
||||
quote = urllib.quote if six.PY2 else urllib.parse.quote
|
||||
request_description = '&'.join(['%s=%s' % (k, quote(params[k], safe='-_.~')) for k in sorted(params)])
|
||||
signature = self.calc_signature(method, request_description)
|
||||
url = '%s%s?%s&Signature=%s' % (self.domain, self.uri, request_description, quote(signature))
|
||||
|
@ -55,8 +55,7 @@ def get_datev_csv(data, filters, csv_class):
|
||||
quoting=QUOTE_NONNUMERIC
|
||||
)
|
||||
|
||||
if not six.PY2:
|
||||
data = data.encode('latin_1', errors='replace')
|
||||
data = data.encode('latin_1', errors='replace')
|
||||
|
||||
header = get_header(filters, csv_class)
|
||||
header = ';'.join(header).encode('latin_1', errors='replace')
|
||||
|
@ -534,11 +534,9 @@ def santize_einvoice_fields(einvoice):
|
||||
return einvoice
|
||||
|
||||
def safe_json_load(json_string):
|
||||
JSONDecodeError = ValueError if six.PY2 else json.JSONDecodeError
|
||||
|
||||
try:
|
||||
return json.loads(json_string)
|
||||
except JSONDecodeError as e:
|
||||
except json.JSONDecodeError as e:
|
||||
# print a snippet of 40 characters around the location where error occured
|
||||
pos = e.pos
|
||||
start, end = max(0, pos-20), min(len(json_string)-1, pos+20)
|
||||
|
Loading…
x
Reference in New Issue
Block a user