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:
krishnagirishp
2021-05-23 21:13:44 +05:30
committed by GitHub
parent 7b4a38c71e
commit 5457db0601
3 changed files with 6 additions and 8 deletions

View File

@@ -7,6 +7,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import urllib import urllib
from urllib.parse import quote
import hashlib import hashlib
import hmac import hmac
import base64 import base64
@@ -68,8 +69,9 @@ def calc_md5(string):
""" """
md = hashlib.md5() md = hashlib.md5()
md.update(string) md.update(string)
return base64.encodestring(md.digest()).strip('\n') if six.PY2 \ return base64.encodebytes(md.digest()).decode().strip()
else base64.encodebytes(md.digest()).decode().strip()
def remove_empty(d): def remove_empty(d):
""" """
@@ -177,7 +179,6 @@ class MWS(object):
'SignatureMethod': 'HmacSHA256', 'SignatureMethod': 'HmacSHA256',
} }
params.update(extra_data) 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)]) request_description = '&'.join(['%s=%s' % (k, quote(params[k], safe='-_.~')) for k in sorted(params)])
signature = self.calc_signature(method, request_description) signature = self.calc_signature(method, request_description)
url = '%s%s?%s&Signature=%s' % (self.domain, self.uri, request_description, quote(signature)) url = '%s%s?%s&Signature=%s' % (self.domain, self.uri, request_description, quote(signature))

View File

@@ -55,8 +55,7 @@ def get_datev_csv(data, filters, csv_class):
quoting=QUOTE_NONNUMERIC 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 = get_header(filters, csv_class)
header = ';'.join(header).encode('latin_1', errors='replace') header = ';'.join(header).encode('latin_1', errors='replace')

View File

@@ -534,11 +534,9 @@ def santize_einvoice_fields(einvoice):
return einvoice return einvoice
def safe_json_load(json_string): def safe_json_load(json_string):
JSONDecodeError = ValueError if six.PY2 else json.JSONDecodeError
try: try:
return json.loads(json_string) 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 # print a snippet of 40 characters around the location where error occured
pos = e.pos pos = e.pos
start, end = max(0, pos-20), min(len(json_string)-1, pos+20) start, end = max(0, pos-20), min(len(json_string)-1, pos+20)