Lines 140-145
Link Here
|
140 |
unjellyableRegistry = {} |
140 |
unjellyableRegistry = {} |
141 |
unjellyableFactoryRegistry = {} |
141 |
unjellyableFactoryRegistry = {} |
142 |
|
142 |
|
|
|
143 |
def _newInstance(cls, state): |
144 |
"""Make a new instance of a class without calling its __init__ method. |
145 |
'state' will be used to update inst.__dict__ . Supports both new- and |
146 |
old-style classes. |
147 |
""" |
148 |
if not isinstance(cls, types.ClassType): |
149 |
# new-style |
150 |
inst = cls.__new__(cls) |
151 |
inst.__dict__.update(state) # Copy 'instance' behaviour |
152 |
else: |
153 |
inst = instance(cls, state) |
154 |
return inst |
155 |
|
156 |
|
143 |
def _maybeClass(classnamep): |
157 |
def _maybeClass(classnamep): |
144 |
try: |
158 |
try: |
145 |
object |
159 |
object |
Lines 535-540
Link Here
|
535 |
inst = _Dummy() # XXX chomp, chomp |
549 |
inst = _Dummy() # XXX chomp, chomp |
536 |
inst.__class__ = regClass |
550 |
inst.__class__ = regClass |
537 |
method = inst.unjellyFor |
551 |
method = inst.unjellyFor |
|
|
552 |
elif isinstance(regClass, type): |
553 |
# regClass.__new__ does not call regClass.__init__ |
554 |
inst = regClass.__new__(regClass) |
555 |
method = inst.unjellyFor |
538 |
else: |
556 |
else: |
539 |
method = regClass # this is how it ought to be done |
557 |
method = regClass # this is how it ought to be done |
540 |
val = method(self, obj) |
558 |
val = method(self, obj) |
Lines 560-571
Link Here
|
560 |
if not self.taster.isClassAllowed(clz): |
578 |
if not self.taster.isClassAllowed(clz): |
561 |
raise InsecureJelly("Class %s not allowed." % jelType) |
579 |
raise InsecureJelly("Class %s not allowed." % jelType) |
562 |
if hasattr(clz, "__setstate__"): |
580 |
if hasattr(clz, "__setstate__"): |
563 |
ret = instance(clz, {}) |
581 |
ret = _newInstance(clz, {}) |
564 |
state = self.unjelly(obj[1]) |
582 |
state = self.unjelly(obj[1]) |
565 |
ret.__setstate__(state) |
583 |
ret.__setstate__(state) |
566 |
else: |
584 |
else: |
567 |
state = self.unjelly(obj[1]) |
585 |
state = self.unjelly(obj[1]) |
568 |
ret = instance(clz, state) |
586 |
ret = _newInstance(clz, state) |
569 |
if hasattr(clz, 'postUnjelly'): |
587 |
if hasattr(clz, 'postUnjelly'): |
570 |
self.postCallbacks.append(ret.postUnjelly) |
588 |
self.postCallbacks.append(ret.postUnjelly) |
571 |
return ret |
589 |
return ret |
Lines 697-708
Link Here
|
697 |
if type(clz) is not types.ClassType: |
715 |
if type(clz) is not types.ClassType: |
698 |
raise InsecureJelly("Instance found with non-class class.") |
716 |
raise InsecureJelly("Instance found with non-class class.") |
699 |
if hasattr(clz, "__setstate__"): |
717 |
if hasattr(clz, "__setstate__"): |
700 |
inst = instance(clz, {}) |
718 |
inst = _newInstance(clz, {}) |
701 |
state = self.unjelly(rest[1]) |
719 |
state = self.unjelly(rest[1]) |
702 |
inst.__setstate__(state) |
720 |
inst.__setstate__(state) |
703 |
else: |
721 |
else: |
704 |
state = self.unjelly(rest[1]) |
722 |
state = self.unjelly(rest[1]) |
705 |
inst = instance(clz, state) |
723 |
inst = _newInstance(clz, state) |
706 |
if hasattr(clz, 'postUnjelly'): |
724 |
if hasattr(clz, 'postUnjelly'): |
707 |
self.postCallbacks.append(inst.postUnjelly) |
725 |
self.postCallbacks.append(inst.postUnjelly) |
708 |
return inst |
726 |
return inst |