Permalink
Browse files

use BSON decoder instead of private func in python driver HADOOP-53

  • Loading branch information...
mpobrien committed Oct 3, 2012
1 parent e478489 commit 833bf5582d305ba556c28545a23fefc2fde7e9eb
Showing with 6 additions and 6 deletions.
  1. +6 −6 streaming/language_support/python/pymongo_hadoop/input.py
@@ -1,4 +1,5 @@
-from bson import _elements_to_dict, InvalidBSON
+from bson import InvalidBSON, BSON
+from bson.binary import Binary
import sys
import struct
@@ -19,13 +20,12 @@ def _read(self):
try:
size_bits = self.fh.read(4)
size = struct.unpack("<i", size_bits)[0] - 4 # BSON size byte includes itself
- data = self.fh.read(size)
- if len(data) != size:
+ data = size_bits + self.fh.read(size)
+ if len(data) != size + 4:
raise struct.error("Unable to cleanly read expected BSON Chunk; EOF, underful buffer or invalid object size.")
- if data[size - 1] != "\x00":
+ if data[size + 4 - 1] != "\x00":
raise InvalidBSON("Bad EOO in BSON Data")
- chunk = data[:size - 1]
- doc = _elements_to_dict(chunk, dict, True)
+ doc = BSON(data).decode(tz_aware=True)
return doc
except struct.error, e:
#print >> sys.stderr, "Parsing Length record failed: %s" % e

0 comments on commit 833bf55

Please sign in to comment.