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)
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)
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)
def open(self): obj = self.s3_bucket.Object(self.key).get() return ClosingContextProxy(obj["Body"])
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