<s> __all__ = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> import os <EOL> import sys <EOL> import weakref <EOL> import threading <EOL> import array <EOL> import Queue <EOL> from traceback import format_exc <EOL> from multiprocessing import Process , current_process , active_children , Pool , util , connection <EOL> from multiprocessing . process import AuthenticationString <EOL> from multiprocessing . forking import exit , Popen , assert_spawning , ForkingPickler <EOL> from multiprocessing . util import Finalize , info <EOL> try : <EOL> from cPickle import PicklingError <EOL> except ImportError : <EOL> from pickle import PicklingError <EOL> def reduce_array ( a ) : <EOL> return array . array , ( a . typecode , a . tostring ( ) ) <EOL> ForkingPickler . register ( array . array , reduce_array ) <EOL> view_types = [ type ( getattr ( { } , name ) ( ) ) for name in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> class Token ( object ) : <EOL> '''<STR_LIT>''' <EOL> __slots__ = ( '<STR_LIT>' , '<STR_LIT:address>' , '<STR_LIT:id>' ) <EOL> def __init__ ( self , typeid , address , id ) : <EOL> ( self . typeid , self . address , self . id ) = ( typeid , address , id ) <EOL> def __getstate__ ( self ) : <EOL> return ( self . typeid , self . address , self . id ) <EOL> def __setstate__ ( self , state ) : <EOL> ( self . typeid , self . address , self . id ) = state <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( self . typeid , self . address , self . id ) <EOL> def dispatch ( c , id , methodname , args = ( ) , kwds = { } ) : <EOL> '''<STR_LIT>''' <EOL> c . send ( ( id , methodname , args , kwds ) ) <EOL> kind , result = c . recv ( ) <EOL> if kind == '<STR_LIT>' : <EOL> return result <EOL> raise convert_to_error ( kind , result ) <EOL> def convert_to_error ( kind , result ) : <EOL> if kind == '<STR_LIT>' : <EOL> return result <EOL> elif kind == '<STR_LIT>' : <EOL> assert type ( result ) is str <EOL> return RemoteError ( result ) <EOL> elif kind == '<STR_LIT>' : <EOL> assert type ( result ) is str <EOL> return RemoteError ( '<STR_LIT>' % result ) <EOL> else : <EOL> return ValueError ( '<STR_LIT>' ) <EOL> class RemoteError ( Exception ) : <EOL> def __str__ ( self ) : <EOL> return ( '<STR_LIT:\n>' + '<STR_LIT:->' * <NUM_LIT> + '<STR_LIT:\n>' + str ( self . args [ <NUM_LIT:0> ] ) + '<STR_LIT:->' * <NUM_LIT> ) <EOL> def all_methods ( obj ) : <EOL> '''<STR_LIT>''' <EOL> temp = [ ] <EOL> for name in dir ( obj ) : <EOL> func = getattr ( obj , name ) <EOL> if hasattr ( func , '<STR_LIT>' ) : <EOL> temp . append ( name ) <EOL> return temp <EOL> def public_methods ( obj ) : <EOL> '''<STR_LIT>''' <EOL> return [ name for name in all_methods ( obj ) if name [ <NUM_LIT:0> ] != '<STR_LIT:_>' ] <EOL> class Server ( object ) : <EOL> '''<STR_LIT>''' <EOL> public = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> def __init__ ( self , registry , address , authkey , serializer ) : <EOL> assert isinstance ( authkey , bytes ) <EOL> self . registry = registry <EOL> self . authkey = AuthenticationString ( authkey ) <EOL> Listener , Client = listener_client [ serializer ] <EOL> self . listener = Listener ( address = address , backlog = <NUM_LIT:16> ) <EOL> self . address = self . listener . address <EOL> self . id_to_obj = { '<STR_LIT:0>' : ( None , ( ) ) } <EOL> self . id_to_refcount = { } <EOL> self . mutex = threading . RLock ( ) <EOL> self . stop = <NUM_LIT:0> <EOL> def serve_forever ( self ) : <EOL> '''<STR_LIT>''' <EOL> current_process ( ) . _manager_server = self <EOL> try : <EOL> try : <EOL> while <NUM_LIT:1> : <EOL> try : <EOL> c = self . listener . accept ( ) <EOL> except ( OSError , IOError ) : <EOL> continue <EOL> t = threading . Thread ( target = self . handle_request , args = ( c , ) ) <EOL> t . daemon = True <EOL> t . start ( ) <EOL> except ( KeyboardInterrupt , SystemExit ) : <EOL> pass <EOL> finally : <EOL> self . stop = <NUM_LIT> <EOL> self . listener . close ( ) <EOL> def handle_request ( self , c ) : <EOL> '''<STR_LIT>''' <EOL> funcname = result = request = None <EOL> try : <EOL> connection . deliver_challenge ( c , self . authkey ) <EOL> connection . answer_challenge ( c , self . authkey ) <EOL> request = c . recv ( ) <EOL> ignore , funcname , args , kwds = request <EOL> assert funcname in self . public , '<STR_LIT>' % funcname <EOL> func = getattr ( self , funcname ) <EOL> except Exception : <EOL> msg = ( '<STR_LIT>' , format_exc ( ) ) <EOL> else : <EOL> try : <EOL> result = func ( c , * args , ** kwds ) <EOL> except Exception : <EOL> msg = ( '<STR_LIT>' , format_exc ( ) ) <EOL> else : <EOL> msg = ( '<STR_LIT>' , result ) <EOL> try : <EOL> c . send ( msg ) <EOL> except Exception , e : <EOL> try : <EOL> c . send ( ( '<STR_LIT>' , format_exc ( ) ) ) <EOL> except Exception : <EOL> pass <EOL> util . info ( '<STR_LIT>' , msg ) <EOL> util . info ( '<STR_LIT>' , request ) <EOL> util . info ( '<STR_LIT>' , e ) <EOL> c . close ( ) <EOL> def serve_client ( self , conn ) : <EOL> '''<STR_LIT>''' <EOL> util . debug ( '<STR_LIT>' , <EOL> threading . current_thread ( ) . name ) <EOL> recv = conn . recv <EOL> send = conn . send <EOL> id_to_obj = self . id_to_obj <EOL> while not self . stop : <EOL> try : <EOL> methodname = obj = None <EOL> request = recv ( ) <EOL> ident , methodname , args , kwds = request <EOL> obj , exposed , gettypeid = id_to_obj [ ident ] <EOL> if methodname not in exposed : <EOL> raise AttributeError ( <EOL> '<STR_LIT>' % <EOL> ( methodname , type ( obj ) , exposed ) <EOL> ) <EOL> function = getattr ( obj , methodname ) <EOL> try : <EOL> res = function ( * args , ** kwds ) <EOL> except Exception , e : <EOL> msg = ( '<STR_LIT>' , e ) <EOL> else : <EOL> typeid = gettypeid and gettypeid . get ( methodname , None ) <EOL> if typeid : <EOL> rident , rexposed = self . create ( conn , typeid , res ) <EOL> token = Token ( typeid , self . address , rident ) <EOL> msg = ( '<STR_LIT>' , ( rexposed , token ) ) <EOL> else : <EOL> msg = ( '<STR_LIT>' , res ) <EOL> except AttributeError : <EOL> if methodname is None : <EOL> msg = ( '<STR_LIT>' , format_exc ( ) ) <EOL> else : <EOL> try : <EOL> fallback_func = self . fallback_mapping [ methodname ] <EOL> result = fallback_func ( <EOL> self , conn , ident , obj , * args , ** kwds <EOL> ) <EOL> msg = ( '<STR_LIT>' , result ) <EOL> except Exception : <EOL> msg = ( '<STR_LIT>' , format_exc ( ) ) <EOL> except EOFError : <EOL> util . debug ( '<STR_LIT>' , <EOL> threading . current_thread ( ) . name ) <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> except Exception : <EOL> msg = ( '<STR_LIT>' , format_exc ( ) ) <EOL> try : <EOL> try : <EOL> send ( msg ) <EOL> except Exception , e : <EOL> send ( ( '<STR_LIT>' , repr ( msg ) ) ) <EOL> except Exception , e : <EOL> util . info ( '<STR_LIT>' , <EOL> threading . current_thread ( ) . name ) <EOL> util . info ( '<STR_LIT>' , msg ) <EOL> util . info ( '<STR_LIT>' , e ) <EOL> conn . close ( ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> def fallback_getvalue ( self , conn , ident , obj ) : <EOL> return obj <EOL> def fallback_str ( self , conn , ident , obj ) : <EOL> return str ( obj ) <EOL> def fallback_repr ( self , conn , ident , obj ) : <EOL> return repr ( obj ) <EOL> fallback_mapping = { <EOL> '<STR_LIT>' : fallback_str , <EOL> '<STR_LIT>' : fallback_repr , <EOL> '<STR_LIT>' : fallback_getvalue <EOL> } <EOL> def dummy ( self , c ) : <EOL> pass <EOL> def debug_info ( self , c ) : <EOL> '''<STR_LIT>''' <EOL> self . mutex . acquire ( ) <EOL> try : <EOL> result = [ ] <EOL> keys = self . id_to_obj . keys ( ) <EOL> keys . sort ( ) <EOL> for ident in keys : <EOL> if ident != '<STR_LIT:0>' : <EOL> result . append ( '<STR_LIT>' % <EOL> ( ident , self . id_to_refcount [ ident ] , <EOL> str ( self . id_to_obj [ ident ] [ <NUM_LIT:0> ] ) [ : <NUM_LIT> ] ) ) <EOL> return '<STR_LIT:\n>' . join ( result ) <EOL> finally : <EOL> self . mutex . release ( ) <EOL> def number_of_objects ( self , c ) : <EOL> '''<STR_LIT>''' <EOL> return len ( self . id_to_obj ) - <NUM_LIT:1> <EOL> def shutdown ( self , c ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> try : <EOL> util . debug ( '<STR_LIT>' ) <EOL> c . send ( ( '<STR_LIT>' , None ) ) <EOL> if sys . stdout != sys . __stdout__ : <EOL> util . debug ( '<STR_LIT>' ) <EOL> sys . stdout = sys . __stdout__ <EOL> sys . stderr = sys . __stderr__ <EOL> util . _run_finalizers ( <NUM_LIT:0> ) <EOL> for p in active_children ( ) : <EOL> util . debug ( '<STR_LIT>' ) <EOL> p . terminate ( ) <EOL> for p in active_children ( ) : <EOL> util . debug ( '<STR_LIT>' ) <EOL> p . join ( ) <EOL> util . _run_finalizers ( ) <EOL> util . info ( '<STR_LIT>' ) <EOL> except : <EOL> import traceback <EOL> traceback . print_exc ( ) <EOL> finally : <EOL> exit ( <NUM_LIT:0> ) <EOL> def create ( self , c , typeid , * args , ** kwds ) : <EOL> '''<STR_LIT>''' <EOL> self . mutex . acquire ( ) <EOL> try : <EOL> callable , exposed , method_to_typeid , proxytype = self . registry [ typeid ] <EOL> if callable is None : <EOL> assert len ( args ) == <NUM_LIT:1> and not kwds <EOL> obj = args [ <NUM_LIT:0> ] <EOL> else : <EOL> obj = callable ( * args , ** kwds ) <EOL> if exposed is None : <EOL> exposed = public_methods ( obj ) <EOL> if method_to_typeid is not None : <EOL> assert type ( method_to_typeid ) is dict <EOL> exposed = list ( exposed ) + list ( method_to_typeid ) <EOL> ident = '<STR_LIT>' % id ( obj ) <EOL> util . debug ( '<STR_LIT>' , typeid , ident ) <EOL> self . id_to_obj [ ident ] = ( obj , set ( exposed ) , method_to_typeid ) <EOL> if ident not in self . id_to_refcount : <EOL> self . id_to_refcount [ ident ] = <NUM_LIT:0> <EOL> self . incref ( c , ident ) <EOL> return ident , tuple ( exposed ) <EOL> finally : <EOL> self . mutex . release ( ) <EOL> def get_methods ( self , c , token ) : <EOL> '''<STR_LIT>''' <EOL> return tuple ( self . id_to_obj [ token . id ] [ <NUM_LIT:1> ] ) <EOL> def accept_connection ( self , c , name ) : <EOL> '''<STR_LIT>''' <EOL> threading . current_thread ( ) . name = name <EOL> c . send ( ( '<STR_LIT>' , None ) ) <EOL> self . serve_client ( c ) <EOL> def incref ( self , c , ident ) : <EOL> self . mutex . acquire ( ) <EOL> try : <EOL> self . id_to_refcount [ ident ] += <NUM_LIT:1> <EOL> finally : <EOL> self . mutex . release ( ) <EOL> def decref ( self , c , ident ) : <EOL> self . mutex . acquire ( ) <EOL> try : <EOL> assert self . id_to_refcount [ ident ] >= <NUM_LIT:1> <EOL> self . id_to_refcount [ ident ] -= <NUM_LIT:1> <EOL> if self . id_to_refcount [ ident ] == <NUM_LIT:0> : <EOL> del self . id_to_obj [ ident ] , self . id_to_refcount [ ident ] <EOL> util . debug ( '<STR_LIT>' , ident ) <EOL> finally : <EOL> self . mutex . release ( ) <EOL> class State ( object ) : <EOL> __slots__ = [ '<STR_LIT:value>' ] <EOL> INITIAL = <NUM_LIT:0> <EOL> STARTED = <NUM_LIT:1> <EOL> SHUTDOWN = <NUM_LIT:2> <EOL> listener_client = { <EOL> '<STR_LIT>' : ( connection . Listener , connection . Client ) , <EOL> '<STR_LIT>' : ( connection . XmlListener , connection . XmlClient ) <EOL> } <EOL> class BaseManager ( object ) : <EOL> '''<STR_LIT>''' <EOL> _registry = { } <EOL> _Server = Server <EOL> def __init__ ( self , address = None , authkey = None , serializer = '<STR_LIT>' ) : <EOL> if authkey is None : <EOL> authkey = current_process ( ) . authkey <EOL> self . _address = address <EOL> self . _authkey = AuthenticationString ( authkey ) <EOL> self . _state = State ( ) <EOL> self . _state . value = State . INITIAL <EOL> self . _serializer = serializer <EOL> self . _Listener , self . _Client = listener_client [ serializer ] <EOL> def __reduce__ ( self ) : <EOL> return type ( self ) . from_address , ( self . _address , self . _authkey , self . _serializer ) <EOL> def get_server ( self ) : <EOL> '''<STR_LIT>''' <EOL> assert self . _state . value == State . INITIAL <EOL> return Server ( self . _registry , self . _address , <EOL> self . _authkey , self . _serializer ) <EOL> def connect ( self ) : <EOL> '''<STR_LIT>''' <EOL> Listener , Client = listener_client [ self . _serializer ] <EOL> conn = Client ( self . _address , authkey = self . _authkey ) <EOL> dispatch ( conn , None , '<STR_LIT>' ) <EOL> self . _state . value = State . STARTED <EOL> def start ( self , initializer = None , initargs = ( ) ) : <EOL> '''<STR_LIT>''' <EOL> assert self . _state . value == State . INITIAL <EOL> if initializer is not None and not hasattr ( initializer , '<STR_LIT>' ) : <EOL> raise TypeError ( '<STR_LIT>' ) <EOL> reader , writer = connection . Pipe ( duplex = False ) <EOL> self . _process = Process ( <EOL> target = type ( self ) . _run_server , <EOL> args = ( self . _registry , self . _address , self . _authkey , <EOL> self . _serializer , writer , initializer , initargs ) , <EOL> ) <EOL> ident = '<STR_LIT::>' . join ( str ( i ) for i in self . _process . _identity ) <EOL> self . _process . name = type ( self ) . __name__ + '<STR_LIT:->' + ident <EOL> self . _process . start ( ) <EOL> writer . close ( ) <EOL> self . _address = reader . recv ( ) <EOL> reader . close ( ) <EOL> self . _state . value = State . STARTED <EOL> self . shutdown = util . Finalize ( <EOL> self , type ( self ) . _finalize_manager , <EOL> args = ( self . _process , self . _address , self . _authkey , <EOL> self . _state , self . _Client ) , <EOL> exitpriority = <NUM_LIT:0> <EOL> ) <EOL> @ classmethod <EOL> def _run_server ( cls , registry , address , authkey , serializer , writer , <EOL> initializer = None , initargs = ( ) ) : <EOL> '''<STR_LIT>''' <EOL> if initializer is not None : <EOL> initializer ( * initargs ) <EOL> server = cls . _Server ( registry , address , authkey , serializer ) <EOL> writer . send ( server . address ) <EOL> writer . close ( ) <EOL> util . info ( '<STR_LIT>' , server . address ) <EOL> server . serve_forever ( ) <EOL> def _create ( self , typeid , * args , ** kwds ) : <EOL> '''<STR_LIT>''' <EOL> assert self . _state . value == State . STARTED , '<STR_LIT>' <EOL> conn = self . _Client ( self . _address , authkey = self . _authkey ) <EOL> try : <EOL> id , exposed = dispatch ( conn , None , '<STR_LIT>' , ( typeid , ) + args , kwds ) <EOL> finally : <EOL> conn . close ( ) <EOL> return Token ( typeid , self . _address , id ) , exposed <EOL> def join ( self , timeout = None ) : <EOL> '''<STR_LIT>''' <EOL> self . _process . join ( timeout ) <EOL> def _debug_info ( self ) : <EOL> '''<STR_LIT>''' <EOL> conn = self . _Client ( self . _address , authkey = self . _authkey ) <EOL> try : <EOL> return dispatch ( conn , None , '<STR_LIT>' ) <EOL> finally : <EOL> conn . close ( ) <EOL> def _number_of_objects ( self ) : <EOL> '''<STR_LIT>''' <EOL> conn = self . _Client ( self . _address , authkey = self . _authkey ) <EOL> try : <EOL> return dispatch ( conn , None , '<STR_LIT>' ) <EOL> finally : <EOL> conn . close ( ) <EOL> def __enter__ ( self ) : <EOL> return self <EOL> def __exit__ ( self , exc_type , exc_val , exc_tb ) : <EOL> self . shutdown ( ) <EOL> @ staticmethod <EOL> def _finalize_manager ( process , address , authkey , state , _Client ) : <EOL> '''<STR_LIT>''' <EOL> if process . is_alive ( ) : <EOL> util . info ( '<STR_LIT>' ) <EOL> try : <EOL> conn = _Client ( address , authkey = authkey ) <EOL> try : <EOL> dispatch ( conn , None , '<STR_LIT>' ) <EOL> finally : <EOL> conn . close ( ) <EOL> except Exception : <EOL> pass <EOL> process . join ( timeout = <NUM_LIT> ) <EOL> if process . is_alive ( ) : <EOL> util . info ( '<STR_LIT>' ) <EOL> if hasattr ( process , '<STR_LIT>' ) : <EOL> util . info ( '<STR_LIT>' ) <EOL> process . terminate ( ) <EOL> process . join ( timeout = <NUM_LIT:0.1> ) <EOL> if process . is_alive ( ) : <EOL> util . info ( '<STR_LIT>' ) <EOL> state . value = State . SHUTDOWN <EOL> try : <EOL> del BaseProxy . _address_to_local [ address ] <EOL> except KeyError : <EOL> pass <EOL> address = property ( lambda self : self . _address ) <EOL> @ classmethod <EOL> def register ( cls , typeid , callable = None , proxytype = None , exposed = None , <EOL> method_to_typeid = None , create_method = True ) : <EOL> '''<STR_LIT>''' <EOL> if '<STR_LIT>' not in cls . __dict__ : <EOL> cls . _registry = cls . _registry . copy ( ) <EOL> if proxytype is None : <EOL> proxytype = AutoProxy <EOL> exposed = exposed or getattr ( proxytype , '<STR_LIT>' , None ) <EOL> method_to_typeid = method_to_typeid or getattr ( proxytype , '<STR_LIT>' , None ) <EOL> if method_to_typeid : <EOL> for key , value in method_to_typeid . items ( ) : <EOL> assert type ( key ) is str , '<STR_LIT>' % key <EOL> assert type ( value ) is str , '<STR_LIT>' % value <EOL> cls . _registry [ typeid ] = ( <EOL> callable , exposed , method_to_typeid , proxytype <EOL> ) <EOL> if create_method : <EOL> def temp ( self , * args , ** kwds ) : <EOL> util . debug ( '<STR_LIT>' , typeid ) <EOL> token , exp = self . _create ( typeid , * args , ** kwds ) <EOL> proxy = proxytype ( <EOL> token , self . _serializer , manager = self , <EOL> authkey = self . _authkey , exposed = exp <EOL> ) <EOL> conn = self . _Client ( token . address , authkey = self . _authkey ) <EOL> dispatch ( conn , None , '<STR_LIT>' , ( token . id , ) ) <EOL> return proxy <EOL> temp . __name__ = typeid <EOL> setattr ( cls , typeid , temp ) <EOL> class ProcessLocalSet ( set ) : <EOL> def __init__ ( self ) : <EOL> util . register_after_fork ( self , lambda obj : obj . clear ( ) ) <EOL> def __reduce__ ( self ) : <EOL> return type ( self ) , ( ) <EOL> class BaseProxy ( object ) : <EOL> '''<STR_LIT>''' <EOL> _address_to_local = { } <EOL> _mutex = util . ForkAwareThreadLock ( ) <EOL> def __init__ ( self , token , serializer , manager = None , <EOL> authkey = None , exposed = None , incref = True ) : <EOL> BaseProxy . _mutex . acquire ( ) <EOL> try : <EOL> tls_idset = BaseProxy . _address_to_local . get ( token . address , None ) <EOL> if tls_idset is None : <EOL> tls_idset = util . ForkAwareLocal ( ) , ProcessLocalSet ( ) <EOL> BaseProxy . _address_to_local [ token . address ] = tls_idset <EOL> finally : <EOL> BaseProxy . _mutex . release ( ) <EOL> self . _tls = tls_idset [ <NUM_LIT:0> ] <EOL> self . _idset = tls_idset [ <NUM_LIT:1> ] <EOL> self . _token = token <EOL> self . _id = self . _token . id <EOL> self . _manager = manager <EOL> self . _serializer = serializer <EOL> self . _Client = listener_client [ serializer ] [ <NUM_LIT:1> ] <EOL> if authkey is not None : <EOL> self . _authkey = AuthenticationString ( authkey ) <EOL> elif self . _manager is not None : <EOL> self . _authkey = self . _manager . _authkey <EOL> else : <EOL> self . _authkey = current_process ( ) . authkey <EOL> if incref : <EOL> self . _incref ( ) <EOL> util . register_after_fork ( self , BaseProxy . _after_fork ) <EOL> def _connect ( self ) : <EOL> util . debug ( '<STR_LIT>' ) <EOL> name = current_process ( ) . name <EOL> if threading . current_thread ( ) . name != '<STR_LIT>' : <EOL> name += '<STR_LIT:|>' + threading . current_thread ( ) . name <EOL> conn = self . _Client ( self . _token . address , authkey = self . _authkey ) <EOL> dispatch ( conn , None , '<STR_LIT>' , ( name , ) ) <EOL> self . _tls . connection = conn <EOL> def _callmethod ( self , methodname , args = ( ) , kwds = { } ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> conn = self . _tls . connection <EOL> except AttributeError : <EOL> util . debug ( '<STR_LIT>' , <EOL> threading . current_thread ( ) . name ) <EOL> self . _connect ( ) <EOL> conn = self . _tls . connection <EOL> conn . send ( ( self . _id , methodname , args , kwds ) ) <EOL> kind , result = conn . recv ( ) <EOL> if kind == '<STR_LIT>' : <EOL> return result <EOL> elif kind == '<STR_LIT>' : <EOL> exposed , token = result <EOL> proxytype = self . _manager . _registry [ token . typeid ] [ - <NUM_LIT:1> ] <EOL> token . address = self . _token . address <EOL> proxy = proxytype ( <EOL> token , self . _serializer , manager = self . _manager , <EOL> authkey = self . _authkey , exposed = exposed <EOL> ) <EOL> conn = self . _Client ( token . address , authkey = self . _authkey ) <EOL> dispatch ( conn , None , '<STR_LIT>' , ( token . id , ) ) <EOL> return proxy <EOL> raise convert_to_error ( kind , result ) <EOL> def _getvalue ( self ) : <EOL> '''<STR_LIT>''' <EOL> return self . _callmethod ( '<STR_LIT>' ) <EOL> def _incref ( self ) : <EOL> conn = self . _Client ( self . _token . address , authkey = self . _authkey ) <EOL> dispatch ( conn , None , '<STR_LIT>' , ( self . _id , ) ) <EOL> util . debug ( '<STR_LIT>' , self . _token . id ) <EOL> self . _idset . add ( self . _id ) <EOL> state = self . _manager and self . _manager . _state <EOL> self . _close = util . Finalize ( <EOL> self , BaseProxy . _decref , <EOL> args = ( self . _token , self . _authkey , state , <EOL> self . _tls , self . _idset , self . _Client ) , <EOL> exitpriority = <NUM_LIT:10> <EOL> ) <EOL> @ staticmethod <EOL> def _decref ( token , authkey , state , tls , idset , _Client ) : <EOL> idset . discard ( token . id ) <EOL> if state is None or state . value == State . STARTED : <EOL> try : <EOL> util . debug ( '<STR_LIT>' , token . id ) <EOL> conn = _Client ( token . address , authkey = authkey ) <EOL> dispatch ( conn , None , '<STR_LIT>' , ( token . id , ) ) <EOL> except Exception , e : <EOL> util . debug ( '<STR_LIT>' , e ) <EOL> else : <EOL> util . debug ( '<STR_LIT>' , token . id ) <EOL> if not idset and hasattr ( tls , '<STR_LIT>' ) : <EOL> util . debug ( '<STR_LIT>' , <EOL> threading . current_thread ( ) . name ) <EOL> tls . connection . close ( ) <EOL> del tls . connection <EOL> def _after_fork ( self ) : <EOL> self . _manager = None <EOL> try : <EOL> self . _incref ( ) <EOL> except Exception , e : <EOL> util . info ( '<STR_LIT>' % e ) <EOL> def __reduce__ ( self ) : <EOL> kwds = { } <EOL> if Popen . thread_is_spawning ( ) : <EOL> kwds [ '<STR_LIT>' ] = self . _authkey <EOL> if getattr ( self , '<STR_LIT>' , False ) : <EOL> kwds [ '<STR_LIT>' ] = self . _exposed_ <EOL> return ( RebuildProxy , <EOL> ( AutoProxy , self . _token , self . _serializer , kwds ) ) <EOL> else : <EOL> return ( RebuildProxy , <EOL> ( type ( self ) , self . _token , self . _serializer , kwds ) ) <EOL> def __deepcopy__ ( self , memo ) : <EOL> return self . _getvalue ( ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( type ( self ) . __name__ , self . _token . typeid , '<STR_LIT>' % id ( self ) ) <EOL> def __str__ ( self ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> return self . _callmethod ( '<STR_LIT>' ) <EOL> except Exception : <EOL> return repr ( self ) [ : - <NUM_LIT:1> ] + "<STR_LIT>" <EOL> def RebuildProxy ( func , token , serializer , kwds ) : <EOL> '''<STR_LIT>''' <EOL> server = getattr ( current_process ( ) , '<STR_LIT>' , None ) <EOL> if server and server . address == token . address : <EOL> return server . id_to_obj [ token . id ] [ <NUM_LIT:0> ] <EOL> else : <EOL> incref = ( <EOL> kwds . pop ( '<STR_LIT>' , True ) and <EOL> not getattr ( current_process ( ) , '<STR_LIT>' , False ) <EOL> ) <EOL> return func ( token , serializer , incref = incref , ** kwds ) <EOL> def MakeProxyType ( name , exposed , _cache = { } ) : <EOL> '''<STR_LIT>''' <EOL> exposed = tuple ( exposed ) <EOL> try : <EOL> return _cache [ ( name , exposed ) ] <EOL> except KeyError : <EOL> pass <EOL> dic = { } <EOL> for meth in exposed : <EOL> exec '''<STR_LIT>''' % ( meth , meth ) in dic <EOL> ProxyType = type ( name , ( BaseProxy , ) , dic ) <EOL> ProxyType . _exposed_ = exposed <EOL> _cache [ ( name , exposed ) ] = ProxyType <EOL> return ProxyType <EOL> def AutoProxy ( token , serializer , manager = None , authkey = None , <EOL> exposed = None , incref = True ) : <EOL> '''<STR_LIT>''' <EOL> _Client = listener_client [ serializer ] [ <NUM_LIT:1> ] <EOL> if exposed is None : <EOL> conn = _Client ( token . address , authkey = authkey ) <EOL> try : <EOL> exposed = dispatch ( conn , None , '<STR_LIT>' , ( token , ) ) <EOL> finally : <EOL> conn . close ( ) <EOL> if authkey is None and manager is not None : <EOL> authkey = manager . _authkey <EOL> if authkey is None : <EOL> authkey = current_process ( ) . authkey <EOL> ProxyType = MakeProxyType ( '<STR_LIT>' % token . typeid , exposed ) <EOL> proxy = ProxyType ( token , serializer , manager = manager , authkey = authkey , <EOL> incref = incref ) <EOL> proxy . _isauto = True <EOL> return proxy <EOL> class Namespace ( object ) : <EOL> def __init__ ( self , ** kwds ) : <EOL> self . __dict__ . update ( kwds ) <EOL> def __repr__ ( self ) : <EOL> items = self . __dict__ . items ( ) <EOL> temp = [ ] <EOL> for name , value in items : <EOL> if not name . startswith ( '<STR_LIT:_>' ) : <EOL> temp . append ( '<STR_LIT>' % ( name , value ) ) <EOL> temp . sort ( ) <EOL> return '<STR_LIT>' % str . join ( '<STR_LIT:U+002CU+0020>' , temp ) <EOL> class Value ( object ) : <EOL> def __init__ ( self , typecode , value , lock = True ) : <EOL> self . _typecode = typecode <EOL> self . _value = value <EOL> def get ( self ) : <EOL> return self . _value <EOL> def set ( self , value ) : <EOL> self . _value = value <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( type ( self ) . __name__ , self . _typecode , self . _value ) <EOL> value = property ( get , set ) <EOL> def Array ( typecode , sequence , lock = True ) : <EOL> return array . array ( typecode , sequence ) <EOL> class IteratorProxy ( BaseProxy ) : <EOL> _exposed_ = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> def __iter__ ( self ) : <EOL> return self <EOL> def __next__ ( self , * args ) : <EOL> return self . _callmethod ( '<STR_LIT>' , args ) <EOL> def next ( self , * args ) : <EOL> return self . _callmethod ( '<STR_LIT>' , args ) <EOL> def send ( self , * args ) : <EOL> return self . _callmethod ( '<STR_LIT>' , args ) <EOL> def throw ( self , * args ) : <EOL> return self . _callmethod ( '<STR_LIT>' , args ) <EOL> def close ( self , * args ) : <EOL> return self . _callmethod ( '<STR_LIT>' , args ) <EOL> class AcquirerProxy ( BaseProxy ) : <EOL> _exposed_ = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def acquire ( self , blocking = True ) : <EOL> return self . _callmethod ( '<STR_LIT>' , ( blocking , ) ) <EOL> def release ( self ) : <EOL> return self . _callmethod ( '<STR_LIT>' ) <EOL> def __enter__ ( self ) : <EOL> return self . _callmethod ( '<STR_LIT>' ) <EOL> def __exit__ ( self , exc_type , exc_val , exc_tb ) : <EOL> return self . _callmethod ( '<STR_LIT>' ) <EOL> class ConditionProxy ( AcquirerProxy ) : <EOL> _exposed_ = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> def wait ( self , timeout = None ) : <EOL> return self . _callmethod ( '<STR_LIT>' , ( timeout , ) ) <EOL> def notify ( self ) : <EOL> return self . _callmethod ( '<STR_LIT>' ) <EOL> def notify_all ( self ) : <EOL> return self . _callmethod ( '<STR_LIT>' ) <EOL> class EventProxy ( BaseProxy ) : <EOL> _exposed_ = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> def is_set ( self ) : <EOL> return self . _callmethod ( '<STR_LIT>' ) <EOL> def set ( self ) : <EOL> return self . _callmethod ( '<STR_LIT>' ) <EOL> def clear ( self ) : <EOL> return self . _callmethod ( '<STR_LIT>' ) <EOL> def wait ( self , timeout = None ) : <EOL> return self . _callmethod ( '<STR_LIT>' , ( timeout , ) ) <EOL> class NamespaceProxy ( BaseProxy ) : <EOL> _exposed_ = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> def __getattr__ ( self , key ) : <EOL> if key [ <NUM_LIT:0> ] == '<STR_LIT:_>' : <EOL> return object . __getattribute__ ( self , key ) <EOL> callmethod = object . __getattribute__ ( self , '<STR_LIT>' ) <EOL> return callmethod ( '<STR_LIT>' , ( key , ) ) <EOL> def __setattr__ ( self , key , value ) : <EOL> if key [ <NUM_LIT:0> ] == '<STR_LIT:_>' : <EOL> return object . __setattr__ ( self , key , value ) <EOL> callmethod = object . __getattribute__ ( self , '<STR_LIT>' ) <EOL> return callmethod ( '<STR_LIT>' , ( key , value ) ) <EOL> def __delattr__ ( self , key ) : <EOL> if key [ <NUM_LIT:0> ] == '<STR_LIT:_>' : <EOL> return object . __delattr__ ( self , key ) <EOL> callmethod = object . __getattribute__ ( self , '<STR_LIT>' ) <EOL> return callmethod ( '<STR_LIT>' , ( key , ) ) <EOL> class ValueProxy ( BaseProxy ) : <EOL> _exposed_ = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def get ( self ) : <EOL> return self . _callmethod ( '<STR_LIT>' ) <EOL> def set ( self , value ) : <EOL> return self . _callmethod ( '<STR_LIT>' , ( value , ) ) <EOL> value = property ( get , set ) <EOL> BaseListProxy = MakeProxyType ( '<STR_LIT>' , ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT:count>' , '<STR_LIT>' , '<STR_LIT:index>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ) ) <EOL> class ListProxy ( BaseListProxy ) : <EOL> def __iadd__ ( self , value ) : <EOL> self . _callmethod ( '<STR_LIT>' , ( value , ) ) <EOL> return self <EOL> def __imul__ ( self , value ) : <EOL> self . _callmethod ( '<STR_LIT>' , ( value , ) ) <EOL> return self <EOL> DictProxy = MakeProxyType ( '<STR_LIT>' , ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ) ) <EOL> ArrayProxy = MakeProxyType ( '<STR_LIT>' , ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ) ) <EOL> PoolProxy = MakeProxyType ( '<STR_LIT>' , ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ) ) <EOL> PoolProxy . _method_to_typeid_ = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> class SyncManager ( BaseManager ) : <EOL> '''<STR_LIT>''' <EOL> SyncManager . register ( '<STR_LIT>' , Queue . Queue ) <EOL> SyncManager . register ( '<STR_LIT>' , Queue . Queue ) <EOL> SyncManager . register ( '<STR_LIT>' , threading . Event , EventProxy ) <EOL> SyncManager . register ( '<STR_LIT>' , threading . Lock , AcquirerProxy ) <EOL> SyncManager . register ( '<STR_LIT>' , threading . RLock , AcquirerProxy ) <EOL> SyncManager . register ( '<STR_LIT>' , threading . Semaphore , AcquirerProxy ) <EOL> SyncManager . register ( '<STR_LIT>' , threading . BoundedSemaphore , <EOL> AcquirerProxy ) <EOL> SyncManager . register ( '<STR_LIT>' , threading . Condition , ConditionProxy ) <EOL> SyncManager . register ( '<STR_LIT>' , Pool , PoolProxy ) <EOL> SyncManager . register ( '<STR_LIT:list>' , list , ListProxy ) <EOL> SyncManager . register ( '<STR_LIT>' , dict , DictProxy ) <EOL> SyncManager . register ( '<STR_LIT>' , Value , ValueProxy ) <EOL> SyncManager . register ( '<STR_LIT>' , Array , ArrayProxy ) <EOL> SyncManager . register ( '<STR_LIT>' , Namespace , NamespaceProxy ) <EOL> SyncManager . register ( '<STR_LIT>' , proxytype = IteratorProxy , create_method = False ) <EOL> SyncManager . register ( '<STR_LIT>' , create_method = False ) </s>
