
    hR                        S r SSKrSSKJr  SSKJr  SSKJrJrJ	r	J
r
  SSKJrJrJr  SSKJr  SSKJrJr  SSKJr  SS	KJrJrJr  S
rSrS r " S S\
5      r " S S5      r " S S\R>                  5      r  " S S\ 5      r!S r" " S S\RF                  5      r$Sr% " S S\RL                  5      r' " S S5      r(/ SQr)g)z
A generic resource for publishing objects via XML-RPC.

Maintainer: Itamar Shtull-Trauring

@var Fault: See L{xmlrpclib.Fault}
@type Fault: L{xmlrpclib.Fault}
    N)urlparse)BinaryBooleanDateTimeFault)defererrorprotocol)Logger)failurereflect)nativeString)httpresourceserverA  B  c                     SU l         U $ )a4  
Decorator to cause the request to be passed as the first argument
to the method.

If an I{xmlrpc_} method is wrapped with C{withRequest}, the
request object is passed as the first argument to that method.
For example::

    @withRequest
    def xmlrpc_echo(self, request, s):
        return s

@since: 10.2
T)withRequest)fs    Y/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/twisted/web/xmlrpc.pyr   r   "   s     AMH    c                       \ rS rSrSrSrg)NoSuchFunction5   z)
There is no function by the given name.
 N)__name__
__module____qualname____firstlineno____doc____static_attributes__r   r   r   r   r   5   s    r   r   c                   $    \ rS rSrSrS rS rSrg)Handler;   a$  
Handle a XML-RPC request and store the state for a request in progress.

Override the run() method and return result using self.result,
a Deferred.

We require this class since we're not using threads, so we can't
encapsulate state in a running function if we're going  to have
to wait for results.

For example, lets say we want to authenticate against twisted.cred,
run a LDAP query and then pass its result to a database query, all
as a result of a single XML-RPC command. We'd use a Handler instance
to store the state of the running command.
c                 b    Xl         [        R                  " 5       U l        U R                  " U6   g N)r   r   Deferredresultrun)selfr   argss      r   __init__Handler.__init__L   s      nn&$r   c                 L    U R                   R                  [        S5      5        g )NzImplement run() in subclasses)r)   errbackNotImplementedError)r+   r,   s     r   r*   Handler.runQ   s    /0OPQr   )r   r)   N)r   r   r   r    r!   r-   r*   r"   r   r   r   r$   r$   ;   s     
Rr   r$   c                   ~    \ rS rSrSrSrSrSrSrSr	\
" 5       rSS jrS	 rS
 rS rS rS rSS jrS rS rS rSrg)XMLRPCV   a  
A resource that implements XML-RPC.

You probably want to connect this to '/RPC2'.

Methods published can return XML-RPC serializable results, Faults,
Binary, Boolean, DateTime, Deferreds, or Handler instances.

By default methods beginning with 'xmlrpc_' are published.

Sub-handlers for prefixed methods (e.g., system.listMethods)
can be added with putSubHandler. By default, prefixes are
separated with a '.'. Override self.separator to change this.

@ivar allowNone: Permit XML translating of Python constant None.
@type allowNone: C{bool}

@ivar useDateTime: Present C{datetime} values as C{datetime.datetime}
    objects?
