def test_slotnames(self): self.assertEquals(copy_reg._slotnames(WithoutSlots), []) self.assertEquals(copy_reg._slotnames(WithWeakref), []) expected = ['_WithPrivate__spam'] self.assertEquals(copy_reg._slotnames(WithPrivate), expected) self.assertEquals(copy_reg._slotnames(WithSingleString), ['spam']) expected = ['eggs', 'spam'] expected.sort() result = copy_reg._slotnames(WithInherited) result.sort() self.assertEquals(result, expected)
def test_slotnames(self): self.assertEquals(copy_reg._slotnames(WithoutSlots), []) self.assertEquals(copy_reg._slotnames(WithWeakref), []) expected = ["_WithPrivate__spam"] self.assertEquals(copy_reg._slotnames(WithPrivate), expected) self.assertEquals(copy_reg._slotnames(WithSingleString), ["spam"]) expected = ["eggs", "spam"] expected.sort() result = copy_reg._slotnames(WithInherited) result.sort() self.assertEquals(result, expected)
def test_slotnames(self): self.assertEqual(copy_reg._slotnames(WithoutSlots), []) self.assertEqual(copy_reg._slotnames(WithWeakref), []) expected = ['_WithPrivate__spam'] self.assertEqual(copy_reg._slotnames(WithPrivate), expected) self.assertEqual(copy_reg._slotnames(WithSingleString), ['spam']) expected = ['eggs', 'spam'] expected.sort() result = copy_reg._slotnames(WithInherited) result.sort() self.assertEqual(result, expected)
def test_slotnames(self): if test_support.due_to_ironpython_bug("http://tkbgitvstfat01:8080/WorkItemTracking/WorkItem.aspx?artifactMoniker=318201"): return self.assertEquals(copy_reg._slotnames(WithoutSlots), []) self.assertEquals(copy_reg._slotnames(WithWeakref), []) expected = ['_WithPrivate__spam'] self.assertEquals(copy_reg._slotnames(WithPrivate), expected) self.assertEquals(copy_reg._slotnames(WithSingleString), ['spam']) expected = ['eggs', 'spam'] expected.sort() result = copy_reg._slotnames(WithInherited) result.sort() self.assertEquals(result, expected)
def _make_wrapper_subclass_if_needed(cls, obj, container): # If the type of an object to be wrapped has __slots__, then we # must create a wrapper subclass that has descriptors for those # same slots. In this way, its methods that use object.__getattribute__ # directly will continue to work, even when given an instance of _Wrapper if getattr(cls, '_Wrapper__DERIVED', False): return None type_obj = type(obj) wrapper_subclass = _wrapper_subclass_cache.get(type_obj, _NOT_GIVEN) if wrapper_subclass is _NOT_GIVEN: slotnames = copy_reg._slotnames(type_obj) if slotnames and not isinstance(obj, _Wrapper): new_type_dict = {'_Wrapper__DERIVED': True} def _make_property(slotname): return property(lambda s: getattr(s._obj, slotname), lambda s, v: setattr(s._obj, slotname, v), lambda s: delattr(s._obj, slotname)) for slotname in slotnames: new_type_dict[slotname] = _make_property(slotname) new_type = type(cls.__name__ + '_' + type_obj.__name__, (cls,), new_type_dict) else: new_type = None wrapper_subclass = _wrapper_subclass_cache[type_obj] = new_type return wrapper_subclass
def __getstate__(self): """ The base implementation of the pickle getstate protocol. This base class implementation handles the generic case where the object and all of its state are pickable. This includes state stored in Atom members, as well as any instance dict or slot attributes. Subclasses which require further customization should reimplement this method and modify the dict generated by this base class method. """ state = {} state.update(getattr(self, '__dict__', {})) slots = copy_reg._slotnames(type(self)) if slots: for name in slots: state[name] = getattr(self, name) for key in self.members(): state[key] = getattr(self, key) return state
def __getstate__(self): """ The base implementation of the pickle getstate protocol. This base class implementation handles the generic case where the object and all of its state are pickable. This includes state stored in Atom members, as well as any instance dict or slot attributes. Subclasses which require further customization should reimplement this method and modify the dict generated by this base class method. """ state = {} state.update(getattr(self, "__dict__", {})) slots = copy_reg._slotnames(type(self)) if slots: for name in slots: state[name] = getattr(self, name) for key in self.members(): state[key] = getattr(self, key) return state