idlelib.rpc
index
/usr/local/lib/python2.3/idlelib/rpc.py

RPC Implemention, originally written for the Python Idle IDE
 
For security reasons, GvR requested that Idle's Python execution server process
connect to the Idle process, which listens for the connection.  Since Idle has
has only one client per server, this was not a limitation.
 
   +---------------------------------+ +-------------+
   | SocketServer.BaseRequestHandler | | SocketIO    |
   +---------------------------------+ +-------------+
                   ^                   | register()  |
                   |                   | unregister()|
                   |                   +-------------+
                   |                      ^  ^
                   |                      |  |
                   | + -------------------+  |
                   | |                       |
   +-------------------------+        +-----------------+
   | RPCHandler              |        | RPCClient       |
   | [attribute of RPCServer]|        |                 |
   +-------------------------+        +-----------------+
 
The RPCServer handler class is expected to provide register/unregister methods.
RPCHandler inherits the mix-in class SocketIO, which provides these methods.
 
See the Idle run.main() docstring for further information on how this was
accomplished in Idle.

 
Modules
       
Queue
SocketServer
copy_reg
marshal
os
cPickle
select
socket
struct
sys
threading
traceback
types

 
Classes
       
SocketServer.BaseRequestHandler
RPCHandler(SocketServer.BaseRequestHandler, SocketIO)
MethodProxy
RPCProxy
RemoteObject
RemoteProxy
SocketIO
RPCClient
RPCHandler(SocketServer.BaseRequestHandler, SocketIO)
SocketServer.TCPServer(SocketServer.BaseServer)
RPCServer

 
class MethodProxy
     Methods defined here:
__call__(self, *args, **kwargs)
__init__(self, sockio, oid, name)

 
class RPCClient(SocketIO)
     Methods defined here:
__init__(self, address, family=2, type=1)
accept(self)
get_remote_proxy(self, oid)

Data and other attributes defined here:
debugging = False
location = '#C'
nextseq = 1

Methods inherited from SocketIO:
EOFhook(self)
Classes using rpc client/server can override to augment EOF action
asynccall(self, oid, methodname, args, kwargs)
asyncqueue(self, oid, methodname, args, kwargs)
asyncreturn(self, seq)
close(self)
debug(self, *args)
decode_interrupthook(self)
decoderesponse(self, response)
exithook(self)
override for specific exit action
getresponse(self, myseq, wait)
handle_EOF(self)
action taken upon link being closed by peer
ioready(self, wait)
localcall(self, seq, request)
mainloop(self)
Listen on socket until I/O not ready or EOF
 
pollresponse() will loop looking for seq number None, which
never comes, and exit on EOFError.
newseq(self)
pollmessage(self, wait)
pollpacket(self, wait)
pollresponse(self, myseq, wait)
Handle messages received on the socket.
 
Some messages received may be asynchronous 'call' or 'queue' requests,
and some may be responses for other threads.
 
'call' requests are passed to localcall() with the expectation of
immediate execution, during which time the socket is not serviced.
 
'queue' requests are used for tasks (which may block or hang) to be
processed in a different thread.  These requests are fed into
request_queue by localcall().  Responses to queued requests are
taken from response_queue and sent across the link with the associated
sequence numbers.  Messages in the queues are (sequence_number,
request/response) tuples and code using this module removing messages
from the request_queue is responsible for returning the correct
sequence number in the response_queue.
 
pollresponse() will loop until a response message with the myseq
sequence number is received, and will save other responses in
self.responses and notify the owning thread.
putmessage(self, message)
register(self, oid, object)
remotecall(self, oid, methodname, args, kwargs)
remotequeue(self, oid, methodname, args, kwargs)
unregister(self, oid)

Data and other attributes inherited from SocketIO:
buffer = ''
bufneed = 4
bufstate = 0

 
class RPCHandler(SocketServer.BaseRequestHandler, SocketIO)
    
Method resolution order:
RPCHandler
SocketServer.BaseRequestHandler
SocketIO

Methods defined here:
__init__(self, sock, addr, svr)
get_remote_proxy(self, oid)
handle(self)
handle() method required by SocketServer

Data and other attributes defined here:
debugging = False
location = '#S'

Methods inherited from SocketServer.BaseRequestHandler:
finish(self)
setup(self)

Methods inherited from SocketIO:
EOFhook(self)
Classes using rpc client/server can override to augment EOF action
asynccall(self, oid, methodname, args, kwargs)
asyncqueue(self, oid, methodname, args, kwargs)
asyncreturn(self, seq)
close(self)
debug(self, *args)
decode_interrupthook(self)
decoderesponse(self, response)
exithook(self)
override for specific exit action
getresponse(self, myseq, wait)
handle_EOF(self)
action taken upon link being closed by peer
ioready(self, wait)
localcall(self, seq, request)
mainloop(self)
Listen on socket until I/O not ready or EOF
 
pollresponse() will loop looking for seq number None, which
never comes, and exit on EOFError.
newseq(self)
pollmessage(self, wait)
pollpacket(self, wait)
pollresponse(self, myseq, wait)
Handle messages received on the socket.
 
