#NEWLINE# def __init__( self , remote_machine , server_class = 'rpyc.utils.server.ThreadedServer' , extra_setup = '' , python_executable = None ) : #NEWLINE# #INDENT# self . proc = None #NEWLINE# self . tun = None #NEWLINE# self . remote_machine = remote_machine #NEWLINE# self . _tmpdir_ctx = None #NEWLINE# rpyc_root = local . path ( rpyc . __file__ ) . up ( ) #NEWLINE# self . _tmpdir_ctx = remote_machine . tempdir ( ) #NEWLINE# tmp = self . _tmpdir_ctx . __enter__ ( ) #NEWLINE# copy ( rpyc_root , ( tmp / 'rpyc' ) ) #NEWLINE# script = ( tmp / 'deployed-rpyc.py' ) #NEWLINE# ( modname , clsname ) = server_class . rsplit ( '.' , 1 ) #NEWLINE# script . write ( SERVER_SCRIPT . replace ( '$MODULE$' , modname ) . replace ( '$SERVER$' , clsname ) . replace ( '$EXTRA_SETUP$' , extra_setup ) ) #NEWLINE# if python_executable : #NEWLINE# #INDENT# cmd = remote_machine [ python_executable ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# major = sys . version_info [ 0 ] #NEWLINE# minor = sys . version_info [ 1 ] #NEWLINE# cmd = None #NEWLINE# for opt in [ ( 'python%s.%s' % ( major , minor ) ) , ( 'python%s' % ( major , ) ) ] : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# cmd = remote_machine [ opt ] #NEWLINE# #UNINDENT# except CommandNotFound : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# #UNINDENT# if ( not cmd ) : #NEWLINE# #INDENT# cmd = remote_machine . python #NEWLINE# #UNINDENT# #UNINDENT# self . proc = cmd . popen ( script , new_session = True ) #NEWLINE# line = '' #NEWLINE# try : #NEWLINE# #INDENT# line = self . proc . stdout . readline ( ) #NEWLINE# self . remote_port = int ( line . strip ( ) ) #NEWLINE# #UNINDENT# except Exception : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# self . proc . terminate ( ) #NEWLINE# #UNINDENT# except Exception : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# ( stdout , stderr ) = self . proc . communicate ( ) #NEWLINE# raise ProcessExecutionError ( self . proc . argv , self . proc . returncode , ( BYTES_LITERAL ( line ) + stdout ) , stderr ) #NEWLINE# #UNINDENT# if hasattr ( remote_machine , 'connect_sock' ) : #NEWLINE# #INDENT# self . local_port = None #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# s = socket . socket ( socket . AF_INET , socket . SOCK_STREAM ) #NEWLINE# s . bind ( ( 'localhost' , 0 ) ) #NEWLINE# self . local_port = s . getsockname ( ) [ 1 ] #NEWLINE# s . close ( ) #NEWLINE# self . tun = remote_machine . tunnel ( self . local_port , self . remote_port )