Changeset 102
- Timestamp:
- 11/19/07 22:34:45 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
projects/Twisted-Goodies/trunk/twisted_goodies/pybywire/params.py
r101 r102 25 25 """ 26 26 27 from twisted.spread import pb 28 from twisted. spread.jelly import Jellyable, Unjellyable27 from twisted.spread import pb, jelly 28 from twisted.python.reflect import namedObject 29 29 30 30 31 class Parameterized(Jellyable, Unjellyable, object):31 def parallow(instances): 32 32 """ 33 Call this function with one or more arguments containing standard string 34 representations of L{Parameterized} subclasses, and instances of those will 35 be allowed past PB security. Use judiciously! 36 """ 37 for stringRep in instances: 38 cls = namedObject(stringRep) 39 pb.globalSecurity.allowInstancesOf(cls) 40 41 42 class Parameterized(jelly.Jellyable, jelly.Unjellyable, object): 43 """ 44 @cvar instances: A list of standard string representations of all instances 45 of me or my subclasses. Your remote PB peer should expose L{parallow} to 46 you so you can call it remotely with this list to allow those instances. 47 33 48 @cvar keyAttrs: A dict of attributes on which cache keying will be 34 49 partially based. Any entry having a value of C{None} has no default, and … … 40 55 41 56 """ 57 instances = [] 42 58 paramNames, keyAttrs = [], {} 43 59 … … 56 72 for name, value in kw.iteritems(): 57 73 setattr(self, name, value) 74 myClass = self.__class__ 75 stringRep = "%s.%s" % (myClass.__module__, myClass.__name__) 76 if stringRep not in self.instances: 77 self.instances.append(stringRep) 78 # Make sure you can accept copies of me coming back, too. 79 pb.globalSecurity.allowInstancesOf(myClass) 58 80 59 81 def __getattr__(self, name): … … 128 150 if hasattr(self, name): 129 151 state[name] = getattr(self, name) 130 myClass = self.__class__131 pb.globalSecurity.allowInstancesOf(myClass)132 pb.globalSecurity.allowModules(myClass.__module__)133 152 return state 134 153 135 154 155 156
