Skip to content

Commit

Permalink
Merge pull request #5 from charettes/wrap-conflictual-objects
Browse files Browse the repository at this point in the history
Make sure ObjectWrapper is considered internal and is optimized with slots.
  • Loading branch information
gintas committed Apr 10, 2012
2 parents f28a7c4 + 4cdc56b commit 54b11bd
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/picklefield/fields.py
Expand Up @@ -27,7 +27,7 @@ class PickledObject(str):
"""

class ObjectWrapper(object):
class _ObjectWrapper(object):
"""
A class used to wrap object that have properties that may clash with the
ORM internals.
Expand All @@ -36,13 +36,14 @@ class ObjectWrapper(object):
`django.db.Model` subclasses won't work under certain conditions and the
same apply for trying to retrieve any `callable` object.
"""

__slots__ = ('_obj',)

def __init__(self, obj):
self._obj = obj

def wrap_conflictual_object(obj):
if hasattr(obj, 'prepare_database_save') or callable(obj):
obj = ObjectWrapper(obj)
obj = _ObjectWrapper(obj)
return obj

def dbsafe_encode(value, compress_object=False, pickle_protocol=DEFAULT_PROTOCOL):
Expand Down Expand Up @@ -124,7 +125,7 @@ def to_python(self, value):
if isinstance(value, PickledObject):
raise
else:
if isinstance(value, ObjectWrapper):
if isinstance(value, _ObjectWrapper):
return value._obj
return value

Expand Down

0 comments on commit 54b11bd

Please sign in to comment.