MCPcopy Create free account
hub / github.com/aws/aws-cli / InterruptReader

Class InterruptReader

awscli/s3transfer/upload.py:66–107  ·  view source on GitHub ↗

Wrapper that can interrupt reading using an error It uses a transfer coordinator to propagate an error if it notices that a read is being made while the file is being read from. :type fileobj: file-like obj :param fileobj: The file-like object to read from :type transfer_coord

Source from the content-addressed store, hash-verified

64
65
66class InterruptReader:
67 """Wrapper that can interrupt reading using an error
68
69 It uses a transfer coordinator to propagate an error if it notices
70 that a read is being made while the file is being read from.
71
72 :type fileobj: file-like obj
73 :param fileobj: The file-like object to read from
74
75 :type transfer_coordinator: s3transfer.futures.TransferCoordinator
76 :param transfer_coordinator: The transfer coordinator to use if the
77 reader needs to be interrupted.
78 """
79
80 def __init__(self, fileobj, transfer_coordinator):
81 self._fileobj = fileobj
82 self._transfer_coordinator = transfer_coordinator
83
84 def read(self, amount=None):
85 # If there is an exception, then raise the exception.
86 # We raise an error instead of returning no bytes because for
87 # requests where the content length and md5 was sent, it will
88 # cause md5 mismatches and retries as there was no indication that
89 # the stream being read from encountered any issues.
90 if self._transfer_coordinator.exception:
91 raise self._transfer_coordinator.exception
92 return self._fileobj.read(amount)
93
94 def seek(self, where, whence=0):
95 self._fileobj.seek(where, whence)
96
97 def tell(self):
98 return self._fileobj.tell()
99
100 def close(self):
101 self._fileobj.close()
102
103 def __enter__(self):
104 return self
105
106 def __exit__(self, *args, **kwargs):
107 self.close()
108
109
110class UploadInputManager:

Callers 4

test_seekMethod · 0.90
test_tellMethod · 0.90
_wrap_fileobjMethod · 0.85

Calls

no outgoing calls

Tested by 3

test_seekMethod · 0.72
test_tellMethod · 0.72