[Checkins] SVN: mongopersist/trunk/src/mongopersist/ Patch pymongo a bit, so that the hash of the DBRef is not computed all
Stephen Richter
cvs-admin at zope.org
Tue Apr 3 18:12:41 UTC 2012
Log message for revision 124921:
Patch pymongo a bit, so that the hash of the DBRef is not computed all
the time but cached. DBRef's are generally considered immutable.
Changed:
U mongopersist/trunk/src/mongopersist/__init__.py
A mongopersist/trunk/src/mongopersist/pymongo.py
-=-
Modified: mongopersist/trunk/src/mongopersist/__init__.py
===================================================================
--- mongopersist/trunk/src/mongopersist/__init__.py 2012-04-03 18:09:50 UTC (rev 124920)
+++ mongopersist/trunk/src/mongopersist/__init__.py 2012-04-03 18:12:38 UTC (rev 124921)
@@ -1 +1,5 @@
# Make a package.
+
+from . import pymongo
+pymongo.patch()
+del pymongo
Added: mongopersist/trunk/src/mongopersist/pymongo.py
===================================================================
--- mongopersist/trunk/src/mongopersist/pymongo.py (rev 0)
+++ mongopersist/trunk/src/mongopersist/pymongo.py 2012-04-03 18:12:38 UTC (rev 124921)
@@ -0,0 +1,32 @@
+##############################################################################
+#
+# Copyright (c) 2011 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""PyMongo Patches"""
+
+def lazy_hash(self):
+ """Get a hash value for this :class:`DBRef`.
+
+ .. versionadded:: 1.1
+ """
+ if self.__hash is None:
+ self.__hash = self.orig_hash()
+ return self.__hash
+
+def patch():
+ # ObjectId should get patched too, but it is hard, since it uses slots
+ # *and* rquires the original object reference to be around (otherwise it
+ # creates BSON encoding errors.
+ import bson.dbref
+ bson.dbref.DBRef.__hash = None
+ bson.dbref.DBRef.orig_hash = bson.dbref.DBRef.__hash__
+ bson.dbref.DBRef.__hash__ = lazy_hash
Property changes on: mongopersist/trunk/src/mongopersist/pymongo.py
___________________________________________________________________
Added: svn:keywords
+ Id
More information about the checkins
mailing list