tzh
2024-08-22 c7d0944258c7d0943aa7b2211498fd612971ce27
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
[\¬Qc@sÖdZddlZddlZddlZddlZddlZddlZddlZddl    Z    ddl
Z
ddl Z ddl Z ddl Z ddlZd„Zd„Ze je jeeƒddZdZdejfd    „ƒYZiZe
j
d
ƒZe
j
d
ƒZd efd „ƒYZd efd„ƒYZd„Zdefd„ƒYZdejefd„ƒYZdefd„ƒYZ defd„ƒYZ!d„Z"d„Z#defd„ƒYZ$dS(sRPC 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.
 
iÿÿÿÿNcCs+tj|ƒ}t|tjƒs't‚|S(N(tmarshaltloadst
isinstancettypestCodeTypetAssertionError(tmstco((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pyt unpickle_code-scCs4t|tjƒst‚tj|ƒ}t|ffS(N(RRRRRtdumpsR(RR((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pyt pickle_code2siis    127.0.0.1t    RPCServercBs8eZdd„Zd„Zd„Zd„Zd„ZRS(cCs/|dkrt}ntjj|||ƒdS(N(tNonet
RPCHandlert SocketServert    TCPServert__init__(tselftaddrt handlerclass((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pyRGs     cCsdS(s@Override TCPServer method, no bind() phase for connecting entityN((R((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pyt server_bindLscCs|jj|jƒdS(sÎ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.
 
        N(tsockettconnecttserver_address(R((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pytserver_activatePscCs|j|jfS(s:Override TCPServer method, return already connected socket(RR(R((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pyt get_requestYscCsÂy‚Wn´tk
r‚n¡tj}|dddIJ|dIJ|dtjƒjƒIJ|dI|IJ|dIt|ƒIJtjd|ƒ|d    IJ|ddIJt    j
d
ƒnXd S( sÜ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.
 
        s
t-i(sUnhandled server exception!s
Thread: %ssClient Address: s    Request: tfiles#
*** Unrecoverable, server exiting!iN( t
SystemExittsyst
__stderr__t    threadingt currentThreadtgetNametreprt    tracebackt    print_exctost_exit(Rtrequesttclient_addressterf((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pyt handle_error]s     
 
N(t__name__t
__module__R RRRRR*(((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pyR Es
                 itSocketIOcBseZdZddd„Zd„Zd„Zd„Zd„Zd„Z    d„Z
d„Z d    „Z d
„Z d „Zd „Zd „Zd„Zd„Zd„Zd„Zd„Zd„Zd„ZdZdZdZd„Zd„Zd„Zd„Zd„Zd„Z d„Z!RS(icCsdtjƒ|_|dk    r'||_n||_|dkrEt}n||_i|_i|_    dS(N(
RR t
sockthreadR t    debuggingtsockt objecttabletobjtablet    responsestcvars(RR0R2R/((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pyR€s                   cCs/|j}d|_|dk    r+|jƒndS(N(R0R tclose(RR0((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pyR5‹s         cCstjdƒdS(s!override for specific exit actioniN(R%R&(R((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pytexithook‘scGsf|js dS|jdttjƒjƒƒ}x"|D]}|dt|ƒ}q7Wtj|IJdS(Nt (R/tlocationtstrRR R!RR(Rtargststa((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pytdebug•s     # cCs||j|<dS(N(R2(Rtoidtobject((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pytregisterscCs&y|j|=Wntk
r!nXdS(N(R2tKeyError(RR>((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pyt
unregister s cCsÛ|jd|ƒy|\}\}}}}Wntk
r@dSX||jkradd|ffS|j|}|dkr—i}    t||    ƒd|    fS|dkrÀi}
t||
ƒd|
fSt||ƒsàdd|ffSt||ƒ} y|d    kr5| ||Ž} t| tƒr+t    | ƒ} nd| fS|d
krat
j || ||ffƒdSdd |fSWndt k
r†‚nQtjk
rœ‚n;d } tj| || |fIJtjdtjƒdSXdS(Ns
localcall:tERRORsBad request formatsUnknown object id: %rt __methods__tOKt__attributes__sUnsupported method name: %rtCALLtQUEUEtQUEUEDsUnsupported message type: %ssU*** Internal Error: rpc.py:SocketIO.localcall()
 
 Object: %s 
 Method: %s 
 Args: %s
Rt    EXCEPTION(RCsBad request format(RIN(RJN(R=t    TypeErrorR2t _getmethodst_getattributesthasattrtgetattrRt RemoteObjectt    remotereft request_queuetputR RRterrorRRR#R$(RtseqR'thowR>t
methodnameR:tkwargstobjtmethodst
attributestmethodtrettmsg((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pyt    localcall¦sL    
 
 
  cCs8|jd||ƒ|j||||ƒ}|j|ƒS(Nsremotecall:asynccall: (R=t    asynccallt asyncreturn(RR>RWR:RXRU((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pyt
remotecallÐscCs8|jd||ƒ|j||||ƒ}|j|ƒS(Nsremotequeue:asyncqueue: (R=t
asyncqueueRa(RR>RWR:RXRU((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pyt remotequeueÕscCs‰d||||ff}|jƒ}tjƒ|jkrUtjƒ}||j|<n|jd|||||ƒ|j||fƒ|S(NRGs asynccall:%d:(tnewseqRR R.t    ConditionR4R=t
putmessage(RR>RWR:RXR'RUtcvar((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pyR`Ús  cCs‰d||||ff}|jƒ}tjƒ|jkrUtjƒ}||j|<n|jd|||||ƒ|j||fƒ|S(NRHsasyncqueue:%d:(ReRR R.RfR4R=Rg(RR>RWR:RXR'RURh((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pyRcäs  cCsG|jd|ƒ|j|ddƒ}|jd||ƒ|j|ƒS(Ns#asyncreturn:%d:call getresponse(): twaitgš™™™™™©?sasyncreturn:%d:response: (R=t getresponsetdecoderesponse(RRUtresponse((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pyRaîscCs«|\}}|dkr|S|dkr,dS|dkrI|jdƒdS|dkrp|jdƒ|jƒdS|dkr˜|jd|ƒt|‚nt||f‚dS(    NRERIRJsdecoderesponse: EXCEPTIONtEOFsdecoderesponse: EOFRCsdecoderesponse: Internal ERROR:(R R=tdecode_interrupthookt RuntimeErrort SystemError(RRlRVtwhat((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pyRkôs        
  cCs
t‚dS(tN(tEOFError(R((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pyRnscCs@y|jddddƒWntk
r;|jdƒdSXdS(s¥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.
 
        tmyseqRigš™™™™™©?smainloop:returnN(RjR RsR=(R((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pytmainloop
s
  cCsU|j||ƒ}|dk    rQ|\}}|dkrQ||j|ƒf}qQn|S(NRE(t _getresponseR t_proxify(RRtRiRlRVRq((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pyRjs    cCsEt|tƒrt||jƒSt|tjƒrAt|j|ƒS|S(N(Rt RemoteProxytRPCProxyR>RtListTypetmapRw(RRY((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pyRws
cCsÑ|jd|ƒtjƒ|jkrPx¥|j||ƒ}|dk    r(|Sq(n}|j|}|jƒx||jkr†|j    ƒqjW|j|}|jd||fƒ|j|=|j|=|j
ƒ|SdS(Ns_getresponse:myseq:s-_getresponse:%s: thread woke up: response: %s( R=RR R.t pollresponseR R4tacquireR3Ritrelease(RRtRiRlRh((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pyRv's" 
 
     
 
 
cCs|jd|_}|S(Ni(tnextseq(RRU((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pyRe=scCs|jd|dƒytj|ƒ}Wn0tjk
rZtjdIt|ƒIJ‚nXtjdt    |ƒƒ|}x—t    |ƒdkry>t
j
g|j ggƒ\}}}|j j |t  ƒ}Wn6ttfk
rìtd‚qztjk
r‚qzX||}qzWdS(Nsputmessage:%d:isCannot pickle:s<issocket no longer exists(R=tpickleR    t PicklingErrorRRR"tstructtpacktlentselectR0tsendtBUFSIZEtAttributeErrorRKtIOErrorRRT(RtmessageR;trtwtxtn((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pyRgAs $ RricCsÙ|jƒt|jƒ|jkrÏtj|jjƒggg|ƒ\}}}t|ƒdkredSy|jjt    ƒ}Wnt
j k
r—t ‚nXt|ƒdkr³t ‚n|j|7_|jƒn|j ƒS(Ni(t_stage0R„tbuffertbufneedR…R0tfilenoR trecvR‡RRTRst_stage1(RRiR‹RŒRR;((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pyt
pollpacketXs
-
     cCsj|jdkrft|jƒdkrf|jd }|jd|_tjd|ƒd|_d|_ndS(Niis<ii(tbufstateR„RR‚tunpackR‘(RR;((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pyRhs
$ cCsd|jdkr`t|jƒ|jkr`|j|j }|j|j|_d|_d|_|SdS(Niii(R–R„RR‘(Rtpacket((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pyR”os '        cCs–|j|ƒ}|dkrdSytj|ƒ}Wn]tjk
r‘tjdIJtjdIt|ƒIJtj    dtjƒtjdIJ‚nX|S(Ns-----------------------scannot unpickle packet:R(
R•R R€RtUnpicklingErrorRRR"R#t print_stack(RRiR˜RŠ((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pyt pollmessagews   c
Cs¾x·ytjdƒ}Wntjk
r,n,X|\}}|d|ff}|j|ƒy#|j|ƒ}|dkrzdSWn-tk
r™|jƒdSt    k
rªdSX|\}}|d}|j
d||fƒ|d    krU|j
d|ƒ|j ||ƒ}|j
d||fƒ|dkr@|j||fƒq|dkrqqq||kre|S|j j|dƒ}    |    dk    r|    j ƒ||j|<|    jƒ|    jƒqqqdS(
sRHandle 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.
 
        iREspollresponse:%d:myseq:%sRGRHspollresponse:%d:localcall:call:s%pollresponse:%d:localcall:response:%sN(sCALLsQUEUE(tresponse_queuetgettQueuetEmptyRgR›R Rst
handle_EOFRˆR=R_R4R}R3tnotifyR~(
RRtRitqmsgRURlRŠtresqRVtcv((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pyR|…sN    
 
         
 
 cCsq|jƒ|jdƒxI|jD]>}|j|}|jƒd|j|<|jƒ|jƒq!W|jƒdS(s+action taken upon link being closed by peerR RmN(sEOFN(    tEOFhookR=R4R}R R3R¡R~R6(RtkeyR¤((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pyR Îs
 
 
cCsdS(sBClasses using rpc client/server can override to augment EOF actionN((R((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pyR¥ÛsN("R+R,RR RR5R6R=R@RBR_RbRdR`RcRaRkRnRuRjRwRvReRgRR‘R–R•RR”R›R|R R¥(((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pyR-|s>                        *            
   
                                                       I     RPcBseZRS((R+R,(((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pyRPáscCs t|ƒ}|t|<t|ƒS(N(tidR1Rx(RYR>((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pyRQås 
RxcBseZd„ZRS(cCs ||_dS(N(R>(RR>((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pyRìs(R+R,R(((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pyRxêsR cBs/eZeZdZd„Zd„Zd„ZRS(s#ScCs6||_tj||ƒtjj||||ƒdS(N(tcurrent_handlerR-RRtBaseRequestHandler(RR0Rtsvr((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pyRôs    cCs|jƒdS(s(handle() method required by SocketServerN(Ru(R((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pythandleùscCs t||ƒS(N(Ry(RR>((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pytget_remote_proxyýs(R+R,tFalseR/R8RR«R¬(((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pyR ïs
        t    RPCClientcBsAeZeZdZdZejejd„Z    d„Z
d„Z RS(s#CicCs9tj||ƒ|_|jj|ƒ|jjdƒdS(Ni(Rtlistening_socktbindtlisten(Rtaddresstfamilyttype((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pyRscCsw|jjƒ\}}|jr4tjdI|IJn|dtkrWtj||ƒntjdI|IJtj    ‚dS(Ns****** Connection request from is** Invalid host: (
R¯tacceptR/RRt    LOCALHOSTR-RRRT(Rt working_sockR²((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pyRµ s    cCs t||ƒS(N(Ry(RR>((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pyR¬s( R+R,R­R/R8RRtAF_INETt SOCK_STREAMRRµR¬(((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pyR®s     
RycBs8eZdZdZd„Zd„Zd„Zd„ZRS(cCs||_||_dS(N(tsockioR>(RRºR>((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pyRs    cCs¡|jdkr|jƒn|jj|ƒrDt|j|j|ƒS|jdkr`|jƒn||jkr”|jj    |jd|fiƒ}|St
|‚dS(Nt__getattribute__( t_RPCProxy__methodsR t_RPCProxy__getmethodsRt MethodProxyRºR>t_RPCProxy__attributest_RPCProxy__getattributesRbRˆ(Rtnametvalue((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pyt __getattr__"s  cCs%|jj|jddiƒ|_dS(NRF((RºRbR>R¿(R((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pyt__getattributes0scCs%|jj|jddiƒ|_dS(NRD((RºRbR>R¼(R((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pyt __getmethods4sN(    R+R,R R¼R¿RRÃRÀR½(((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pyRys             cCs§x?t|ƒD]1}t||ƒ}t|dƒr d||<q q Wt|ƒtjkrjt|j|ƒnt|ƒtjkr£x!|j    D]}t||ƒq‰WndS(Nt__call__i(
tdirRORNR´Rt InstanceTypeRLt    __class__t    ClassTypet    __bases__(RYRZRÁtattrtsuper((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pyRL8scCsFx?t|ƒD]1}t||ƒ}t|dƒs d||<q q WdS(NRÆi(RÇRORN(RYR[RÁRÌ((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pyRMEsR¾cBseZd„Zd„ZRS(cCs||_||_||_dS(N(RºR>RÁ(RRºR>RÁ((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pyRMs        cOs%|jj|j|j||ƒ}|S(N(RºRbR>RÁ(RR:RXRÂ((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pyRÆRs!(R+R,RRÆ(((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pyR¾Ks    (%t__doc__RR%RR…RR‚tcPickleR€RRžR#tcopy_regRRRR
RR‡R¶RR R1RRRœR?R-RPRQRxR©R R®RyRLRMR¾(((sS/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/idlelib/rpc.pyt<module>sB                      
2ÿf