From 836c99bec5f5b6d683c542155dc3203a1ae1cebb Mon Sep 17 00:00:00 2001 From: Mike Dirolf Date: Tue, 6 Jan 2009 18:15:39 -0500 Subject: [PATCH] from_dict w/ support for ints, floats, unicode, sub-dicts, lists, and booleans. more tests coming (i ported some tests from mlmongo but forgot that they would break because dicts aren't ordered) --- bson.py | 66 +++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 48 insertions(+), 18 deletions(-) diff --git a/bson.py b/bson.py index 5c9fe7669..41dda9534 100644 --- a/bson.py +++ b/bson.py @@ -34,6 +34,9 @@ def _get_c_string(data): return (unicode(data[:end], "utf-8"), data[end + 1:]) +def _make_c_string(string): + return string.encode("utf-8") + "\x00" + def _validate_number(data): assert len(data) >= 8 return data[8:] @@ -148,7 +151,36 @@ def _validate_document(data, valid_name=_valid_object_name): return data[obj_size:] def _int_to_bson(int): - return struct.pack("