Some messages received may be asynchronous 'call' or 'queue' requests,
and some may be responses for other threads.
 
'call' requests are passed to localcall() with the expectation of
immediate execution, during which time the socket is not serviced.
 
'queue' requests are used for tasks (which may block or hang) to be
processed in a different thread.  These requests are fed into
request_queue by localcall().  Responses to queued requests are
taken from response_queue and sent across the link with the associated
sequence numbers.  Messages in the queues are (sequence_number,
request/response) tuples and code using this module removing messages
from the request_queue is responsible for returning the correct
sequence number in the response_queue.
 
pollresponse() will loop until a response message with the myseq
sequence number is received, and will save other responses in
self.responses and notify the owning thread.
putmessage(self, message)
register(self, oid, object)
remotecall(self, oid, methodname, args, kwargs)
remotequeue(self, oid, methodname, args, kwargs)
unregister(self, oid)

Data and other attributes inherited from SocketIO:
buffer = ''
bufneed = 4
bufstate = 0
nextseq = 0

 
class RPCProxy
     Methods defined here:
__getattr__(self, name)
__init__(self, sockio, oid)

 
class RPCServer(SocketServer.TCPServer)
    
Method resolution order:
RPCServer
SocketServer.TCPServer
SocketServer.BaseServer

Methods defined here:
__init__(self, addr, handlerclass=None)
get_request(self)
Override TCPServer method, return already connected socket
handle_error(self, request, client_address)
Override TCPServer method
 
Error message goes to __stderr__.  No error message if exiting
normally or socket raised EOF.  Other exceptions not handled in
server code will cause os._exit.
server_activate(self)
Override TCPServer method, connect() instead of listen()
 
Due to the reversed connection, self.server_address is actually the
address of the Idle Client to which we are connecting.
server_bind(self)
Override TCPServer method, no bind() phase for connecting entity

Methods inherited from SocketServer.TCPServer:
close_request(self, request)
Called to clean up an individual request.
fileno(self)
Return socket file number.
 
Interface required by select().
server_close(self)
Called to clean-up the server.
 
May be overridden.

Data and other attributes inherited from SocketServer.TCPServer:
address_family = 2
allow_reuse_address = False
request_queue_size = 5
socket_type = 1

Methods inherited from SocketServer.BaseServer:
finish_request(self, request, client_address)
Finish one request by instantiating RequestHandlerClass.
handle_request(self)
Handle one request, possibly blocking.
process_request(self, request, client_address)
Call finish_request.
 
Overridden by ForkingMixIn and ThreadingMixIn.
serve_forever(self)
Handle one request at a time until doomsday.
verify_request(self, request, client_address)
Verify the request.  May be overridden.
 
Return True if we should proceed with this request.

 
class RemoteObject
    

 
class RemoteProxy
     Methods defined here:
__init__(self, oid)

 
class SocketIO
     Methods defined here:
EOFhook(self)
Classes using rpc client/server can override to augment EOF action
__init__(self, sock, objtable=None, debugging=None)
asynccall(self, oid, methodname, args, kwargs)
asyncqueue(self, oid, methodname, args, kwargs)
asyncreturn(self, seq)
close(self)
debug(self, *args)
decode_interrupthook(self)
decoderesponse(self, response)
exithook(self)
override for specific exit action
getresponse(self, myseq, wait)
handle_EOF(self)
action taken upon link being closed by peer
ioready(self, wait)
localcall(self, seq, request)
mainloop(self)
Listen on socket until I/O not ready or EOF
 
pollresponse() will loop looking for seq number None, which
never comes, and exit on EOFError.
newseq(self)
pollmessage(self, wait)
pollpacket(self, wait)
pollresponse(self, myseq, wait)
Handle messages received on the socket.
 
Some messages received may be asynchronous 'call' or 'queue' requests,
and some may be responses for other threads.
 
'call' requests are passed to localcall() with the expectation of
immediate execution, during which time the socket is not serviced.
 
'queue' requests are used for tasks (which may block or hang) to be
processed in a different thread.  These requests are fed into
request_queue by localcall().  Responses to queued requests are
taken from response_queue and sent across the link with the associated
sequence numbers.  Messages in the queues are (sequence_number,
request/response) tuples and code using this module removing messages
from the request_queue is responsible for returning the correct
sequence number in the response_queue.
 
pollresponse() will loop until a response message with the myseq
sequence number is received, and will save other responses in
self.responses and notify the owning thread.
putmessage(self, message)
register(self, oid, object)
remotecall(self, oid, methodname, args, kwargs)
remotequeue(self, oid, methodname, args, kwargs)
unregister(self, oid)

Data and other attributes defined here:
buffer = ''
bufneed = 4
bufstate = 0
nextseq = 0

 
Functions
       
pickle_code(co)
remoteref(obj)
test()
testClient(addr)
demonstrates RPC Client
testServer(addr)
unpickle_code(ms)

 
Data
        BUFSIZE = 8192
LOCALHOST = '127.0.0.1'
objecttable = {}
request_queue = <Queue.Queue instance>
response_queue = <Queue.Queue instance>