Ticket #11716: trac_11716_twisted_persisted_styles.patch

File trac_11716_twisted_persisted_styles.patch, 3.0 KB (added by saraedum, 10 years ago)
  • sage/all.py

    exporting patch:
    # HG changeset patch
    # User Julian Rüth <julian.rueth@gmail.com>
    Trac 11716: removes import of twisted.persisted.styles
    
    diff --git a/sage/all.py b/sage/all.py
    index 13598ce..e5bcc92 100644
    a b if sys.version_info[:2] < (2, 5): 
    5454
    5555###################################################################
    5656
    57 #Import twisted.persisted.styles in order to allow things like
    58 #modules to be pickles
    59 
    60 import twisted.persisted.styles
    61 
    62 ###################################################################
    63 
    6457# We have to set this here so urllib, etc. can detect it.
    6558import sage.server.notebook.gnutls_socket_ssl
    6659sage.server.notebook.gnutls_socket_ssl.require_SSL()
  • sage/misc/fpickle.pyx

    diff --git a/sage/misc/fpickle.pyx b/sage/misc/fpickle.pyx
    index 2fe1e82..3f464b8 100644
    a b def call_pickled_function(fpargs): 
    8080    f = eval("unpickle_function(fp)", sage.all.__dict__, {'fp':fp})
    8181    res = eval("f(*args, **kwds)",sage.all.__dict__, {'args':args, 'kwds':kwds, 'f':f})
    8282    return ((args, kwds), res)
     83
     84# The following four methods are taken from twisted.persisted.styles - the
     85# import of twisted.persisted.styles takes a long time and we do not use
     86# most functionality it provides
     87def pickleMethod(method):
     88    'support function for copy_reg to pickle method refs'
     89    return unpickleMethod, (method.im_func.__name__,
     90                             method.im_self,
     91                             method.im_class)
     92
     93def unpickleMethod(im_name,
     94                    im_self,
     95                    im_class):
     96    'support function for copy_reg to unpickle method refs'
     97    try:
     98        unbound = getattr(im_class,im_name)
     99        if im_self is None:
     100            return unbound
     101        bound=new.instancemethod(unbound.im_func,
     102                                 im_self,
     103                                 im_class)
     104        return bound
     105    except AttributeError:
     106        assert im_self is not None,"No recourse: no instance to guess from."
     107        # Attempt a common fix before bailing -- if classes have
     108        # changed around since we pickled this method, we may still be
     109        # able to get it by looking on the instance's current class.
     110        unbound = getattr(im_self.__class__,im_name)
     111        if im_self is None:
     112            return unbound
     113        bound=new.instancemethod(unbound.im_func,
     114                                 im_self,
     115                                 im_self.__class__)
     116        return bound
     117
     118copy_reg.pickle(types.MethodType,
     119                pickleMethod,
     120                unpickleMethod)
     121
     122oldModules = {}
     123
     124def pickleModule(module):
     125    'support function for copy_reg to pickle module refs'
     126    return unpickleModule, (module.__name__,)
     127
     128def unpickleModule(name):
     129    'support function for copy_reg to unpickle module refs'
     130    if oldModules.has_key(name):
     131        name = oldModules[name]
     132    return __import__(name,{},{},'x')
     133
     134copy_reg.pickle(types.ModuleType,
     135                pickleModule,
     136                unpickleModule)
     137