From 6e7d0ff1efdbfcc2e2c8b1a7f525f058a0076026 Mon Sep 17 00:00:00 2001 From: Mike Dirolf Date: Mon, 2 Feb 2009 10:08:01 -0500 Subject: [PATCH] support encoding/decoding binary w/ different subtypes --- pymongo/bson.py | 20 +++++++++++--------- test/test_bson.py | 4 ++++ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/pymongo/bson.py b/pymongo/bson.py index 04578ba15..caf38951e 100644 --- a/pymongo/bson.py +++ b/pymongo/bson.py @@ -198,14 +198,14 @@ def _get_array(data): def _get_binary(data): (length, data) = _get_int(data) - subtype = data[0] + subtype = ord(data[0]) data = data[1:] - if subtype != "\x02": - raise InvalidBSON("binary subtype %r is unsupported" % subtype) - (length2, data) = _get_int(data) - if length2 != length - 4: - raise InvalidBSON("invalid binary - lengths don't match!") - return (Binary(data[:length2]), data[length2:]) + if subtype == 2: + (length2, data) = _get_int(data) + if length2 != length - 4: + raise InvalidBSON("invalid binary (st 2) - lengths don't match!") + length = length2 + return (Binary(data[:length], subtype), data[length:]) def _get_oid(data): oid = _shuffle_oid(data[:12]) @@ -290,8 +290,10 @@ def _element_to_bson(key, value): if isinstance(value, float): return "\x01" + name + struct.pack("