Attachment() namedtuple, encode_attachement()

Bug #1078656 reported by Jason Gerard DeRose
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Microfiber
Fix Released
High
Jason Gerard DeRose

Bug Description

namedtuple are pretty darn handy, so I'm adding an Attachment(content_type, data) namedtuple.

CouchBase.get_att() will now return an Attachment rather than a vanilla tuple. This doesn't break the API as the namedtuple works just like a regular tuple when used like one. But the `content_type` and `data` attributes are nice.

I'm also adding an encode_attachment() function as I have equivalent code in Dmedia in a few places and it makes sense to consolidate this is Microfiber.

The function sig is:

  encode_attachment(attachment)

Where *attachment* is an Attachment namedtuple. I have somewhat mixed feelings about this, but I like the fact that it makes round-tripping easy without intermediate code having to unpack the (content_type, data) all the time, or know any details about the attachment data structure. The equivalent function in Dmedia is currently:

  encode_attachment(content_type, data)

Lastly, I'm adding an experimental CouchBase.put_att2() method with an API change I'd like to make. This would be a breaking API change, so I'm adding this temp method to make it easier for everyone to evaluate it before we make a decision. I'm not sure how much put_att() is being used outside of Novacut, so if you're using it, please voice your opinion on this proposed change! The 2 signatures are:

  CouchBase.put_att(content_type, data, *parts, **options)

  CouchBase.put_att2(attachment, *parts, **options)

The rational is similar as for encode_attachment(): you can round-trip the attachment while treating the Attachment namedtuple as an opaque data structure. There are also some future plans I'm considering for using the Attachment namedtuple as a way to make the core REST adapter a bit more generic, although that could be done without changing put_att().

To clarify, this bug itself involves *no* API breakage. If it seems like a good idea, CouchBase.put_att() will be changed in a separate merge. Regardless, CouchBase.put_att2() will be removed after a decision is made.

Related branches

Changed in microfiber:
status: In Progress → Fix Committed
Changed in microfiber:
status: Fix Committed → Fix Released
status: Fix Released → Fix Committed
Changed in microfiber:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.