This change optimizes creating an instance of ObjectId
from a 12 byte bytes instance. It gets us most of the way
to what was requested in the ticket without creating a
separate subtype just for decoding.
There are also a number of changes to clean up the module
in general and silence pylint complaints.
When encoding a document in C while running in a python sub interpreter
(e.g. mod_wsgi spawning sub interpreters) PyMongo would often have
to reload its cache of pure python types - ObjectId, Timestamp,
UUID, etc. - raising RuntimeWarning in the process. The reason this was
necessary is described in the mod_wsgi documentation here:
https://code.google.com/p/modwsgi/wiki/ApplicationIssues#Multiple_Python_Sub_Interpreters
With workarounds documented here:
http://api.mongodb.org/python/2.6.2/faq.html#does-pymongo-work-with-mod-wsgi
With this commit PyMongo will no longer use cached pure python types
when running in a sub interpreter. Instead it will look up pure python
types as needed (primarily when decoding BSON). This eliminates the
problem described in the mod_wsgi docs and eliminates the need for the
Runtime warning.
This works around issues caused by applications that
use sys.setdefaultencoding to set an interpreter-wide
encoding other than ascii or utf8. This is only an
issue in python 2.x. In python 3.0 and 3.1
setdefaultencoding is a noop. It was completely
removed in python 3.2.
Many of the pymongo modules have been moved into the bson
package. Aliases for those modules have been added to the pymongo
package, without deprecation warnings for now. Application developers
should begin to use the bson namespace, as deprecation of moved
modules will probably begin in the next release.