Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diyan/4337132 to your computer and use it in GitHub Desktop.
Save diyan/4337132 to your computer and use it in GitHub Desktop.
Monkey patch Couchbase Python client in order to work with data stored by .NET couchbase client.
# Monkey patch Couchbase Python client in order to work with data stored by .NET couchbase client.
# http://www.couchbase.com/docs/couchbase-manual-2.0/couchbase-views-datastore-fields.html
# Both Python and .NET couchbase clients using fields in document metadata
# for storing type information which does not compatible with each other.
def get_patched_couchbase():
from couchbase.constants import MemcachedConstants
import struct as original_struct
unpack_original = original_struct.unpack
def unpack_workaround(fmt, string):
if fmt == MemcachedConstants.GET_RES_FMT and string.encode('hex') == '00000112':
return unpack_original(fmt, '00000000'.decode('hex'))
else:
return unpack_original(fmt, string)
original_struct.unpack = unpack_workaround
from couchbase.client import Couchbase
return Couchbase
Couchbase = get_patched_couchbase()
couchbase = Couchbase('localhost:8091', 'admin', 'password')
bucket = couchbase['dev']
rows = bucket.view('_design/testing/_view/all_by_types')
for row in rows:
print bucket.get(row['id'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment