diff options
author | James Saryerwinnie <js@jamesls.com> | 2013-04-18 04:14:08 -0700 |
---|---|---|
committer | James Saryerwinnie <js@jamesls.com> | 2013-04-18 04:14:08 -0700 |
commit | 89f4947000587e12042e5b35c4557871b21137b9 (patch) | |
tree | 0606c64058f8402e74b29c621105b74292ff366c /boto/file/key.py | |
parent | b5852b0aa5ac91f462b28ac9decee33d872dec4d (diff) | |
parent | 699d861f453aff8a398f9cd5a8de91ec8e36a8cf (diff) | |
download | boto-2.9.0.tar.gz |
Merge branch 'release-2.9.0'2.9.0
* release-2.9.0: (158 commits)
Bump version to 2.9.0
Added underlying DynamoDB v2 support.
Add redshift to setup.py/docs index
Updated requests to something more modern.
Only use 2 metadata service calls to get credentials
Fix #1146: return response from custom url opener
Fixed missing import.
Add metadata_service_num_attempts config option
Added cleanup for the snapshots created.
Added support for redshift.
Let total attempts by 1 + num_retries
Add more diagnostics to debug logs
Change GS calls to make_request to always convert to utf-8 bytes.
Allow kwargs to be passed through to uplaoder
Remove whitespace, fix long line lengths
Improve VPC and VPN support
Added sleeps to allow amazon time to propogate
Added error handling for out of space during downloads
Initial integration tests for idempotent subscribe
Removed dead code from resumable upload handler
...
Diffstat (limited to 'boto/file/key.py')
-rwxr-xr-x | boto/file/key.py | 41 |
1 files changed, 36 insertions, 5 deletions
diff --git a/boto/file/key.py b/boto/file/key.py index d39c8c65..2f20cae5 100755 --- a/boto/file/key.py +++ b/boto/file/key.py @@ -37,8 +37,10 @@ class Key(object): self.full_path = name if name == '-': self.name = None + self.size = None else: self.name = name + self.size = os.stat(name).st_size self.key_type = key_type if key_type == self.KEY_STREAM_READABLE: self.fp = sys.stdin @@ -68,9 +70,9 @@ class Key(object): :type cb: int :param num_cb: ignored in this subclass. """ - if self.key_type & self.KEY_STREAM_READABLE: - raise BotoClientError('Stream is not Readable') - elif self.key_type & self.KEY_STREAM_WRITABLE: + if self.key_type & self.KEY_STREAM_WRITABLE: + raise BotoClientError('Stream is not readable') + elif self.key_type & self.KEY_STREAM_READABLE: key_file = self.fp else: key_file = open(self.full_path, 'rb') @@ -114,9 +116,9 @@ class Key(object): This is the same format returned by the compute_md5 method. :param md5: ignored in this subclass. """ - if self.key_type & self.KEY_STREAM_WRITABLE: + if self.key_type & self.KEY_STREAM_READABLE: raise BotoClientError('Stream is not writable') - elif self.key_type & self.KEY_STREAM_READABLE: + elif self.key_type & self.KEY_STREAM_WRITABLE: key_file = self.fp else: if not replace and os.path.exists(self.full_path): @@ -127,6 +129,35 @@ class Key(object): finally: key_file.close() + def get_contents_to_file(self, fp, headers=None, cb=None, num_cb=None, + torrent=False, version_id=None, + res_download_handler=None, response_headers=None): + """ + Copy contents from the current file to the file pointed to by 'fp'. + + :type fp: File-like object + :param fp: + + :type headers: dict + :param headers: Unused in this subclass. + + :type cb: function + :param cb: Unused in this subclass. + + :type cb: int + :param num_cb: Unused in this subclass. + + :type torrent: bool + :param torrent: Unused in this subclass. + + :type res_upload_handler: ResumableDownloadHandler + :param res_download_handler: Unused in this subclass. + + :type response_headers: dict + :param response_headers: Unused in this subclass. + """ + shutil.copyfileobj(self.fp, fp) + def get_contents_as_string(self, headers=None, cb=None, num_cb=10, torrent=False): """ |