Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes
idlelib.PyShell.MyRPCClient Class Reference
Inheritance diagram for idlelib.PyShell.MyRPCClient:
Inheritance graph
[legend]
Collaboration diagram for idlelib.PyShell.MyRPCClient:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def handle_EOF
def accept
def get_remote_proxy
def close
def exithook
def debug
def register
def unregister
def localcall
def remotecall
def remotequeue
def asynccall
def asyncqueue
def asyncreturn
def decoderesponse
def decode_interrupthook
def mainloop
def getresponse
def newseq
def putmessage
def pollpacket
def pollmessage
def pollresponse
def EOFhook

Public Attributes

 listening_sock
 buff
 bufneed
 bufstate
 sockthread
 sock
 objtable
 responses
 cvars
_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type

Static Public Attributes

 debugging = False
string location = "#C"
int nextseq = 1
string buff = ''
int bufneed = 4
int bufstate = 0

Detailed Description

Definition at line 324 of file PyShell.py.


Member Function Documentation

def idlelib.rpc.RPCClient.accept (   self) [inherited]

Definition at line 524 of file rpc.py.

00524 
00525     def accept(self):
00526         working_sock, address = self.listening_sock.accept()
00527         if self.debugging:
00528             print("****** Connection request from ", address, file=sys.__stderr__)
00529         if address[0] == LOCALHOST:
00530             SocketIO.__init__(self, working_sock)
00531         else:
00532             print("** Invalid host: ", address, file=sys.__stderr__)
00533             raise socket.error

def idlelib.rpc.SocketIO.asynccall (   self,
  oid,
  methodname,
  args,
  kwargs 
) [inherited]

Definition at line 218 of file rpc.py.

00218 
00219     def asynccall(self, oid, methodname, args, kwargs):
00220         request = ("CALL", (oid, methodname, args, kwargs))
00221         seq = self.newseq()
00222         if threading.current_thread() != self.sockthread:
00223             cvar = threading.Condition()
00224             self.cvars[seq] = cvar
00225         self.debug(("asynccall:%d:" % seq), oid, methodname, args, kwargs)
00226         self.putmessage((seq, request))
00227         return seq

Here is the call graph for this function:

Here is the caller graph for this function:

def idlelib.rpc.SocketIO.asyncqueue (   self,
  oid,
  methodname,
  args,
  kwargs 
) [inherited]

Definition at line 228 of file rpc.py.

00228 
00229     def asyncqueue(self, oid, methodname, args, kwargs):
00230         request = ("QUEUE", (oid, methodname, args, kwargs))
00231         seq = self.newseq()
00232         if threading.current_thread() != self.sockthread:
00233             cvar = threading.Condition()
00234             self.cvars[seq] = cvar
00235         self.debug(("asyncqueue:%d:" % seq), oid, methodname, args, kwargs)
00236         self.putmessage((seq, request))
00237         return seq

Here is the call graph for this function:

Here is the caller graph for this function:

def idlelib.rpc.SocketIO.asyncreturn (   self,
  seq 
) [inherited]

Definition at line 238 of file rpc.py.

00238 
00239     def asyncreturn(self, seq):
00240         self.debug("asyncreturn:%d:call getresponse(): " % seq)
00241         response = self.getresponse(seq, wait=0.05)
00242         self.debug(("asyncreturn:%d:response: " % seq), response)
00243         return self.decoderesponse(response)

Here is the call graph for this function:

Here is the caller graph for this function:

def idlelib.rpc.SocketIO.close (   self) [inherited]

Definition at line 139 of file rpc.py.

00139 
00140     def close(self):
00141         sock = self.sock
00142         self.sock = None
00143         if sock is not None:
00144             sock.close()

Here is the caller graph for this function:

def idlelib.rpc.SocketIO.debug (   self,
  args 
) [inherited]

Definition at line 149 of file rpc.py.

00149 
00150     def debug(self, *args):
00151         if not self.debugging:
00152             return
00153         s = self.location + " " + str(threading.current_thread().name)
00154         for a in args:
00155             s = s + " " + str(a)
00156         print(s, file=sys.__stderr__)

Here is the call graph for this function:

Here is the caller graph for this function:

def idlelib.rpc.SocketIO.decode_interrupthook (   self) [inherited]

Reimplemented in idlelib.run.MyHandler.

Definition at line 262 of file rpc.py.

00262 
00263     def decode_interrupthook(self):
00264         ""
00265         raise EOFError

Here is the caller graph for this function:

