Properly serialize UnsafeProxy objects

Required as part of fix for #12123
This commit is contained in:
James Cammarata 2015-09-10 14:00:40 -04:00
parent a410bf26d3
commit 95a58d1178

View file

@ -61,13 +61,22 @@ class UnsafeProxy(object):
def __getattribute__(self, name): def __getattribute__(self, name):
if name == '_obj': if name == '_obj':
return object.__getattribute__(self, "_obj") return object.__getattribute__(self, "_obj")
elif name == '__reduce_ex__':
return object.__getattribute__(self, "__reduce_ex__")
elif name == '__UNSAFE__': elif name == '__UNSAFE__':
return True return True
else: else:
return getattr(object.__getattribute__(self, "_obj"), name) return getattr(object.__getattribute__(self, "_obj"), name)
def __eq__(self, obj): def __eq__(self, obj):
'''
special handling for == due to the fact that int objects do
not define it, so trying to guess whether we should or should
not override object.__eq__ with the wrapped classes version
causes problems
'''
return object.__getattribute__(self, "_obj") == obj return object.__getattribute__(self, "_obj") == obj
def __delattr__(self, name): def __delattr__(self, name):
delattr(object.__getattribute__(self, "_obj"), name) delattr(object.__getattribute__(self, "_obj"), name)
def __setattr__(self, name, value): def __setattr__(self, name, value):
@ -76,12 +85,17 @@ class UnsafeProxy(object):
def __nonzero__(self): def __nonzero__(self):
return bool(object.__getattribute__(self, "_obj")) return bool(object.__getattribute__(self, "_obj"))
def __str__(self): def __str__(self):
#import epdb; epdb.st()
return str(object.__getattribute__(self, "_obj")) return str(object.__getattribute__(self, "_obj"))
def __unicode__(self): def __unicode__(self):
#import epdb; epdb.st()
return unicode(object.__getattribute__(self, "_obj")) return unicode(object.__getattribute__(self, "_obj"))
def __repr__(self): def __repr__(self):
return repr(object.__getattribute__(self, "_obj")) return repr(object.__getattribute__(self, "_obj"))
def __reduce_ex__(self, protocol):
return (UnsafeProxy, (self._obj,))
# #
# factories # factories
# #
@ -94,12 +108,11 @@ class UnsafeProxy(object):
'__imul__', '__int__', '__invert__', '__ior__', '__ipow__', '__irshift__', '__imul__', '__int__', '__invert__', '__ior__', '__ipow__', '__irshift__',
'__isub__', '__iter__', '__itruediv__', '__ixor__', '__le__', '__len__', '__isub__', '__iter__', '__itruediv__', '__ixor__', '__le__', '__len__',
'__long__', '__lshift__', '__lt__', '__mod__', '__mul__', '__ne__', '__long__', '__lshift__', '__lt__', '__mod__', '__mul__', '__ne__',
'__neg__', '__oct__', '__or__', '__pos__', '__pow__', '__radd__', '__neg__', '__oct__', '__or__', '__pos__', '__pow__', '__radd__', '__rand__',
'__rand__', '__rdiv__', '__rdivmod__', '__reduce__', '__reduce_ex__', '__rdiv__', '__rdivmod__', '__repr__', '__reversed__', '__rfloordiv__',
'__repr__', '__reversed__', '__rfloordiv__', '__rlshift__', '__rmod__', '__rlshift__', '__rmod__', '__rmul__', '__ror__', '__rpow__', '__rrshift__',
'__rmul__', '__ror__', '__rpow__', '__rrshift__', '__rshift__', '__rsub__', '__rshift__', '__rsub__', '__rtruediv__', '__rxor__', '__setitem__',
'__rtruediv__', '__rxor__', '__setitem__', '__setslice__', '__sub__', '__setslice__', '__sub__', '__truediv__', '__xor__', 'next',
'__truediv__', '__xor__', 'next',
] ]
@classmethod @classmethod