ϪfRdZddlZddlmZddlmZddlmZmZm Z m Z ddl m Z m Z mZddlmZddlmZmZddlmZdd lmZmZmZd Zd Zd ZGd de ZGddZGddej>Z Gdde Z!dZ"GddejFZ$dZ%GddejLZ'GddZ(gdZ)y)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)BinaryBooleanDateTimeFault)defererrorprotocol)Logger)failurereflect) nativeString)httpresourceserverABcd|_|S)a\ 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 4/usr/lib/python3/dist-packages/twisted/web/xmlrpc.pyrr"sAM HceZdZdZy)NoSuchFunctionz1 There is no function by the given name. N)__name__ __module__ __qualname____doc__rrrr5srrceZdZdZdZdZy)HandleraP 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. cb||_tj|_|j|yN)rrDeferredresultrun)selfrargss r__init__zHandler.__init__Ls$  nn& $rcL|jjtdy)NzImplement run() in subclasses)r%errbackNotImplementedError)r'r(s rr&z Handler.runQs /0OPQrN)rrrrr)r&rrrr!r!;s  Rrr!creZdZdZdZdZdZdZdZe Z ddZ dZ d Z d Zd Zd ZddZdZdZdZy )XMLRPCa 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} rr.)POSTcltjj|i|_||_||_yr#)rResourcer) subHandlers allowNone useDateTime)r'r5r6s rr)zXMLRPC.__init__ws-""4("&rc"||j|<yr#)__dict__)r'namevalues r __setattr__zXMLRPC.__setattr__}s# drc"||j|<yr#)r4)r'prefixhandlers r putSubHandlerzXMLRPC.putSubHandlers#* rc:|jj|dSr#)r4get)r'r=s r getSubHandlerzXMLRPC.getSubHandlers##FD11rcHt|jjSr#)listr4keysr's rgetSubHandlerPrefixeszXMLRPC.getSubHandlerPrefixessD$$))+,,rcf|jjdd|jdd tj|jj |j \}} |j|}g}|jj|jt|ddrtj||g|}ntj|g|}|j|j|j|j ||t(j*S#t"$r+}|j!||Yd}~t(j*Sd}~wwxYw#t$$rD}t#|j&d|}|j!||Yd}~t(j*Sd}~wwxYw)Nrs content-typetext/xml; charset=utf-8 use_datetimerFzCan't deserialize input: )contentseek setHeader xmlrpclibloadsreadr6lookupProcedure notifyFinish addErrbackappendgetattrr maybeDeferred _ebRender addCallback _cbRenderr ExceptionFAILUREr NOT_DONE_YET) r'requestr( functionPathfunctionresponseFaileddres r render_POSTzXMLRPC.render_POSTssQ"/+EF G!*$$&T5E5E" D, G// ="$$$&11.2G2GH8]E:++HgEEA++Hrs rrRzXMLRPC.lookupProcedures(   dnn - 3$1$7$7$J !FM((0G$T^^5Lv5UVV**=9 9 D+ 5t <  8= H !  ;m K HrcBtj|jdS)z\ Return a list of the names of all xmlrpc procedures. @since: 11.1 xmlrpc_)r prefixedMethodNames __class__rFs rlistProcedureszXMLRPC.listProceduress **4>>9EEr)FFr#)rrrrryr\isLeafrwallowedMethodsr rqr)r;r?rBrGrdrZrXrRrrrrr.r.Vs]0IG FIN 8D' $+2-#:6, %NFrr.cheZdZdZdZdZdgge_dZddgge_dZddgddgge_y) XMLRPCIntrospectiona 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<tj|||_y)z Implement Introspection support for an XMLRPC server. @param parent: the XMLRPC server to add Introspection support to. @type parent: L{XMLRPC} N)r.r)_xmlrpc_parent)r'parents rr)zXMLRPCIntrospection.__init__s $rcjg}|jdfg}|r|jd\}}|j|jDcgc]}||z c}|j|j Dcgc]%}|j |||z|j zf'c}|r|Scc}wcc}w)zO Return a list of the method names implemented by this server. rjr)rpopextendrrGrBrw)r' functionstodoobjr=r9s rxmlrpc_listMethodsz&XMLRPCIntrospection.xmlrpc_listMethodss $$b)*((1+KC   8J8J8LMftmM N KK!$ 9 9 ;&&t,ftmcmm.KL Ns  B+5*B0arraycx|jj|}t|ddxst|ddxsdS)zW Return a documentation string describing the use of the given method. helpNrrjrrRrVr'methods rxmlrpc_methodHelpz%XMLRPCIntrospection.xmlrpc_methodHelp!s=$$44V<vvt,V 40PVTVVrstringcZ|jj|}t|ddxsdS)a+ 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. signatureNrjrrs rxmlrpc_methodSignaturez*XMLRPCIntrospection.xmlrpc_methodSignature*s.$$44V<v{D17R7rN) rrrrr)rrrrrrrrrs[ %"&-I; W%-h#7"8 8 ( 8($rrc:|jdt|y)z Add Introspection support to an XMLRPC server. @param xmlrpc: the XMLRPC server to add Introspection support to. @type xmlrpc: L{XMLRPC} systemN)r?r)xmlrpcs raddIntrospectionr<s #6v#>?rc$eZdZdZdZdZdZy) QueryProtocolcd|_|jd|jj|j dd|j d|jj |j dd|jj }|j ddt|fz|jjrsd j|jj|jjg}d jd tj|g}|j d ||j|jj|y) Nr1s User-AgentsTwisted/XMLRPClibsHosts Content-typerIsContent-lengthri:rsBasic s Authorization) _response sendCommandfactorypath sendHeaderhostpayloadrouserjoinpasswordbase64 b64encode endHeaders transportrp)r'rauth authHeaders rconnectionMadezQueryProtocol.connectionMadeGs $,,"3"34  ';< !2!23 )CD,,&& )5CL?+BC <<  99dll//1F1FGHD9f.>.>t.D"EFJ OO,j 9  W%rcH|dk7r|jj||yy)Ns200)r badStatus)r'versionstatusmessages r handleStatuszQueryProtocol.handleStatusWs# V  LL " "67 3 rcF|jj||_y)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)rloseConnectionr)r'contentss rhandleResponsezQueryProtocol.handleResponse[s %%'!rcP|jtjtjs|jj d|t jj|||j0|jdc}|_ |jj|yy)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 ConnectionDoneConnectionLostrclientConnectionLostr HTTPClientconnectionLostr parseResponse)r'reasonresponses rrzQueryProtocol.connectionLostfsy||E00%2F2FG LL - -dF ; &&tV4 >> %'+~~t $Hdn LL & &x 0 &rN)rrrrrrrrrrrrFs& 4 " 1rrzP %s %s cBeZdZdZdZeZ ddZdZdZ e Z dZ y) QueryFactorya 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 @||c|_|_||c|_|_t|t j ||fz|_t|jtr |jjd|_tj||_ | |_y)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} )rgrhN)rrrrpayloadTemplaterOrlrrkrmrnrr$deferredr6) r'rrrrrr5r( cancellerr6s rr)zQueryFactory.__init__s8 $T 49#'  4=&  OODY 7*    dllC (<<..v6DLy1 &rcD|jsy tj||jdd}|jdc}|_|j |y#t $r:|jdc}|_|j tjYywxYw)NrJr) rrOrPr6callback BaseExceptionr+r Failure)r'rrrs rrzQueryFactory.parseResponses}}  ( xd>N>NOPQRSTUH '+mmT #Hdm   h '  0&*mmT #Hdm   W__. / 0s'AABBch|j&|jdc}|_|j|yyr#)rr+)r'_rrs rrz!QueryFactory.clientConnectionLosts1 == $&*mmT #Hdm   V $ %rcb|jdc}|_|jt||yr#)rr+ ValueError)r'rrrs rrzQueryFactory.badStatuss)"&--$-FG45r)NNFrNF) rrrrrrr r)rrclientConnectionFailedrrrrrr~sD.HH %'N (% 26rrc.eZdZdZeZ ddZdZy)Proxya 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|ddlm}t|\}} } } } } | jd}t |dk(rN|j djd}|j d|_ |j d|_ndx|_|_|djd}|j d|_ t|j d|_ | |_ |jdvrd|_ |d k(|_ |||_|||_||_||_||_||_y#t$r d|_YwxYw#t$r d|_ Y}wxYw) aX @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)rN/shttps)twisted.internetrrrxrorrrrrintportrsecurer5r6connectTimeout_reactor)r'urlrrr5r6rrschemenetlocrparamsqueryfragment netlocPartsuserpasshostports rr)zProxy.__init__ sT$ ? 08@ 5feXll4( { q "q)//5H QDI % ( Q )- ,DI q>''-LLO  HLLO,DI 99 #DI(  DI  $DM"&, +! % $  % DI s$1D5E 5EE EEc fd}|j|j|j||j|j|j |||j |jrddlm }|jt|j}|jjt|j|jxsd||jj"S|jj!t|j|jxsd|jj"S)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}. c4d_jyr#)r disconnect)rb connectorrs rcancelz Proxy.callRemote..cancelKs#G   "rr)ssl)hostnamei)timeoutP) queryFactoryrrrrr5r6rrroptionsForClientTLSrr connectSSLrr connectTCPr)r'rr(rrcontextFactoryrrs @@r callRemotezProxy.callRemote=s ### II II  II MM NN        ;; , 44l499>U4VN 00TYY'  S++ 1I  00TYY' R++ 1I r)NNFFg>@N)rrrrrrr)rrrrrrs.-^ L 1 f0 rr)r.r!rrrrrr)*rr xmlrpc.clientclientrO urllib.parserrrrrrrr r twisted.loggerr twisted.pythonr r twisted.python.compatr twisted.webrrrryr\rrr!r3r.rrrrr ClientFactoryrr__all__rrrrs !!::33!+./.   &U RR6^FX  ^FBB&BJ@-1DOO-1`W68))W6tU U p r