Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1722)

Unified Diff: boto/file/key.py

Issue 8386013: Merging in latest boto. (Closed) Base URL: svn://svn.chromium.org/boto
Patch Set: Redoing vendor drop by deleting and then merging. Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « boto/file/bucket.py ('k') | boto/fps/connection.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: boto/file/key.py
diff --git a/boto/file/key.py b/boto/file/key.py
index af801a5e96d978bd87ed1af9d8950b066a581d64..6f66eda50c8c882c170e23d89a5a76a3b678e106 100755
--- a/boto/file/key.py
+++ b/boto/file/key.py
@@ -1,4 +1,5 @@
# Copyright 2010 Google Inc.
+# Copyright (c) 2011, Nexenta Systems Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
@@ -22,14 +23,31 @@
# File representation of key, for use with "file://" URIs.
import os, shutil, StringIO
+import sys
class Key(object):
- def __init__(self, bucket, name, fp=None):
+ KEY_STREAM_READABLE = 0x01
+ KEY_STREAM_WRITABLE = 0x02
+ KEY_STREAM = (KEY_STREAM_READABLE | KEY_STREAM_WRITABLE)
+ KEY_REGULAR_FILE = 0x00
+
+ def __init__(self, bucket, name, fp=None, key_type=KEY_REGULAR_FILE):
self.bucket = bucket
self.full_path = name
- self.name = name
- self.fp = fp
+ if name == '-':
+ self.name = None
+ else:
+ self.name = name
+ self.key_type = key_type
+ if key_type == self.KEY_STREAM_READABLE:
+ self.fp = sys.stdin
+ self.full_path = '<STDIN>'
+ elif key_type == self.KEY_STREAM_WRITABLE:
+ self.fp = sys.stdout
+ self.full_path = '<STDOUT>'
+ else:
+ self.fp = fp
def __str__(self):
return 'file://' + self.full_path
@@ -50,7 +68,12 @@ class Key(object):
:type cb: int
:param num_cb: ignored in this subclass.
"""
- key_file = open(self.full_path, 'rb')
+ if self.key_type & self.KEY_STREAM_READABLE:
+ raise BotoClientError('Stream is not Readable')
+ elif self.key_type & self.KEY_STREAM_WRITABLE:
+ key_file = self.fp
+ else:
+ key_file = open(self.full_path, 'rb')
shutil.copyfileobj(key_file, fp)
def set_contents_from_file(self, fp, headers=None, replace=True, cb=None,
@@ -88,9 +111,14 @@ class Key(object):
This is the same format returned by the compute_md5 method.
:param md5: ignored in this subclass.
"""
- if not replace and os.path.exists(self.full_path):
- return
- key_file = open(self.full_path, 'wb')
+ if self.key_type & self.KEY_STREAM_WRITABLE:
+ raise BotoClientError('Stream is not writable')
+ elif self.key_type & self.KEY_STREAM_READABLE:
+ key_file = self.fp
+ else:
+ if not replace and os.path.exists(self.full_path):
+ return
+ key_file = open(self.full_path, 'wb')
shutil.copyfileobj(fp, key_file)
key_file.close()
@@ -121,3 +149,6 @@ class Key(object):
fp = StringIO.StringIO()
self.get_contents_to_file(fp)
return fp.getvalue()
+
+ def is_stream(self):
+ return (self.key_type & self.KEY_STREAM)
« no previous file with comments | « boto/file/bucket.py ('k') | boto/fps/connection.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698