Skip to content
This repository has been archived by the owner on May 13, 2020. It is now read-only.

Commit

Permalink
- update to latest package versions
Browse files Browse the repository at this point in the history
  biggest change: ``pymongo`` does not reexport ``objectid`` and ``dbref``
  • Loading branch information
Adam Groszer committed Jan 29, 2013
1 parent 1e52d08 commit 75c0d3c
Show file tree
Hide file tree
Showing 10 changed files with 157 additions and 134 deletions.
3 changes: 2 additions & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ CHANGES
0.7.3 (unreleased)
------------------

- ...
- update to latest package versions
biggest change: ``pymongo`` does not reexport ``objectid`` and ``dbref``

0.7.2 (2012-04-19)
------------------
Expand Down
1 change: 1 addition & 0 deletions buildout.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ buildout_versions_file = ./versions.cfg
newest = false
include-site-packages = false
unzip = true
prefer-final = true

[test]
recipe = zc.recipe.testrunner
Expand Down
17 changes: 10 additions & 7 deletions src/mongopersist/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@
import types
import zope.interface
import zope.schema
from pymongo import objectid, dbref
from bson import objectid, dbref

MONGO_NATIVE_TYPES = (
int, float, unicode, datetime.datetime, types.NoneType,
objectid.ObjectId, dbref.DBRef)


class ConflictError(transaction.interfaces.TransientError):
"""An error raised when a write conflict is detected."""

Expand All @@ -50,20 +51,21 @@ def new_serial(self):

def __str__(self):
extras = [
'oid %s' %self.object._p_oid,
'class %s' %self.object.__class__.__name__,
'orig serial %s' %self.orig_serial,
'cur serial %s' %self.cur_serial,
'new serial %s' %self.new_serial]
'oid %s' % self.object._p_oid,
'class %s' % self.object.__class__.__name__,
'orig serial %s' % self.orig_serial,
'cur serial %s' % self.cur_serial,
'new serial %s' % self.new_serial]
return "%s (%s)" % (self.message, ", ".join(extras))

def __repr__(self):
return '%s: %s' %(self.__class__.__name__, self)
return '%s: %s' % (self.__class__.__name__, self)


class CircularReferenceError(Exception):
pass


class IConflictHandler(zope.interface.Interface):

datamanager = zope.interface.Attribute(
Expand Down Expand Up @@ -104,6 +106,7 @@ def check_conflicts(self, objs):
conflicts.
"""


class IResolvingConflictHandler(IConflictHandler):
"""A conflict handler that is able to resolve conflicts."""

Expand Down
5 changes: 2 additions & 3 deletions src/mongopersist/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
"""Mongo Mapping Implementations"""
from __future__ import absolute_import
import UserDict
import pymongo
import bson.dbref

from mongopersist import interfaces

class MongoCollectionMapping(UserDict.DictMixin, object):
__mongo_database__ = None
Expand All @@ -41,7 +40,7 @@ def __getitem__(self, key):
if doc is None:
raise KeyError(key)
db_name = self.__mongo_database__ or self._m_jar.default_database
dbref = pymongo.dbref.DBRef(
dbref = bson.dbref.DBRef(
self.__mongo_collection__, doc['_id'], db_name)
return self._m_jar._reader.get_ghost(dbref)

Expand Down
13 changes: 8 additions & 5 deletions src/mongopersist/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
import persistent.interfaces
import persistent.dict
import persistent.list
import pymongo.binary
import bson.dbref
import bson.binary
import repoze.lru
import types
import zope.interface
Expand All @@ -37,8 +38,10 @@
AVAILABLE_NAME_MAPPINGS = set()
PATH_RESOLVE_CACHE = {}


def get_dotted_name(obj):
return obj.__module__+'.'+obj.__name__
return obj.__module__ + '.' + obj.__name__


class PersistentDict(persistent.dict.PersistentDict):
_p_mongo_sub_object = True
Expand Down Expand Up @@ -187,7 +190,7 @@ def get_state(self, obj, seen=None):
obj.decode('utf-8')
return obj
except UnicodeError:
return pymongo.binary.Binary(obj)
return bson.binary.Binary(obj)

# Some objects might not naturally serialize well and create a very
# ugly Mongo entry. Thus, we allow custom serializers to be
Expand Down Expand Up @@ -275,7 +278,7 @@ def store(self, obj, ref_only=False):
doc_id = coll.insert(doc)
stored = True
obj._p_jar = self._jar
obj._p_oid = pymongo.dbref.DBRef(coll_name, doc_id, db_name)
obj._p_oid = bson.dbref.DBRef(coll_name, doc_id, db_name)
# Make sure that any other code accessing this object in this
# session, gets the same instance.
self._jar._object_cache[hash(obj._p_oid)] = obj
Expand Down Expand Up @@ -454,7 +457,7 @@ def get_object(self, state, obj):
if isinstance(state, bson.objectid.ObjectId):
# The object id is special. Preserve it.
return state
if isinstance(state, pymongo.binary.Binary):
if isinstance(state, bson.binary.Binary):
# Binary data in Python 2 is presented as a string. We will
# convert back to binary when serializing again.
return str(state)
Expand Down
2 changes: 1 addition & 1 deletion src/mongopersist/tests/test_datamanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import doctest
import persistent
import transaction
from pymongo import dbref, objectid
from bson import dbref, objectid

from mongopersist import conflict, interfaces, testing, datamanager

Expand Down
2 changes: 1 addition & 1 deletion src/mongopersist/tests/test_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import persistent
import pprint
import transaction
from pymongo import dbref, objectid
from bson import dbref, objectid

from mongopersist import testing, mapping

Expand Down
2 changes: 1 addition & 1 deletion src/mongopersist/tests/test_serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import persistent
import pprint

from pymongo import binary, dbref, objectid
from bson import binary, dbref, objectid

from mongopersist import conflict, serialize, testing

Expand Down
13 changes: 7 additions & 6 deletions src/mongopersist/zope/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@
"""Mongo Persistence Zope Containers"""
import UserDict
import persistent
import pymongo.dbref
import pymongo.objectid
import bson.dbref
import bson.objectid
import zope.component
from bson.errors import InvalidId
from rwproperty import getproperty, setproperty
from zope.container import contained, sample
from zope.container.interfaces import IContainer

from mongopersist import interfaces, serialize
from mongopersist import interfaces
from mongopersist.zope import interfaces as zinterfaces


class MongoContained(contained.Contained):

@getproperty
Expand Down Expand Up @@ -165,7 +166,7 @@ def _locate(self, obj, doc):

def _load_one(self, doc):
# Create a DBRef object and then load the full state of the object.
dbref = pymongo.dbref.DBRef(
dbref = bson.dbref.DBRef(
self._m_collection, doc['_id'],
self._m_database or self._m_jar.default_database)
# Stick the doc into the _latest_states:
Expand Down Expand Up @@ -285,7 +286,7 @@ def _locate(self, obj, doc):

def __getitem__(self, key):
try:
id = pymongo.objectid.ObjectId(key)
id = bson.objectid.ObjectId(key)
except InvalidId:
raise KeyError(key)
filter = self._m_get_items_filter()
Expand All @@ -297,7 +298,7 @@ def __getitem__(self, key):

def __contains__(self, key):
try:
id = pymongo.objectid.ObjectId(key)
id = bson.objectid.ObjectId(key)
except InvalidId:
return False
return self.raw_find_one({'_id': id}, fields=()) is not None
Expand Down
Loading

0 comments on commit 75c0d3c

Please sign in to comment.