def idlelib.rpc.SocketIO.decoderesponse (   self,
  response 
) [inherited]

Definition at line 244 of file rpc.py.

00244 
00245     def decoderesponse(self, response):
00246         how, what = response
00247         if how == "OK":
00248             return what
00249         if how == "QUEUED":
00250             return None
00251         if how == "EXCEPTION":
00252             self.debug("decoderesponse: EXCEPTION")
00253             return None
00254         if how == "EOF":
00255             self.debug("decoderesponse: EOF")
00256             self.decode_interrupthook()
00257             return None
00258         if how == "ERROR":
00259             self.debug("decoderesponse: Internal ERROR:", what)
00260             raise RuntimeError(what)
00261         raise SystemError(how, what)

Here is the call graph for this function:

Here is the caller graph for this function:

def idlelib.rpc.SocketIO.EOFhook (   self) [inherited]

Reimplemented in idlelib.run.MyHandler.

Definition at line 475 of file rpc.py.

00475 
00476     def EOFhook(self):
00477         "Classes using rpc client/server can override to augment EOF action"
00478         pass
00479 
00480 #----------------- end class SocketIO --------------------

Here is the caller graph for this function:

def idlelib.rpc.SocketIO.exithook (   self) [inherited]

Reimplemented in idlelib.run.MyHandler.

Definition at line 145 of file rpc.py.

00145 
00146     def exithook(self):
00147         "override for specific exit action"
00148         os._exit()

Here is the caller graph for this function:

def idlelib.rpc.RPCClient.get_remote_proxy (   self,
  oid 
) [inherited]

Definition at line 534 of file rpc.py.

00534 
00535     def get_remote_proxy(self, oid):
00536         return RPCProxy(self, oid)

def idlelib.rpc.SocketIO.getresponse (   self,
  myseq,
  wait 
) [inherited]

Definition at line 279 of file rpc.py.

00279 
00280     def getresponse(self, myseq, wait):
00281         response = self._getresponse(myseq, wait)
00282         if response is not None:
00283             how, what = response
00284             if how == "OK":
00285                 response = how, self._proxify(what)
00286         return response

Here is the call graph for this function:

Here is the caller graph for this function:

Reimplemented from idlelib.rpc.SocketIO.

Definition at line 326 of file PyShell.py.

00326 
00327     def handle_EOF(self):
00328         "Override the base class - just re-raise EOFError"
00329         raise EOFError
00330 

Here is the caller graph for this function:

def idlelib.rpc.SocketIO.localcall (   self,
  seq,
  request 
) [inherited]

Definition at line 166 of file rpc.py.

00166 
00167     def localcall(self, seq, request):
00168         self.debug("localcall:", request)
00169         try:
00170             how, (oid, methodname, args, kwargs) = request
00171         except TypeError:
00172             return ("ERROR", "Bad request format")
00173         if oid not in self.objtable:
00174             return ("ERROR", "Unknown object id: %r" % (oid,))
00175         obj = self.objtable[oid]
00176         if methodname == "__methods__":
00177             methods = {}
00178             _getmethods(obj, methods)
00179             return ("OK", methods)
00180         if methodname == "__attributes__":
00181             attributes = {}
00182             _getattributes(obj, attributes)
00183             return ("OK", attributes)
00184         if not hasattr(obj, methodname):
00185             return ("ERROR", "Unsupported method name: %r" % (methodname,))
00186         method = getattr(obj, methodname)
00187         try:
00188             if how == 'CALL':
00189                 ret = method(*args, **kwargs)
00190                 if isinstance(ret, RemoteObject):
00191                     ret = remoteref(ret)
00192                 return ("OK", ret)
00193             elif how == 'QUEUE':
00194                 request_queue.put((seq, (method, args, kwargs)))
00195                 return("QUEUED", None)
00196             else:
00197                 return ("ERROR", "Unsupported message type: %s" % how)
00198         except SystemExit:
00199             raise
00200         except socket.error:
00201             raise
00202         except:
00203             msg = "*** Internal Error: rpc.py:SocketIO.localcall()\n\n"\
00204                   " Object: %s \n Method: %s \n Args: %s\n"
00205             print(msg % (oid, method, args), file=sys.__stderr__)
00206             traceback.print_exc(file=sys.__stderr__)
00207             return ("EXCEPTION", None)

Here is the call graph for this function:

Here is the caller graph for this function:

def idlelib.rpc.SocketIO.mainloop (   self) [inherited]
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.

