Python 3.6 compatibility: bytes vs strings stuff

These changes mostly revolve around the change in ObjectId constructor
when running on Python 3.6. Where on 2.7 the constructor would accept
12- and 24-byte strings, now only 12-byte bytes and 24-character strings
are accepted. Good thing, but required some changes in our code.

Other changes include hashing of strings, which isn't supported, so they
are converted to bytes first, and sometimes converted back afterwards.
This commit is contained in:
2017-03-03 14:14:36 +01:00
parent c2206e6b27
commit 2e41c074b5
12 changed files with 62 additions and 46 deletions

View File

@@ -296,7 +296,7 @@ def delete_file(file_item):
process_file_delete(file_item)
def generate_link(backend, file_path, project_id=None, is_public=False):
def generate_link(backend, file_path: str, project_id=None, is_public=False):
"""Hook to check the backend of a file resource, to build an appropriate link
that can be used by the client to retrieve the actual file.
"""
@@ -328,7 +328,7 @@ def generate_link(backend, file_path, project_id=None, is_public=False):
if backend == 'cdnsun':
return hash_file_path(file_path, None)
if backend == 'unittest':
return 'https://unit.test/%s' % md5(file_path).hexdigest()
return 'https://unit.test/%s' % md5(file_path.encode()).hexdigest()
log.warning('generate_link(): Unknown backend %r, returning empty string '
'as new link.',