<s> """<STR_LIT>""" <EOL> import types <EOL> import copy_reg <EOL> import copy <EOL> try : <EOL> import cStringIO as StringIO <EOL> except ImportError : <EOL> import StringIO <EOL> from twisted . python import log <EOL> try : <EOL> from new import instancemethod <EOL> except : <EOL> from org . python . core import PyMethod <EOL> instancemethod = PyMethod <EOL> oldModules = { } <EOL> def pickleMethod ( method ) : <EOL> '<STR_LIT>' <EOL> return unpickleMethod , ( method . im_func . __name__ , <EOL> method . im_self , <EOL> method . im_class ) <EOL> def unpickleMethod ( im_name , <EOL> im_self , <EOL> im_class ) : <EOL> '<STR_LIT>' <EOL> try : <EOL> unbound = getattr ( im_class , im_name ) <EOL> if im_self is None : <EOL> return unbound <EOL> bound = instancemethod ( unbound . im_func , <EOL> im_self , <EOL> im_class ) <EOL> return bound <EOL> except AttributeError : <EOL> log . msg ( "<STR_LIT>" , im_name , "<STR_LIT>" , im_class ) <EOL> assert im_self is not None , "<STR_LIT>" <EOL> unbound = getattr ( im_self . __class__ , im_name ) <EOL> log . msg ( "<STR_LIT>" , unbound ) <EOL> if im_self is None : <EOL> return unbound <EOL> bound = instancemethod ( unbound . im_func , <EOL> im_self , <EOL> im_self . __class__ ) <EOL> return bound <EOL> copy_reg . pickle ( types . MethodType , <EOL> pickleMethod , <EOL> unpickleMethod ) <EOL> def pickleModule ( module ) : <EOL> '<STR_LIT>' <EOL> return unpickleModule , ( module . __name__ , ) <EOL> def unpickleModule ( name ) : <EOL> '<STR_LIT>' <EOL> if oldModules . has_key ( name ) : <EOL> log . msg ( "<STR_LIT>" % name ) <EOL> name = oldModules [ name ] <EOL> log . msg ( name ) <EOL> return __import__ ( name , { } , { } , '<STR_LIT:x>' ) <EOL> copy_reg . pickle ( types . ModuleType , <EOL> pickleModule , <EOL> unpickleModule ) <EOL> def pickleStringO ( stringo ) : <EOL> '<STR_LIT>' <EOL> return unpickleStringO , ( stringo . getvalue ( ) , stringo . tell ( ) ) <EOL> def unpickleStringO ( val , sek ) : <EOL> x = StringIO . StringIO ( ) <EOL> x . write ( val ) <EOL> x . seek ( sek ) <EOL> return x <EOL> if hasattr ( StringIO , '<STR_LIT>' ) : <EOL> copy_reg . pickle ( StringIO . OutputType , <EOL> pickleStringO , <EOL> unpickleStringO ) <EOL> def pickleStringI ( stringi ) : <EOL> return unpickleStringI , ( stringi . getvalue ( ) , stringi . tell ( ) ) <EOL> def unpickleStringI ( val , sek ) : <EOL> x = StringIO . StringIO ( val ) <EOL> x . seek ( sek ) <EOL> return x <EOL> if hasattr ( StringIO , '<STR_LIT>' ) : <EOL> copy_reg . pickle ( StringIO . InputType , <EOL> pickleStringI , <EOL> unpickleStringI ) <EOL> class Ephemeral : <EOL> """<STR_LIT>""" <EOL> def __getstate__ ( self ) : <EOL> log . msg ( "<STR_LIT>" % self ) <EOL> import gc <EOL> if getattr ( gc , '<STR_LIT>' , None ) : <EOL> for r in gc . get_referrers ( self ) : <EOL> log . msg ( "<STR_LIT>" % ( r , ) ) <EOL> return None <EOL> def __setstate__ ( self , state ) : <EOL> log . msg ( "<STR_LIT>" % self . __class__ ) <EOL> self . __class__ = Ephemeral <EOL> versionedsToUpgrade = { } <EOL> upgraded = { } <EOL> def doUpgrade ( ) : <EOL> global versionedsToUpgrade , upgraded <EOL> for versioned in versionedsToUpgrade . values ( ) : <EOL> requireUpgrade ( versioned ) <EOL> versionedsToUpgrade = { } <EOL> upgraded = { } <EOL> def requireUpgrade ( obj ) : <EOL> """<STR_LIT>""" <EOL> objID = id ( obj ) <EOL> if objID in versionedsToUpgrade and objID not in upgraded : <EOL> upgraded [ objID ] = <NUM_LIT:1> <EOL> obj . versionUpgrade ( ) <EOL> return obj <EOL> from twisted . python import reflect <EOL> def _aybabtu ( c ) : <EOL> l = [ ] <EOL> for b in reflect . allYourBase ( c , Versioned ) : <EOL> if b not in l and b is not Versioned : <EOL> l . append ( b ) <EOL> return l <EOL> class Versioned : <EOL> """<STR_LIT>""" <EOL> persistenceVersion = <NUM_LIT:0> <EOL> persistenceForgets = ( ) <EOL> def __setstate__ ( self , state ) : <EOL> versionedsToUpgrade [ id ( self ) ] = self <EOL> self . __dict__ = state <EOL> def __getstate__ ( self , dict = None ) : <EOL> """<STR_LIT>""" <EOL> dct = copy . copy ( dict or self . __dict__ ) <EOL> bases = _aybabtu ( self . __class__ ) <EOL> bases . reverse ( ) <EOL> bases . append ( self . __class__ ) <EOL> for base in bases : <EOL> if base . __dict__ . has_key ( '<STR_LIT>' ) : <EOL> for slot in base . persistenceForgets : <EOL> if dct . has_key ( slot ) : <EOL> del dct [ slot ] <EOL> if base . __dict__ . has_key ( '<STR_LIT>' ) : <EOL> dct [ '<STR_LIT>' % reflect . qual ( base ) ] = base . persistenceVersion <EOL> return dct <EOL> def versionUpgrade ( self ) : <EOL> """<STR_LIT>""" <EOL> bases = _aybabtu ( self . __class__ ) <EOL> bases . reverse ( ) <EOL> bases . append ( self . __class__ ) <EOL> if self . __dict__ . has_key ( "<STR_LIT>" ) : <EOL> pver = self . __dict__ [ '<STR_LIT>' ] <EOL> del self . __dict__ [ '<STR_LIT>' ] <EOL> highestVersion = <NUM_LIT:0> <EOL> highestBase = None <EOL> for base in bases : <EOL> if not base . __dict__ . has_key ( '<STR_LIT>' ) : <EOL> continue <EOL> if base . persistenceVersion > highestVersion : <EOL> highestBase = base <EOL> highestVersion = base . persistenceVersion <EOL> if highestBase : <EOL> self . __dict__ [ '<STR_LIT>' % reflect . qual ( highestBase ) ] = pver <EOL> for base in bases : <EOL> if ( Versioned not in base . __bases__ and <EOL> not base . __dict__ . has_key ( '<STR_LIT>' ) ) : <EOL> continue <EOL> currentVers = base . persistenceVersion <EOL> pverName = '<STR_LIT>' % reflect . qual ( base ) <EOL> persistVers = ( self . __dict__ . get ( pverName ) or <NUM_LIT:0> ) <EOL> if persistVers : <EOL> del self . __dict__ [ pverName ] <EOL> assert persistVers <= currentVers , "<STR_LIT>" <EOL> while persistVers < currentVers : <EOL> persistVers = persistVers + <NUM_LIT:1> <EOL> method = base . __dict__ . get ( '<STR_LIT>' % persistVers , None ) <EOL> if method : <EOL> log . msg ( "<STR_LIT>" % ( reflect . qual ( base ) , reflect . qual ( self . __class__ ) , id ( self ) , persistVers ) ) <EOL> method ( self ) <EOL> else : <EOL> log . msg ( '<STR_LIT>' % ( base , persistVers ) ) </s>
