Skip to content

Commit

Permalink
backward compatibility fixes (#294)
Browse files Browse the repository at this point in the history
* backward compatibility fixes

* disable certain tests under Py2

* get rid of unused s3_upload keyword argument
  • Loading branch information
mpenkov authored Apr 17, 2019
1 parent 9d5f32c commit b0d97b4
Show file tree
Hide file tree
Showing 3 changed files with 1,068 additions and 1 deletion.
1 change: 0 additions & 1 deletion smart_open/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,6 @@ def __init__(
bucket,
key,
min_part_size=DEFAULT_MIN_PART_SIZE,
s3_upload=None,
session=None,
resource_kwargs=dict(),
multipart_upload_kwargs=dict(),
Expand Down
33 changes: 33 additions & 0 deletions smart_open/smart_open_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,39 @@ def smart_open(uri, mode="rb", **kw):
expected_kwargs = _inspect_kwargs(open)
scrubbed_kwargs = {}
transport_params = {}

#
# Handle renamed keyword arguments. This is required to maintain backward
# compatibility. See test_smart_open_old.py for tests.
#
if 'host' in kw or 's3_upload' in kw:
transport_params['multipart_upload_kwargs'] = {}
transport_params['resource_kwargs'] = {}

if 'host' in kw:
url = kw.pop('host')
if not url.startswith('http'):
url = 'http://' + url
transport_params['multipart_upload_kwargs'].update(endpoint_url=url)
transport_params['resource_kwargs'].update(endpoint_url=url)

if 's3_upload' in kw:
transport_params['multipart_upload_kwargs'].update(**kw.pop('s3_upload'))

#
# Providing the entire Session object as opposed to just the profile name
# is more flexible and powerful, and thus preferable in the case of
# conflict.
#
if 'profile_name' in kw and 's3_session' in kw:
logger.error('profile_name and s3_session are mutually exclusive, ignoring the former')

if 'profile_name' in kw:
transport_params['session'] = boto3.Session(profile_name=kw.pop('profile_name'))

if 's3_session' in kw:
transport_params['session'] = kw.pop('s3_session')

for key, value in kw.items():
if key in expected_kwargs:
scrubbed_kwargs[key] = value
Expand Down
Loading

0 comments on commit b0d97b4

Please sign in to comment.