@type useDateTime: C{bool}
r   r      .)   POSTc                 h    [         R                  R                  U 5        0 U l        Xl        X l        g r'   )r   Resourcer-   subHandlers	allowNoneuseDateTime)r+   r<   r=   s      r   r-   XMLRPC.__init__w   s)    ""4("&r   c                      X R                   U'   g r'   )__dict__)r+   namevalues      r   __setattr__XMLRPC.__setattr__}   s    #dr   c                      X R                   U'   g r'   )r;   )r+   prefixhandlers      r   putSubHandlerXMLRPC.putSubHandler   s    #* r   c                 :    U R                   R                  US 5      $ r'   )r;   get)r+   rF   s     r   getSubHandlerXMLRPC.getSubHandler   s    ##FD11r   c                 H    [        U R                  R                  5       5      $ r'   )listr;   keysr+   s    r   getSubHandlerPrefixesXMLRPC.getSubHandlerPrefixes   s    D$$))+,,r   c                 j   UR                   R                  SS5        UR                  SS5         [        R                  " UR                   R                  5       U R                  S9u  p# U R                  U5      n/ nUR                  5       R                  UR                  5        [        USS5      (       a  [        R                  " XA/UQ76 nO[        R                  " U/UQ76 nUR                  U R                  5        UR                  U R                   X5        [(        R*                  $ ! ["         a*  nU R!                  Xq5         S nA[(        R*                  $ S nAff = f! [$         aC  n[#        U R&                  SU 35      nU R!                  Xq5         S nA[(        R*                  $ S nAff = f)Nr   s   content-type   text/xml; charset=utf-8use_datetimer   FzCan't deserialize input: )contentseek	setHeader	xmlrpclibloadsreadr=   lookupProcedurenotifyFinish
addErrbackappendgetattrr   maybeDeferred	_ebRenderaddCallback	_cbRenderr   	ExceptionFAILUREr   NOT_DONE_YET)	r+   requestr,   functionPathfunctionresponseFaileddr   es	            r   render_POSTXMLRPC.render_POST   sl   Q"/+EF	G!*$$&T5E5E"DG//= "$$$&11.2G2GH8]E::++HEEA++H<t<AT^^,dnngF"""  +q** """+  	'dll&?s$CDANN1&&$ """)	's/   9E% *D. .
E"8EE"%
F2/*F--F2Nc                    U(       a  g [        U[        5      (       a  UR                  n[        U[        5      (       d  U4n  [        R
                  " USU R                  S9n[        U[        5      (       a  UR                  S5      nUR                  SS[        U5      4-  5        UR                  U5        UR!                  5         g ! [         aC  n[        U R                  SU 35      n[        R
                  " USU R                  S9n S nANS nAff = f! [         a    U R                  R                  S5         Nf = f)NT)methodresponse
allow_nonezCan't serialize output: utf8s   content-length   %d )
isinstancer$   r)   r   r[   dumpsr<   rg   rh   strencoderZ   lenwrite_logr   finish)r+   r)   rj   rm   rX   ro   r   s          r   rf   XMLRPC._cbRender   s   fg&&]]F&%((YF	"#//4DNN '3''!..0/#g,1HIMM'" 	  $,,*B1#(FG#//dt~~  	"IIb!	"s7    C $AD 
D9DD DD %EEc                     [        UR                  [        5      (       a  UR                  $ U R                  R	                  SU5        [        U R
                  S5      $ )Nrw   r	   )rx   rB   r   r~   r   rh   )r+   r   s     r   rd   XMLRPC._ebRender   sB    gmmU++== 		"g&T\\7++r   c                    UR                  U R                  5      S:w  a\  UR                  U R                  S5      u  p!U R                  U5      nUc  [	        U R
                  SU-  5      eUR                  U5      $ [        U SU-  S5      nU(       d  [	        U R
                  SU-  5      e[        U5      (       d  [	        U R
                  SU-  5      eU$ )a  
Given a string naming a procedure, return a callable object for that
procedure or raise NoSuchFunction.

The returned object will be called, and should return the result of the
procedure, a Deferred, or a Fault instance.

Override in subclasses if you want your own policy.  The base
implementation that given C{'foo'}, C{self.xmlrpc_foo} will be returned.
If C{procedurePath} contains C{self.separator}, the sub-handler for the
initial prefix is used to search for the remaining path.

If you override C{lookupProcedure}, you may also want to override
C{listProcedures} to accurately report the procedures supported by your
resource, so that clients using the I{system.listMethods} procedure
receive accurate results.

@since: 11.1
r6   Nzno such subHandler %sz	xmlrpc_%szprocedure %s not foundzprocedure %s not callable)	find	separatorsplitrL   r   	NOT_FOUNDr^   rb   callable)r+   procedurePathrF   rG   r   s        r   r^   XMLRPC.lookupProcedure   s    ( dnn-3$1$7$7$J!F((0G$T^^5Lv5UVV**=99D+5t<  8= H  !  ;m K  Hr   c                 D    [         R                  " U R                  S5      $ )zD
Return a list of the names of all xmlrpc procedures.

@since: 11.1
xmlrpc_)r   prefixedMethodNames	__class__rQ   s    r   listProceduresXMLRPC.listProcedures   s     **4>>9EEr   )r<   r;   r=   )FFr'   )r   r   r   r    r!   r   rh   isLeafr   allowedMethodsr   r~   r-   rC   rH   rL   rR   rp   rf   rd   r^   r   r"   r   r   r   r4   r4   V   s]    0 IGFIN8D'$+2-#:6,%NFr   r4   c                   p    \ rS rSrSrS rS rS//\l        S rSS//\l        S r	SS/SS//\	l        S	r
g
)XMLRPCIntrospection   a  
Implement the XML-RPC Introspection API.

By default, the methodHelp method returns the 'help' method attribute,
if it exists, otherwise the __doc__ method attribute, if it exists,
otherwise the empty string.

To enable the methodSignature method, add a 'signature' method attribute
containing a list of lists. See methodSignature's documentation for the
format. Note the type strings should be XML-RPC types, not Python types.
c                 :    [         R                  U 5        Xl        g)z
Implement Introspection support for an XMLRPC server.

@param parent: the XMLRPC server to add Introspection support to.
@type parent: L{XMLRPC}
N)r4   r-   _xmlrpc_parent)r+   parents     r   r-   XMLRPCIntrospection.__init__  s     	$r   c                    / nU R                   S4/nU(       a  UR                  S5      u  p4UR                  UR                  5        Vs/ s H  oTU-   PM	     sn5        UR                  UR	                  5        Vs/ s H%  nUR                  U5      XE-   UR                  -   4PM'     sn5        U(       a  M  U$ s  snf s  snf )z?
Return a list of the method names implemented by this server.
rw   r   )r   popextendr   rR   rL   r   )r+   	functionstodoobjrF   rA   s         r   xmlrpc_listMethods&XMLRPCIntrospection.xmlrpc_listMethods  s     	$$b)*((1+KC8J8J8LM8Ltm8LMNKK !$ 9 9 ; ; &&t,fmcmm.KL ; d  Ns   	B9;,B>arrayc                     U R                   R                  U5      n[        USS5      =(       d    [        USS5      =(       d    S$ )zG
Return a documentation string describing the use of the given method.
helpNr!   rw   r   r^   rb   r+   methods     r   xmlrpc_methodHelp%XMLRPCIntrospection.xmlrpc_methodHelp!  s=     $$44V<vvt,V	40PVTVVr   stringc                 d    U R                   R                  U5      n[        USS5      =(       d    S$ )z
Return a list of type signatures.

Each type signature is a list of the form [rtype, type1, type2, ...]
where rtype is the return type and typeN is the type of the Nth
argument. If no signature information is available, the empty
string is returned.
	signatureNrw   r   r   s     r   xmlrpc_methodSignature*XMLRPCIntrospection.xmlrpc_methodSignature*  s.     $$44V<v{D17R7r   )r   N)r   r   r   r    r!   r-   r   r   r   r   r"   r   r   r   r   r      s[    
%" &-I; W %-h#7"8
8 
(	8($r   r   c                 :    U R                  S[        U 5      5        g)z
Add Introspection support to an XMLRPC server.

@param xmlrpc: the XMLRPC server to add Introspection support to.
@type xmlrpc: L{XMLRPC}
systemN)rH   r   )xmlrpcs    r   addIntrospectionr   <  s     #6v#>?r   c                   ,    \ rS rSrS rS rS rS rSrg)QueryProtocoliF  c                    S U l         U R                  SU R                  R                  5        U R	                  SS5        U R	                  SU R                  R
                  5        U R	                  SS5        U R                  R                  nU R	                  SS[        U5      4-  5        U R                  R                  (       at  S	R                  U R                  R                  U R                  R                  /5      nS
R                  S[        R                  " U5      /5      nU R	                  SU5        U R                  5         U R                  R                  U5        g )Nr8   s
   User-Agents   Twisted/XMLRPClibs   Hosts   Content-typerU   s   Content-lengthrv      :r   s   Basic s   Authorization)	_responsesendCommandfactorypath
sendHeaderhostpayloadr|   userjoinpasswordbase64	b64encode
endHeaders	transportr}   )r+   r   auth
authHeaders       r   connectionMadeQueryProtocol.connectionMadeG  s    $,,"3"34';<!2!23)CD,,&&)5CL?+BC<<99dll//1F1FGHD9f.>.>t.D"EFJOO,j9W%r   c                 H    US:w  a  U R                   R                  X#5        g g )Ns   200)r   	badStatus)r+   versionstatusmessages       r   handleStatusQueryProtocol.handleStatusW  s!    VLL""63 r   c                 D    U R                   R                  5         Xl        g)z
Handle the XML-RPC response received from the server.

Specifically, disconnect from the server and store the XML-RPC
response so that it can be properly handled when the disconnect is
finished.
N)r   loseConnectionr   )r+   contentss     r   handleResponseQueryProtocol.handleResponse[  s     	%%'!r   c                 X   UR                  [        R                  [        R                  5      (       d  U R                  R                  SU5        [        R                  R                  X5        U R                  b/  U R                  Sso l	        U R                  R                  U5        gg)z
The connection to the server has been lost.

If we have a full response from the server, then parse it and fired a
Deferred with the return value or C{Fault} that the server gave us.
N)checkr	   ConnectionDoneConnectionLostr   clientConnectionLostr   
HTTPClientconnectionLostr   parseResponse)r+   reasonresponses      r   r   QueryProtocol.connectionLostf  sx     ||E00%2F2FGGLL--dF;&&t4>>%'+~~t$HnLL&&x0 &r   )r   N)	r   r   r   r    r   r   r   r   r"   r   r   r   r   r   F  s    & 4	"1r   r   zP<?xml version="1.0"?>
<methodCall>
<methodName>%s</methodName>
%s
</methodCall>
c                   L    \ rS rSrSrSr\r      S	S jrS r	S r
\
rS rSrg)
QueryFactoryi~  a}  
XML-RPC Client Factory

@ivar path: The path portion of the URL to which to post method calls.
@type path: L{bytes}

@ivar host: The value to use for the Host HTTP header.
@type host: L{bytes}

@ivar user: The username with which to authenticate with the server
    when making calls.
@type user: L{bytes} or L{None}

@ivar password: The password with which to authenticate with the server
    when making calls.
@type password: L{bytes} or L{None}

@ivar useDateTime: Accept datetime values as datetime.datetime objects.
    also passed to the underlying xmlrpclib implementation.  Defaults to
    C{False}.
@type useDateTime: C{bool}
Nc
                 @   XsU l         U l        XEsU l        U l        [        U[
        R                  " XvS94-  U l        [        U R                  [        5      (       a   U R                  R                  S5      U l        [        R                  " U5      U l        Xl        g)a  
@param method: The name of the method to call.
@type method: C{str}

@param allowNone: allow the use of None values in parameters. It's
    passed to the underlying xmlrpclib implementation. Defaults to
    C{False}.
@type allowNone: C{bool} or L{None}

@param args: the arguments to pass to the method.
@type args: C{tuple}

@param canceller: A 1-argument callable passed to the deferred as the
    canceller callback.
@type canceller: callable or L{None}
)rt   ru   N)r   r   r   r   payloadTemplater[   ry   r   rx   rz   r{   r   r(   deferredr=   )
r+   r   r   r   r   r   r<   r,   	cancellerr=   s
             r   r-   QueryFactory.__init__  s    8  $	49#' 	4=&OOD7*
 
 dllC((<<..v6DLy1&r   c                 H   U R                   (       d  g  [        R                  " XR                  S9S   S   nU R                   S so0l         UR	                  U5        g ! [
         a:    U R                   S so0l         UR                  [        R                  " 5       5         g f = f)NrV   r   )	r   r[   r\   r=   callbackBaseExceptionr0   r   Failure)r+   r   r   r   s       r   r   QueryFactory.parseResponse  s    }}	( x>N>NOPQRSTUH
 '+mmT#Hmh'  	0&*mmT#HmW__./	0s   $A AB! B!c                 h    U R                   b%  U R                   S so0l         UR                  U5        g g r'   )r   r0   )r+   _r   r   s       r   r   !QueryFactory.clientConnectionLost  s/    ==$&*mmT#HmV$ %r   c                 ^    U R                   S so0l         UR                  [        X5      5        g r'   )r   r0   
ValueError)r+   r   r   r   s       r   r   QueryFactory.badStatus  s%    "&---F45r   )r   r   r   r   r   r=   r   )NNFr   NF)r   r   r   r    r!   r   r   r
   r-   r   r   clientConnectionFailedr   r"   r   r   r   r   r   ~  sD    . HH %'N
(%
 26r   r   c                   8    \ rS rSrSr\r      SS jrS rSr	g)Proxyi  aa  
A Proxy for making remote XML-RPC calls.

Pass the URL of the remote XML-RPC server to the constructor.

Use C{proxy.callRemote('foobar', *args)} to call remote method
'foobar' with *args.

@ivar user: The username with which to authenticate with the server
    when making calls.  If specified, overrides any username information
    embedded in C{url}.  If not specified, a value may be taken from
    C{url} if present.
@type user: L{bytes} or L{None}

@ivar password: The password with which to authenticate with the server
    when making calls.  If specified, overrides any password information
    embedded in C{url}.  If not specified, a value may be taken from
    C{url} if present.
@type password: L{bytes} or L{None}

@ivar allowNone: allow the use of None values in parameters. It's
    passed to the underlying L{xmlrpclib} implementation. Defaults to
    C{False}.
@type allowNone: C{bool} or L{None}

@ivar useDateTime: Accept datetime values as datetime.datetime objects.
    also passed to the underlying L{xmlrpclib} implementation. Defaults to
    C{False}.
@type useDateTime: C{bool}

@ivar connectTimeout: Number of seconds to wait before assuming the
    connection has failed.
@type connectTimeout: C{float}

@ivar _reactor: The reactor used to create connections.
@type _reactor: Object providing L{twisted.internet.interfaces.IReactorTCP}

@ivar queryFactory: Object returning a factory for XML-RPC protocol. Use
    this for testing, or to manipulate the XML-RPC parsing behavior. For
    example, you may set this to a custom "debugging" factory object that
    reimplements C{parseResponse} in order to log the raw XML-RPC contents
    from the server before continuing on with parsing. Another possibility
    is to implement your own XML-RPC marshaller here to handle non-standard
    XML-RPC traffic.
@type queryFactory: L{twisted.web.xmlrpc.QueryFactory}
Nc                    Uc  SSK Jn  [        U5      u  pppU	R                  S5      n[	        U5      S:X  aN  UR                  S5      R                  S5      nUR                  S5      U l         UR                  S5      U l        OS=U l        U l        US   R                  S5      nUR                  S5      U l	         [        UR                  S5      5      U l        Xl        U R                  S;   a  SU l        US	:H  U l        Ub  X l        Ub  X0l        X@l        XPl        X`l        Xpl        g! [         a
    SU l         Nf = f! [         a
    SU l         N|f = f)
a(  
@param url: The URL to which to post method calls.  Calls will be made
    over SSL if the scheme is HTTPS.  If netloc contains username or
    password information, these will be used to authenticate, as long as
    the C{user} and C{password} arguments are not specified.
@type url: L{bytes}

Nr   )reactor   @   r   )r   N   /s   https)twisted.internetr   r   r   r|   r   r   r   r   r   intportr   securer<   r=   connectTimeout_reactor)r+   urlr   r   r<   r=   r   r   schemenetlocr   paramsqueryfragmentnetlocPartsuserpasshostports                    r   r-   Proxy.__init__
  s@   $ ?08@5ell4({q "q)//5H QDI% (Q )-,DIq>''-LLO		HLLO,DI 	99#DI(I$M"&,+ ! % $%  	DI	s$   0D1  E 1EEEEc                   ^^ UU4S jnU R                  U R                  U R                  UU R                  U R                  U R
                  UUU R                  5	      mU R                  (       a  SSKJ	n  UR                  [        U R                  5      S9nU R                  R                  [        U R                  5      U R                  =(       d    STUU R                  S9mTR"                  $ U R                  R!                  [        U R                  5      U R                  =(       d    STU R                  S9mTR"                  $ )a  
Call remote XML-RPC C{method} with given arguments.

@return: a L{defer.Deferred} that will fire with the method response,
    or a failure if the method failed. Generally, the failure type will
    be L{Fault}, but you can also have an C{IndexError} on some buggy
    servers giving empty responses.

    If the deferred is cancelled before the request completes, the
    connection is closed and the deferred will fire with a
    L{defer.CancelledError}.
c                 4   > S Tl         TR                  5         g r'   )r   
disconnect)rn   	connectorr   s    r   cancel Proxy.callRemote.<locals>.cancelK  s    #G  "r   r   )ssl)hostnamei  )timeoutP   )queryFactoryr   r   r   r   r<   r=   r   r   r  optionsForClientTLSr   r   
connectSSLr   r   
connectTCPr   )r+   r   r,   r  r  contextFactoryr  r   s         @@r   
callRemoteProxy.callRemote=  s   	# ##IIIIIIMMNN

 ;;, 44l499>U4VN00TYY'		 S++ 1 I  00TYY'		R++	 1 I r   )
r   r<   r   r   r   r   r   r   r=   r   )NNFFg      >@N)
r   r   r   r    r!   r   r  r-   r  r"   r   r   r   r   r     s.    -^  L
 1 f0 r   r   )r4   r$   r   r   r   r   r   r   )*r!   r   xmlrpc.clientclientr[   urllib.parser   r   r   r   r   r   r   r	   r
   twisted.loggerr   twisted.pythonr   r   twisted.python.compatr   twisted.webr   r   r   r   rh   r   r   r$   r:   r4   r   r   r   r   r   ClientFactoryr   r   __all__r   r   r   <module>r%     s   
  ! ! : : 3 3 ! + . / . 	
&U R R6^FX ^FBB& BJ@-1DOO -1`W68)) W6tU  U p	r   