Skip to content

Commit

Permalink
py38 compat fixes (#376)
Browse files Browse the repository at this point in the history
* Update coverage library

* update coverage library also in setup

* explicitly call digestmod=md5 to make it work on 38

* try/except the whole loading the certs thing, hopefully it's fine

* Get rid of the flag
  • Loading branch information
kavigupta authored Oct 31, 2019
1 parent 04ea6ad commit 5142ed1
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 20 deletions.
38 changes: 22 additions & 16 deletions client/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,28 @@ def patch_requests():
"""
config.create_config_directory()
ca_certs_file = config.CERT_FILE
ca_certs_contents = requests.__loader__.get_data('requests/cacert.pem')

should_write_certs = True

if os.path.isfile(ca_certs_file):
with open(ca_certs_file, 'rb') as f:
existing_certs = f.read()
if existing_certs != ca_certs_contents:
should_write_certs = True
print("Updating local SSL certificates")
else:
should_write_certs = False

if should_write_certs:
with open(ca_certs_file, 'wb') as f:
f.write(ca_certs_contents)
ca_certs_contents = None
try:
ca_certs_contents = requests.__loader__.get_data('requests/cacert.pem')
except OSError:
# TODO(kavigupta) not sure why this is coming up???
pass

if ca_certs_contents is not None:
should_write_certs = True

if os.path.isfile(ca_certs_file):
with open(ca_certs_file, 'rb') as f:
existing_certs = f.read()
if existing_certs != ca_certs_contents:
should_write_certs = True
print("Updating local SSL certificates")
else:
should_write_certs = False

if should_write_certs:
with open(ca_certs_file, 'wb') as f:
f.write(ca_certs_contents)

os.environ['REQUESTS_CA_BUNDLE'] = ca_certs_file

Expand Down
2 changes: 1 addition & 1 deletion client/utils/locking.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

def lock(key, text):
"""Locks the given text using the given key and returns the result"""
return hmac.new(key.encode('utf-8'), text.encode('utf-8')).hexdigest()
return hmac.new(key.encode('utf-8'), text.encode('utf-8'), digestmod='md5').hexdigest()
2 changes: 1 addition & 1 deletion client/utils/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def set_foreign_function_type(func, restype, argtypes):
SECURITY_KEY = 'uMWm4sviPK3LyPzgWYFn'.encode('utf-8')

def mac(value):
mac = hmac.new(SECURITY_KEY)
mac = hmac.new(SECURITY_KEY, digestmod='md5')
mac.update(repr(value).encode('utf-8'))
return mac.hexdigest()

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Client
requests[security]==2.20.0
coverage==3.7.1
coverage==4.5.4

# Tests
nose==1.3.3
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@
],
install_requires=[
'requests==2.12.4',
'coverage==3.7.1'
'coverage==4.5.4'
],
)

0 comments on commit 5142ed1

Please sign in to comment.