Beispiel #1
0
 def fetch_attachment(self, name, stream=False):
     if self._deferred_blobs and name in self._deferred_blobs:
         body = self._deferred_blobs[name]["content"]
         if stream:
             return ClosingContextProxy(StringIO(body))
         try:
             body = body.decode("utf-8", "strict")
         except UnicodeDecodeError:
             # Return bytes on decode failure, otherwise unicode.
             # Ugly, but consistent with restkit.wrappers.Response.body_string
             pass
         return body
     return super(DeferredBlobMixin, self).fetch_attachment(name, stream)
Beispiel #2
0
 def fetch_attachment(self, name, stream=False):
     if self._deferred_blobs and name in self._deferred_blobs:
         if self._deferred_blobs[name] is None:
             raise ResourceNotFound(
                 "{model} {model_id} attachment: {name!r}".format(
                     model=type(self).__name__,
                     model_id=self._id,
                     name=name,
                 ))
         body = self._deferred_blobs[name]["content"]
         if stream:
             return ClosingContextProxy(BytesIO(body))
         return body
     return super(DeferredBlobMixin, self).fetch_attachment(name, stream)
Beispiel #3
0
 def fetch_attachment(self, name, stream=False):
     if self._deferred_blobs and name in self._deferred_blobs:
         if self._deferred_blobs[name] is None:
             raise ResourceNotFound(
                 u"{model} {model_id} attachment: {name!r}".format(
                     model=type(self).__name__,
                     model_id=self._id,
                     name=name,
                 ))
         body = self._deferred_blobs[name]["content"]
         if stream:
             return ClosingContextProxy(StringIO(body))
         try:
             body = body.decode("utf-8", "strict")
         except UnicodeDecodeError:
             # Return bytes on decode failure, otherwise unicode.
             # Ugly, but consistent with restkit.wrappers.Response.body_string
             pass
         return body
     return super(DeferredBlobMixin, self).fetch_attachment(name, stream)
Beispiel #4
0
 def open(self):
     obj = self.s3_bucket.Object(self.key).get()
     return ClosingContextProxy(obj["Body"])
Beispiel #5
0
 def get(self, identifier, bucket=DEFAULT_BUCKET):
     path = self.get_path(identifier, bucket)
     with maybe_not_found(throw=NotFound(identifier, bucket)):
         resp = self._s3_bucket().Object(path).get()
     return ClosingContextProxy(resp["Body"])  # body stream