Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix url parsing for S3 #235

Merged
merged 1 commit into from
Sep 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions smart_open/smart_open_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@


Uri = collections.namedtuple(
'Uri',
'Uri',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My text editor did this 🤷‍♂️

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's ok, don't worry

(
'scheme',
'uri_path',
Expand Down Expand Up @@ -488,7 +488,7 @@ def _parse_uri_s3x(parsed_uri):
try:
uri = parsed_uri.netloc + parsed_uri.path
# Separate authentication from URI if exist
if ':' in uri.split('@')[0]:
if ':' in uri.split('@')[0] and '@' in uri:
auth, uri = uri.split('@', 1)
access_id, access_secret = auth.split(':')
else:
Expand Down
9 changes: 9 additions & 0 deletions smart_open/tests/test_smart_open.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@ def test_uri_from_issue_223_works(self):
self.assertEqual(parsed_uri.access_id, "")
self.assertEqual(parsed_uri.access_secret, "")

def test_s3_uri_with_colon_in_key_name(self):
""" Correctly parse the s3 url if there is a colon in the key or dir """
parsed_uri = smart_open_lib._parse_uri("s3://mybucket/mydir/my:key")
self.assertEqual(parsed_uri.scheme, "s3")
self.assertEqual(parsed_uri.bucket_id, "mybucket")
self.assertEqual(parsed_uri.key_id, "mydir/my:key")
self.assertEqual(parsed_uri.access_id, None)
self.assertEqual(parsed_uri.access_secret, None)


class SmartOpenHttpTest(unittest.TestCase):
"""
Expand Down