MCPcopy
hub / github.com/hyperopt/hyperopt / get_attachment

Method get_attachment

hyperopt/mongoexp.py:632–645  ·  view source on GitHub ↗

Retrieve data attached to `doc` by `attach_blob`. Raises OperationFailure if `name` does not correspond to an attached blob. Returns the blob as a string.

(self, doc, name)

Source from the content-addressed store, hash-verified

630 # return new_file_id
631
632 def get_attachment(self, doc, name):
633 """Retrieve data attached to `doc` by `attach_blob`.
634
635 Raises OperationFailure if `name` does not correspond to an attached blob.
636
637 Returns the blob as a string.
638 """
639 attachments = doc.get("_attachments", [])
640 file_ids = [a[1] for a in attachments if a[0] == name]
641 if not file_ids:
642 raise OperationFailure("Attachment not found: %s" % name)
643 if len(file_ids) > 1:
644 raise OperationFailure("multiple name matches", (name, file_ids))
645 return self.gfs.get(file_ids[0]).read()
646
647 def delete_attachment(self, doc, name, collection=None):
648 attachments = doc.get("_attachments", [])

Callers 1

__getitem__Method · 0.80

Calls 2

OperationFailureClass · 0.85
getMethod · 0.80

Tested by

no test coverage detected