Commits

Jason R. Coombs committed c92bf7d

It is no longer necessary to call jaraco.modb.init; modb bypasses the JSONPluginMgr altogether and uses the Pickler and Unpickler objects directly.

Comments (0)

Files changed (2)

jaraco/modb/__init__.py

-import jsonpickle
+import jsonpickle.pickler
+import jsonpickle.unpickler
 import pymongo.binary
 import jaraco.util.dictlib
 from jaraco.util.string import is_binary
 	return json
 
 def init():
-	# remove all other backends so only this one is used
-	orig_backends = list(jsonpickle.json._backend_names)
-	map(jsonpickle.remove_backend, orig_backends)
-	jsonpickle.load_backend(__name__, 'to_bson', 'from_bson', ValueError)
-	jsonpickle.set_preferred_backend(__name__)
+	warnings.warn("It is no longer necessary to call jaraco.modb.init",
+		DeprecationWarning)
 
-encode = jsonpickle.encode
-decode = jsonpickle.decode
+def encode(value):
+	return to_bson(jsonpickle.pickler.Pickler().flatten(value))
+
+def decode(value):
+	return jsonpickle.unpickler.Unpickler().restore(from_bson(value))
 import pymongo.binary
 import jaraco.modb
 
-def setup_module(module):
-	jaraco.modb.init()
-
 def test_to_bson():
 	sample = dict(
 		a = u'a string',
 	assert 'MyDict' in str(encoded)
 	decoded = jaraco.modb.decode(encoded)
 	assert isinstance(decoded, MyDict)
-
-def test_init():
-	"If init works correctly, jaraco.modb will be the only backend."
-	assert jaraco.modb.jsonpickle.json._backend_names == ['jaraco.modb']