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

smart_open/s3: Initial implementations of str and repr #359

Merged
merged 7 commits into from Oct 6, 2019
38 changes: 38 additions & 0 deletions smart_open/s3.py
Expand Up @@ -412,6 +412,26 @@ def truncate(self, size=None):
"""Unsupported."""
raise io.UnsupportedOperation

def __str__(self):
return ("smart_open.s3.SeekableBufferedInputBase(%r, %r)") % (
zlatsic marked this conversation as resolved.
Show resolved Hide resolved
self._object.bucket_name,
self._object.key
)

def __repr__(self):
return (
"smart_open.s3.SeekableBufferedInputBase("
mpenkov marked this conversation as resolved.
Show resolved Hide resolved
"bucket_name=%r, "
"key=%r, "
"version_id=%r, "
"line_terminator=%r, "
) % (
self._object.bucket_name,
self._object.key,
self._version_id,
self._line_terminator,
)


class BufferedOutputBase(io.BufferedIOBase):
"""Writes bytes to S3.
Expand Down Expand Up @@ -553,6 +573,24 @@ def __exit__(self, exc_type, exc_val, exc_tb):
else:
self.close()

def __str__(self):
return "smart_open.s3.BufferedOutputBase(%r, %r)" % (
self._object.bucket_name,
self._object.key
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
self._object.key
self._object.key,

But really, I think the above should fit on one line and still be within limits.

)

def __repr__(self):
return (
"smart_open.s3.BufferedOutputBase("
"bucket_name=%r, "
"key=%r, "
"min_part_size=%r)"
) % (
self._object.bucket_name,
self._object.key,
self._min_part_size,
)


def iter_bucket(bucket_name, prefix='', accept_key=None,
key_limit=None, workers=16, retries=3):
Expand Down