Linux ip-148-66-134-25.ip.secureserver.net 3.10.0-1160.119.1.el7.tuxcare.els10.x86_64 #1 SMP Fri Oct 11 21:40:41 UTC 2024 x86_64
Apache
: 148.66.134.25 | : 18.119.105.155
66 Domain
8.0.30
amvm
www.github.com/MadExploits
Terminal
AUTO ROOT
Adminer
Backdoor Destroyer
Linux Exploit
Lock Shell
Lock File
Create User
CREATE RDP
PHP Mailer
BACKCONNECT
UNLOCK SHELL
HASH IDENTIFIER
CPANEL RESET
BLACK DEFEND!
README
+ Create Folder
+ Create File
/
usr /
lib64 /
python2.7 /
idlelib /
[ HOME SHELL ]
Name
Size
Permission
Action
Icons
[ DIR ]
drwxr-xr-x
AutoComplete.py
8.79
KB
-rw-r--r--
AutoComplete.pyc
7.69
KB
-rw-r--r--
AutoComplete.pyo
7.69
KB
-rw-r--r--
AutoCompleteWindow.py
16.8
KB
-rw-r--r--
AutoCompleteWindow.pyc
12.15
KB
-rw-r--r--
AutoCompleteWindow.pyo
12.09
KB
-rw-r--r--
AutoExpand.py
2.42
KB
-rw-r--r--
AutoExpand.pyc
2.5
KB
-rw-r--r--
AutoExpand.pyo
2.5
KB
-rw-r--r--
Bindings.py
3.22
KB
-rw-r--r--
Bindings.pyc
4.76
KB
-rw-r--r--
Bindings.pyo
4.76
KB
-rw-r--r--
CREDITS.txt
1.82
KB
-rw-r--r--
CallTipWindow.py
5.98
KB
-rw-r--r--
CallTipWindow.pyc
6.14
KB
-rw-r--r--
CallTipWindow.pyo
6.14
KB
-rw-r--r--
CallTips.py
7.75
KB
-rw-r--r--
CallTips.pyc
10.14
KB
-rw-r--r--
CallTips.pyo
10.14
KB
-rw-r--r--
ChangeLog
55.07
KB
-rw-r--r--
ClassBrowser.py
6.22
KB
-rw-r--r--
ClassBrowser.pyc
8.95
KB
-rw-r--r--
ClassBrowser.pyo
8.95
KB
-rw-r--r--
CodeContext.py
8.15
KB
-rw-r--r--
CodeContext.pyc
6.52
KB
-rw-r--r--
CodeContext.pyo
6.47
KB
-rw-r--r--
ColorDelegator.py
10.13
KB
-rw-r--r--
ColorDelegator.pyc
8.71
KB
-rw-r--r--
ColorDelegator.pyo
8.71
KB
-rw-r--r--
Debugger.py
15.45
KB
-rw-r--r--
Debugger.pyc
16.55
KB
-rw-r--r--
Debugger.pyo
16.55
KB
-rw-r--r--
Delegator.py
831
B
-rw-r--r--
Delegator.pyc
1.58
KB
-rw-r--r--
Delegator.pyo
1.58
KB
-rw-r--r--
EditorWindow.py
63.29
KB
-rw-r--r--
EditorWindow.pyc
55.13
KB
-rw-r--r--
EditorWindow.pyo
55.03
KB
-rw-r--r--
FileList.py
3.57
KB
-rw-r--r--
FileList.pyc
3.86
KB
-rw-r--r--
FileList.pyo
3.82
KB
-rw-r--r--
FormatParagraph.py
5.66
KB
-rw-r--r--
FormatParagraph.pyc
4.69
KB
-rw-r--r--
FormatParagraph.pyo
4.69
KB
-rw-r--r--
GrepDialog.py
3.96
KB
-rw-r--r--
GrepDialog.pyc
4.9
KB
-rw-r--r--
GrepDialog.pyo
4.9
KB
-rw-r--r--
HISTORY.txt
10.08
KB
-rw-r--r--
HyperParser.py
10.31
KB
-rw-r--r--
HyperParser.pyc
6.49
KB
-rw-r--r--
HyperParser.pyo
6.49
KB
-rw-r--r--
IOBinding.py
20.69
KB
-rw-r--r--
IOBinding.pyc
17.16
KB
-rw-r--r--
IOBinding.pyo
17.16
KB
-rw-r--r--
IdleHistory.py
3.07
KB
-rw-r--r--
IdleHistory.pyc
3.13
KB
-rw-r--r--
IdleHistory.pyo
3.13
KB
-rw-r--r--
MultiCall.py
17.07
KB
-rw-r--r--
MultiCall.pyc
15.55
KB
-rw-r--r--
MultiCall.pyo
15.48
KB
-rw-r--r--
MultiStatusBar.py
783
B
-rw-r--r--
MultiStatusBar.pyc
1.49
KB
-rw-r--r--
MultiStatusBar.pyo
1.49
KB
-rw-r--r--
NEWS.txt
28.32
KB
-rw-r--r--
ObjectBrowser.py
4.05
KB
-rw-r--r--
ObjectBrowser.pyc
6.56
KB
-rw-r--r--
ObjectBrowser.pyo
6.56
KB
-rw-r--r--
OutputWindow.py
4.47
KB
-rw-r--r--
OutputWindow.pyc
5.11
KB
-rw-r--r--
OutputWindow.pyo
5.11
KB
-rw-r--r--
ParenMatch.py
6.47
KB
-rw-r--r--
ParenMatch.pyc
6.82
KB
-rw-r--r--
ParenMatch.pyo
6.82
KB
-rw-r--r--
PathBrowser.py
2.58
KB
-rw-r--r--
PathBrowser.pyc
4.02
KB
-rw-r--r--
PathBrowser.pyo
4.02
KB
-rw-r--r--
Percolator.py
2.55
KB
-rw-r--r--
Percolator.pyc
3.55
KB
-rw-r--r--
Percolator.pyo
3.37
KB
-rw-r--r--
PyParse.py
19.05
KB
-rw-r--r--
PyParse.pyc
9.77
KB
-rw-r--r--
PyParse.pyo
9.34
KB
-rw-r--r--
PyShell.py
54.81
KB
-rw-r--r--
PyShell.pyc
49.14
KB
-rw-r--r--
PyShell.pyo
49.04
KB
-rw-r--r--
README.txt
2.56
KB
-rw-r--r--
RemoteDebugger.py
11.38
KB
-rw-r--r--
RemoteDebugger.pyc
15.97
KB
-rw-r--r--
RemoteDebugger.pyo
15.82
KB
-rw-r--r--
RemoteObjectBrowser.py
942
B
-rw-r--r--
RemoteObjectBrowser.pyc
2.1
KB
-rw-r--r--
RemoteObjectBrowser.pyo
2.1
KB
-rw-r--r--
ReplaceDialog.py
5.69
KB
-rw-r--r--
ReplaceDialog.pyc
6.32
KB
-rw-r--r--
ReplaceDialog.pyo
6.32
KB
-rw-r--r--
RstripExtension.py
824
B
-rw-r--r--
RstripExtension.pyc
1.45
KB
-rw-r--r--
RstripExtension.pyo
1.45
KB
-rw-r--r--
ScriptBinding.py
8.22
KB
-rw-r--r--
ScriptBinding.pyc
7.96
KB
-rw-r--r--
ScriptBinding.pyo
7.96
KB
-rw-r--r--
ScrolledList.py
3.9
KB
-rw-r--r--
ScrolledList.pyc
6.03
KB
-rw-r--r--
ScrolledList.pyo
6.03
KB
-rw-r--r--
SearchDialog.py
1.99
KB
-rw-r--r--
SearchDialog.pyc
2.93
KB
-rw-r--r--
SearchDialog.pyo
2.93
KB
-rw-r--r--
SearchDialogBase.py
4.28
KB
-rw-r--r--
SearchDialogBase.pyc
5.37
KB
-rw-r--r--
SearchDialogBase.pyo
5.37
KB
-rw-r--r--
SearchEngine.py
6.57
KB
-rw-r--r--
SearchEngine.pyc
7.02
KB
-rw-r--r--
SearchEngine.pyo
7.02
KB
-rw-r--r--
StackViewer.py
3.77
KB
-rw-r--r--
StackViewer.pyc
5.79
KB
-rw-r--r--
StackViewer.pyo
5.79
KB
-rw-r--r--
TODO.txt
8.28
KB
-rw-r--r--
ToolTip.py
2.67
KB
-rw-r--r--
ToolTip.pyc
4.05
KB
-rw-r--r--
ToolTip.pyo
4.05
KB
-rw-r--r--
TreeWidget.py
14.87
KB
-rw-r--r--
TreeWidget.pyc
17.48
KB
-rw-r--r--
TreeWidget.pyo
17.48
KB
-rw-r--r--
UndoDelegator.py
10.04
KB
-rw-r--r--
UndoDelegator.pyc
12.27
KB
-rw-r--r--
UndoDelegator.pyo
12.27
KB
-rw-r--r--
WidgetRedirector.py
4.37
KB
-rw-r--r--
WidgetRedirector.pyc
5.23
KB
-rw-r--r--
WidgetRedirector.pyo
5.23
KB
-rw-r--r--
WindowList.py
2.42
KB
-rw-r--r--
WindowList.pyc
3.55
KB
-rw-r--r--
WindowList.pyo
3.55
KB
-rw-r--r--
ZoomHeight.py
1.28
KB
-rw-r--r--
ZoomHeight.pyc
1.61
KB
-rw-r--r--
ZoomHeight.pyo
1.61
KB
-rw-r--r--
__init__.py
37
B
-rw-r--r--
__init__.pyc
127
B
-rw-r--r--
__init__.pyo
127
B
-rw-r--r--
aboutDialog.py
6.42
KB
-rw-r--r--
aboutDialog.pyc
6.63
KB
-rw-r--r--
aboutDialog.pyo
6.63
KB
-rw-r--r--
config-extensions.def
2.72
KB
-rw-r--r--
config-highlight.def
1.7
KB
-rw-r--r--
config-keys.def
7.35
KB
-rw-r--r--
config-main.def
2.45
KB
-rw-r--r--
configDialog.py
52.23
KB
-rw-r--r--
configDialog.pyc
43.81
KB
-rw-r--r--
configDialog.pyo
43.81
KB
-rw-r--r--
configHandler.py
28.68
KB
-rw-r--r--
configHandler.pyc
26.83
KB
-rw-r--r--
configHandler.pyo
26.83
KB
-rw-r--r--
configHelpSourceEdit.py
6.52
KB
-rw-r--r--
configHelpSourceEdit.pyc
6.56
KB
-rw-r--r--
configHelpSourceEdit.pyo
6.56
KB
-rw-r--r--
configSectionNameDialog.py
3.63
KB
-rw-r--r--
configSectionNameDialog.pyc
4.21
KB
-rw-r--r--
configSectionNameDialog.pyo
4.21
KB
-rw-r--r--
dynOptionMenuWidget.py
1.27
KB
-rw-r--r--
dynOptionMenuWidget.pyc
1.66
KB
-rw-r--r--
dynOptionMenuWidget.pyo
1.66
KB
-rw-r--r--
extend.txt
3.56
KB
-rw-r--r--
help.txt
11.72
KB
-rw-r--r--
idle.py
400
B
-rw-r--r--
idle.pyc
406
B
-rw-r--r--
idle.pyo
406
B
-rw-r--r--
idle.pyw
664
B
-rw-r--r--
idlever.py
23
B
-rw-r--r--
idlever.pyc
159
B
-rw-r--r--
idlever.pyo
159
B
-rw-r--r--
keybindingDialog.py
12.12
KB
-rw-r--r--
keybindingDialog.pyc
12.05
KB
-rw-r--r--
keybindingDialog.pyo
12.05
KB
-rw-r--r--
macosxSupport.py
6.08
KB
-rw-r--r--
macosxSupport.pyc
6.25
KB
-rw-r--r--
macosxSupport.pyo
6.25
KB
-rw-r--r--
rpc.py
19.75
KB
-rw-r--r--
rpc.pyc
21.26
KB
-rw-r--r--
rpc.pyo
21.16
KB
-rw-r--r--
run.py
11.54
KB
-rw-r--r--
run.pyc
12.14
KB
-rw-r--r--
run.pyo
12.08
KB
-rw-r--r--
tabbedpages.py
17.76
KB
-rw-r--r--
tabbedpages.pyc
17.67
KB
-rw-r--r--
tabbedpages.pyo
17.67
KB
-rw-r--r--
textView.py
3.46
KB
-rw-r--r--
textView.pyc
4.2
KB
-rw-r--r--
textView.pyo
4.2
KB
-rw-r--r--
Delete
Unzip
Zip
${this.title}
Close
Code Editor : 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 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. """ import sys import os import socket import select import SocketServer import struct import cPickle as pickle import threading import Queue import traceback import copy_reg import types import marshal def unpickle_code(ms): co = marshal.loads(ms) assert isinstance(co, types.CodeType) return co def pickle_code(co): assert isinstance(co, types.CodeType) ms = marshal.dumps(co) return unpickle_code, (ms,) # XXX KBK 24Aug02 function pickling capability not used in Idle # def unpickle_function(ms): # return ms # def pickle_function(fn): # assert isinstance(fn, type.FunctionType) # return repr(fn) copy_reg.pickle(types.CodeType, pickle_code, unpickle_code) # copy_reg.pickle(types.FunctionType, pickle_function, unpickle_function) BUFSIZE = 8*1024 LOCALHOST = '127.0.0.1' class RPCServer(SocketServer.TCPServer): def __init__(self, addr, handlerclass=None): if handlerclass is None: handlerclass = RPCHandler SocketServer.TCPServer.__init__(self, addr, handlerclass) def server_bind(self): "Override TCPServer method, no bind() phase for connecting entity" pass def 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. """ self.socket.connect(self.server_address) def get_request(self): "Override TCPServer method, return already connected socket" return self.socket, self.server_address def 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. """ try: raise except SystemExit: raise except: erf = sys.__stderr__ print>>erf, '\n' + '-'*40 print>>erf, 'Unhandled server exception!' print>>erf, 'Thread: %s' % threading.currentThread().getName() print>>erf, 'Client Address: ', client_address print>>erf, 'Request: ', repr(request) traceback.print_exc(file=erf) print>>erf, '\n*** Unrecoverable, server exiting!' print>>erf, '-'*40 os._exit(0) #----------------- end class RPCServer -------------------- objecttable = {} request_queue = Queue.Queue(0) response_queue = Queue.Queue(0) class SocketIO(object): nextseq = 0 def __init__(self, sock, objtable=None, debugging=None): self.sockthread = threading.currentThread() if debugging is not None: self.debugging = debugging self.sock = sock if objtable is None: objtable = objecttable self.objtable = objtable self.responses = {} self.cvars = {} def close(self): sock = self.sock self.sock = None if sock is not None: sock.close() def exithook(self): "override for specific exit action" os._exit(0) def debug(self, *args): if not self.debugging: return s = self.location + " " + str(threading.currentThread().getName()) for a in args: s = s + " " + str(a) print>>sys.__stderr__, s def register(self, oid, object): self.objtable[oid] = object def unregister(self, oid): try: del self.objtable[oid] except KeyError: pass def localcall(self, seq, request): self.debug("localcall:", request) try: how, (oid, methodname, args, kwargs) = request except TypeError: return ("ERROR", "Bad request format") if oid not in self.objtable: return ("ERROR", "Unknown object id: %r" % (oid,)) obj = self.objtable[oid] if methodname == "__methods__": methods = {} _getmethods(obj, methods) return ("OK", methods) if methodname == "__attributes__": attributes = {} _getattributes(obj, attributes) return ("OK", attributes) if not hasattr(obj, methodname): return ("ERROR", "Unsupported method name: %r" % (methodname,)) method = getattr(obj, methodname) try: if how == 'CALL': ret = method(*args, **kwargs) if isinstance(ret, RemoteObject): ret = remoteref(ret) return ("OK", ret) elif how == 'QUEUE': request_queue.put((seq, (method, args, kwargs))) return("QUEUED", None) else: return ("ERROR", "Unsupported message type: %s" % how) except SystemExit: raise except socket.error: raise except: msg = "*** Internal Error: rpc.py:SocketIO.localcall()\n\n"\ " Object: %s \n Method: %s \n Args: %s\n" print>>sys.__stderr__, msg % (oid, method, args) traceback.print_exc(file=sys.__stderr__) return ("EXCEPTION", None) def remotecall(self, oid, methodname, args, kwargs): self.debug("remotecall:asynccall: ", oid, methodname) seq = self.asynccall(oid, methodname, args, kwargs) return self.asyncreturn(seq) def remotequeue(self, oid, methodname, args, kwargs): self.debug("remotequeue:asyncqueue: ", oid, methodname) seq = self.asyncqueue(oid, methodname, args, kwargs) return self.asyncreturn(seq) def asynccall(self, oid, methodname, args, kwargs): request = ("CALL", (oid, methodname, args, kwargs)) seq = self.newseq() if threading.currentThread() != self.sockthread: cvar = threading.Condition() self.cvars[seq] = cvar self.debug(("asynccall:%d:" % seq), oid, methodname, args, kwargs) self.putmessage((seq, request)) return seq def asyncqueue(self, oid, methodname, args, kwargs): request = ("QUEUE", (oid, methodname, args, kwargs)) seq = self.newseq() if threading.currentThread() != self.sockthread: cvar = threading.Condition() self.cvars[seq] = cvar self.debug(("asyncqueue:%d:" % seq), oid, methodname, args, kwargs) self.putmessage((seq, request)) return seq def asyncreturn(self, seq): self.debug("asyncreturn:%d:call getresponse(): " % seq) response = self.getresponse(seq, wait=0.05) self.debug(("asyncreturn:%d:response: " % seq), response) return self.decoderesponse(response) def decoderesponse(self, response): how, what = response if how == "OK": return what if how == "QUEUED": return None if how == "EXCEPTION": self.debug("decoderesponse: EXCEPTION") return None if how == "EOF": self.debug("decoderesponse: EOF") self.decode_interrupthook() return None if how == "ERROR": self.debug("decoderesponse: Internal ERROR:", what) raise RuntimeError, what raise SystemError, (how, what) def decode_interrupthook(self): "" raise EOFError def 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. """ try: self.getresponse(myseq=None, wait=0.05) except EOFError: self.debug("mainloop:return") return def getresponse(self, myseq, wait): response = self._getresponse(myseq, wait) if response is not None: how, what = response if how == "OK": response = how, self._proxify(what) return response def _proxify(self, obj): if isinstance(obj, RemoteProxy): return RPCProxy(self, obj.oid) if isinstance(obj, types.ListType): return map(self._proxify, obj) # XXX Check for other types -- not currently needed return obj def _getresponse(self, myseq, wait): self.debug("_getresponse:myseq:", myseq) if threading.currentThread() is self.sockthread: # this thread does all reading of requests or responses while 1: response = self.pollresponse(myseq, wait) if response is not None: return response else: # wait for notification from socket handling thread cvar = self.cvars[myseq] cvar.acquire() while myseq not in self.responses: cvar.wait() response = self.responses[myseq] self.debug("_getresponse:%s: thread woke up: response: %s" % (myseq, response)) del self.responses[myseq] del self.cvars[myseq] cvar.release() return response def newseq(self): self.nextseq = seq = self.nextseq + 2 return seq def putmessage(self, message): self.debug("putmessage:%d:" % message[0]) try: s = pickle.dumps(message) except pickle.PicklingError: print >>sys.__stderr__, "Cannot pickle:", repr(message) raise s = struct.pack("<i", len(s)) + s while len(s) > 0: try: r, w, x = select.select([], [self.sock], []) n = self.sock.send(s[:BUFSIZE]) except (AttributeError, TypeError): raise IOError, "socket no longer exists" except socket.error: raise else: s = s[n:] buffer = "" bufneed = 4 bufstate = 0 # meaning: 0 => reading count; 1 => reading data def pollpacket(self, wait): self._stage0() if len(self.buffer) < self.bufneed: r, w, x = select.select([self.sock.fileno()], [], [], wait) if len(r) == 0: return None try: s = self.sock.recv(BUFSIZE) except socket.error: raise EOFError if len(s) == 0: raise EOFError self.buffer += s self._stage0() return self._stage1() def _stage0(self): if self.bufstate == 0 and len(self.buffer) >= 4: s = self.buffer[:4] self.buffer = self.buffer[4:] self.bufneed = struct.unpack("<i", s)[0] self.bufstate = 1 def _stage1(self): if self.bufstate == 1 and len(self.buffer) >= self.bufneed: packet = self.buffer[:self.bufneed] self.buffer = self.buffer[self.bufneed:] self.bufneed = 4 self.bufstate = 0 return packet def pollmessage(self, wait): packet = self.pollpacket(wait) if packet is None: return None try: message = pickle.loads(packet) except pickle.UnpicklingError: print >>sys.__stderr__, "-----------------------" print >>sys.__stderr__, "cannot unpickle packet:", repr(packet) traceback.print_stack(file=sys.__stderr__) print >>sys.__stderr__, "-----------------------" raise return message def 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 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. """ while 1: # send queued response if there is one available try: qmsg = response_queue.get(0) except Queue.Empty: pass else: seq, response = qmsg message = (seq, ('OK', response)) self.putmessage(message) # poll for message on link try: message = self.pollmessage(wait) if message is None: # socket not ready return None except EOFError: self.handle_EOF() return None except AttributeError: return None seq, resq = message how = resq[0] self.debug("pollresponse:%d:myseq:%s" % (seq, myseq)) # process or queue a request if how in ("CALL", "QUEUE"): self.debug("pollresponse:%d:localcall:call:" % seq) response = self.localcall(seq, resq) self.debug("pollresponse:%d:localcall:response:%s" % (seq, response)) if how == "CALL": self.putmessage((seq, response)) elif how == "QUEUE": # don't acknowledge the 'queue' request! pass continue # return if completed message transaction elif seq == myseq: return resq # must be a response for a different thread: else: cv = self.cvars.get(seq, None) # response involving unknown sequence number is discarded, # probably intended for prior incarnation of server if cv is not None: cv.acquire() self.responses[seq] = resq cv.notify() cv.release() continue def handle_EOF(self): "action taken upon link being closed by peer" self.EOFhook() self.debug("handle_EOF") for key in self.cvars: cv = self.cvars[key] cv.acquire() self.responses[key] = ('EOF', None) cv.notify() cv.release() # call our (possibly overridden) exit function self.exithook() def EOFhook(self): "Classes using rpc client/server can override to augment EOF action" pass #----------------- end class SocketIO -------------------- class RemoteObject(object): # Token mix-in class pass def remoteref(obj): oid = id(obj) objecttable[oid] = obj return RemoteProxy(oid) class RemoteProxy(object): def __init__(self, oid): self.oid = oid class RPCHandler(SocketServer.BaseRequestHandler, SocketIO): debugging = False location = "#S" # Server def __init__(self, sock, addr, svr): svr.current_handler = self ## cgt xxx SocketIO.__init__(self, sock) SocketServer.BaseRequestHandler.__init__(self, sock, addr, svr) def handle(self): "handle() method required by SocketServer" self.mainloop() def get_remote_proxy(self, oid): return RPCProxy(self, oid) class RPCClient(SocketIO): debugging = False location = "#C" # Client nextseq = 1 # Requests coming from the client are odd numbered def __init__(self, address, family=socket.AF_INET, type=socket.SOCK_STREAM): self.listening_sock = socket.socket(family, type) self.listening_sock.bind(address) self.listening_sock.listen(1) def accept(self): working_sock, address = self.listening_sock.accept() if self.debugging: print>>sys.__stderr__, "****** Connection request from ", address if address[0] == LOCALHOST: SocketIO.__init__(self, working_sock) else: print>>sys.__stderr__, "** Invalid host: ", address raise socket.error def get_remote_proxy(self, oid): return RPCProxy(self, oid) class RPCProxy(object): __methods = None __attributes = None def __init__(self, sockio, oid): self.sockio = sockio self.oid = oid def __getattr__(self, name): if self.__methods is None: self.__getmethods() if self.__methods.get(name): return MethodProxy(self.sockio, self.oid, name) if self.__attributes is None: self.__getattributes() if name in self.__attributes: value = self.sockio.remotecall(self.oid, '__getattribute__', (name,), {}) return value else: raise AttributeError, name def __getattributes(self): self.__attributes = self.sockio.remotecall(self.oid, "__attributes__", (), {}) def __getmethods(self): self.__methods = self.sockio.remotecall(self.oid, "__methods__", (), {}) def _getmethods(obj, methods): # Helper to get a list of methods from an object # Adds names to dictionary argument 'methods' for name in dir(obj): attr = getattr(obj, name) if hasattr(attr, '__call__'): methods[name] = 1 if type(obj) == types.InstanceType: _getmethods(obj.__class__, methods) if type(obj) == types.ClassType: for super in obj.__bases__: _getmethods(super, methods) def _getattributes(obj, attributes): for name in dir(obj): attr = getattr(obj, name) if not hasattr(attr, '__call__'): attributes[name] = 1 class MethodProxy(object): def __init__(self, sockio, oid, name): self.sockio = sockio self.oid = oid self.name = name def __call__(self, *args, **kwargs): value = self.sockio.remotecall(self.oid, self.name, args, kwargs) return value # XXX KBK 09Sep03 We need a proper unit test for this module. Previously # existing test code was removed at Rev 1.27 (r34098).
Close