Definition at line 266 of file rpc.py.

00266 
00267     def mainloop(self):
00268         """Listen on socket until I/O not ready or EOF
00269 
00270         pollresponse() will loop looking for seq number None, which
00271         never comes, and exit on EOFError.
00272 
00273         """
00274         try:
00275             self.getresponse(myseq=None, wait=0.05)
00276         except EOFError:
00277             self.debug("mainloop:return")
00278             return

Here is the call graph for this function:

Here is the caller graph for this function:

def idlelib.rpc.SocketIO.newseq (   self) [inherited]

Definition at line 317 of file rpc.py.

00317 
00318     def newseq(self):
00319         self.nextseq = seq = self.nextseq + 2
00320         return seq

Here is the caller graph for this function:

def idlelib.rpc.SocketIO.pollmessage (   self,
  wait 
) [inherited]

Definition at line 375 of file rpc.py.

00375 
00376     def pollmessage(self, wait):
00377         packet = self.pollpacket(wait)
00378         if packet is None:
00379             return None
00380         try:
00381             message = pickle.loads(packet)
00382         except pickle.UnpicklingError:
00383             print("-----------------------", file=sys.__stderr__)
00384             print("cannot unpickle packet:", repr(packet), file=sys.__stderr__)
00385             traceback.print_stack(file=sys.__stderr__)
00386             print("-----------------------", file=sys.__stderr__)
00387             raise
00388         return message

Here is the call graph for this function:

Here is the caller graph for this function:

def idlelib.rpc.SocketIO.pollpacket (   self,
  wait 
) [inherited]

Definition at line 344 of file rpc.py.

00344 
00345     def pollpacket(self, wait):
00346         self._stage0()
00347         if len(self.buff) < self.bufneed:
00348             r, w, x = select.select([self.sock.fileno()], [], [], wait)
00349             if len(r) == 0:
00350                 return None
00351             try:
00352                 s = self.sock.recv(BUFSIZE)
00353             except socket.error:
00354                 raise EOFError
00355             if len(s) == 0:
00356                 raise EOFError
00357             self.buff += s
00358             self._stage0()
00359         return self._stage1()

Here is the call graph for this function:

Here is the caller graph for this function:

def idlelib.rpc.SocketIO.pollresponse (   self,
  myseq,
  wait 
) [inherited]
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 self.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 self.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.

Definition at line 389 of file rpc.py.

00389 
00390     def pollresponse(self, myseq, wait):
00391         """Handle messages received on the socket.
00392 
00393         Some messages received may be asynchronous 'call' or 'queue' requests,
00394         and some may be responses for other threads.
00395 
00396         'call' requests are passed to self.localcall() with the expectation of
00397         immediate execution, during which time the socket is not serviced.
00398 
00399         'queue' requests are used for tasks (which may block or hang) to be
00400         processed in a different thread.  These requests are fed into
00401         request_queue by self.localcall().  Responses to queued requests are
00402         taken from response_queue and sent across the link with the associated
00403         sequence numbers.  Messages in the queues are (sequence_number,
00404         request/response) tuples and code using this module removing messages
00405         from the request_queue is responsible for returning the correct
00406         sequence number in the response_queue.
00407 
00408         pollresponse() will loop until a response message with the myseq
00409         sequence number is received, and will save other responses in
00410         self.responses and notify the owning thread.
00411 
00412         """
00413         while 1:
00414             # send queued response if there is one available
00415             try:
00416                 qmsg = response_queue.get(0)
00417             except queue.Empty:
00418                 pass
00419             else:
00420                 seq, response = qmsg
00421                 message = (seq, ('OK', response))
00422                 self.putmessage(message)
00423             # poll for message on link
00424             try:
00425                 message = self.pollmessage(wait)
00426                 if message is None:  # socket not ready
00427                     return None
00428             except EOFError:
00429                 self.handle_EOF()
00430                 return None
00431             except AttributeError:
00432                 return None
00433             seq, resq = message
00434             how = resq[0]
00435             self.debug("pollresponse:%d:myseq:%s" % (seq, myseq))
00436             # process or queue a request
00437             if how in ("CALL", "QUEUE"):
00438                 self.debug("pollresponse:%d:localcall:call:" % seq)
00439                 response = self.localcall(seq, resq)
00440                 self.debug("pollresponse:%d:localcall:response:%s"
00441                            % (seq, response))
00442                 if how == "CALL":
00443                     self.putmessage((seq, response))
00444                 elif how == "QUEUE":
00445                     # don't acknowledge the 'queue' request!
00446                     pass
00447                 continue
00448             # return if completed message transaction
00449             elif seq == myseq:
00450                 return resq
00451             # must be a response for a different thread:
00452             else:
00453                 cv = self.cvars.get(seq, None)
00454                 # response involving unknown sequence number is discarded,
00455                 # probably intended for prior incarnation of server
00456                 if cv is not None:
00457                     cv.acquire()
00458                     self.responses[seq] = resq
00459                     cv.notify()
00460                     cv.release()
00461                 continue

Here is the call graph for this function:

Here is the caller graph for this function:

def idlelib.rpc.SocketIO.putmessage (   self,
  message 
) [inherited]

Definition at line 321 of file rpc.py.

00321 
00322     def putmessage(self, message):
00323         self.debug("putmessage:%d:" % message[0])
00324         try:
00325             s = pickle.dumps(message)
00326         except pickle.PicklingError:
00327             print("Cannot pickle:", repr(message), file=sys.__stderr__)
00328             raise
00329         s = struct.pack("<i", len(s)) + s
00330         while len(s) > 0:
00331             try:
00332                 r, w, x = select.select([], [self.sock], [])
00333                 n = self.sock.send(s[:BUFSIZE])
00334             except (AttributeError, TypeError):
00335                 raise IOError("socket no longer exists")
00336             except socket.error:
00337                 raise
00338             else:
00339                 s = s[n:]

Here is the call graph for this function:

Here is the caller graph for this function:

def idlelib.rpc.SocketIO.register (   self,
  oid,
  object 
) [inherited]

Definition at line 157 of file rpc.py.

00157 
00158     def register(self, oid, object):
00159         self.objtable[oid] = object

Here is the caller graph for this function:

def idlelib.rpc.SocketIO.remotecall (   self,
  oid,
  methodname,
  args,
  kwargs 
) [inherited]

Definition at line 208 of file rpc.py.

00208 
00209     def remotecall(self, oid, methodname, args, kwargs):
00210         self.debug("remotecall:asynccall: ", oid, methodname)
00211         seq = self.asynccall(oid, methodname, args, kwargs)
00212         return self.asyncreturn(seq)

Here is the call graph for this function:

def idlelib.rpc.SocketIO.remotequeue (   self,
  oid,
  methodname,
  args,
  kwargs 
) [inherited]

Definition at line 213 of file rpc.py.

00213 
00214     def remotequeue(self, oid, methodname, args, kwargs):
00215         self.debug("remotequeue:asyncqueue: ", oid, methodname)
00216         seq = self.asyncqueue(oid, methodname, args, kwargs)
00217         return self.asyncreturn(seq)

Here is the call graph for this function:

def idlelib.rpc.SocketIO.unregister (   self,
  oid 
) [inherited]

Definition at line 160 of file rpc.py.

00160 
00161     def unregister(self, oid):
00162         try:
00163             del self.objtable[oid]
00164         except KeyError:
00165             pass

Here is the caller graph for this function:


Member Data Documentation

string idlelib.rpc.SocketIO.buff = '' [static, inherited]

Definition at line 340 of file rpc.py.

Definition at line 363 of file rpc.py.

int idlelib.rpc.SocketIO.bufneed = 4 [static, inherited]

Definition at line 341 of file rpc.py.

Definition at line 364 of file rpc.py.

int idlelib.rpc.SocketIO.bufstate = 0 [static, inherited]

Definition at line 342 of file rpc.py.

Definition at line 361 of file rpc.py.

Definition at line 137 of file rpc.py.

idlelib.rpc.RPCClient.debugging = False [static, inherited]

Reimplemented from idlelib.rpc.SocketIO.

Definition at line 514 of file rpc.py.

Definition at line 520 of file rpc.py.

string idlelib.rpc.RPCClient.location = "#C" [static, inherited]

Definition at line 515 of file rpc.py.

int idlelib.rpc.RPCClient.nextseq = 1 [static, inherited]

Reimplemented from idlelib.rpc.SocketIO.

Definition at line 517 of file rpc.py.

Definition at line 107 of file object.h.

struct _typeobject* _object::ob_type [inherited]

Definition at line 108 of file object.h.

Definition at line 135 of file rpc.py.

Definition at line 136 of file rpc.py.

Definition at line 132 of file rpc.py.

Definition at line 129 of file rpc.py.


The documentation for this class was generated from the following file: