o ,] @sdZddlmZmZmZmZddlmZmZm Z m Z m Z ddl Z e j e _e je _ddlZddlZddlmZddlmZddlmZddlmZdd lmZddlZddlZdd l m!Z!zddl"Z"Wn e#ymdZ"Ynwd d Z$ej%dd Z&dZ'dZ(dZ)dZ*dZ+dZ,dZ-dZ.dZ/dZ0dZ1dZ2dZ3dZ4Gddde5Z6Gddde6Z7Gddde6Z8Gd d!d!e6Z9e:Z;ZGd&d'd'e?Z@d(d)ZAd*d+ZBGd,d-d-e?ZCd.d/ZDe@eCfZEGd0d1d1e?ZFGd2d3d3e?ZGGd4d5d5e?ZHGd6d7d7e?ZIGd8d9d9e?ZJGd:d;d;e?ZKdZLZMZNdWd=d>ZO  z>)replace)sr@/usr/lib/python3/dist-packages/future/backports/xmlrpc/client.pyescapes   riiiDii ipiԁiCiBiiic@eZdZdZddZdS)ErrorzBase class for client errors.cCst|SN)reprselfrrr__str__sz Error.__str__N)__name__ __module__ __qualname____doc__r rrrrrs rc@ eZdZdZddZddZdS) ProtocolErrorz!Indicates an HTTP protocol error.cCs&t|||_||_||_||_dSr)r__init__urlerrcodeerrmsgheaders)rr(r)r*r+rrrr's  zProtocolError.__init__cCsd|j|j|jfS)Nz)r(r)r*rrrr__repr__szProtocolError.__repr__Nr!r"r#r$r'r,rrrrr&s r&c@seZdZdZdS) ResponseErrorz$Indicates a broken response package.N)r!r"r#r$rrrrr.sr.c@r%)Faultz#Indicates an XML-RPC fault package.cKst|||_||_dSr)rr' faultCode faultString)rr0r1extrarrrr'  zFault.__init__cCsdt|jt|jfS)Nz)rr0r1rrrrr,s zFault.__repr__Nr-rrrrr/s r/cCs d|j|j|j|j|j|jfS)N%04d%02d%02dT%02d:%02d:%02d)yearmonthdayhourminutesecondvaluerrr_iso8601_formats  r=cCsLt|tr t|St|ttjfs|dkrt}t|}d|ddS)Nrr4) isinstancer r=tupletime struct_time localtimer;rrr _strftime's  rDc@szeZdZdZdddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZdS)DateTimezDateTime wrapper for an ISO 8601 string or time tuple or localtime integer value to generate 'dateTime.iso8601' XML-RPC value. rcCs"t|tr ||_dSt||_dSr)r?r r<rD)rr<rrrr'8s  zDateTime.__init__cCst|tr|j}|j}||fSt|tr|j}t|}||fSt|tr-|j}|}||fSt|dr>|}|}||fSt|drG|jj pJt |}t d|jj |f)N timetuple __class__zCan't compare %s and %s) r?rEr<r r=r hasattrrFrGr!type TypeError)rotherrootyperrrmake_comparable>s0      zDateTime.make_comparablecCs||\}}||kSrrNrrKrrLrrr__lt__SzDateTime.__lt__cCs||\}}||kSrrOrPrrr__le__WrRzDateTime.__le__cCs||\}}||kSrrOrPrrr__gt__[rRzDateTime.__gt__cCs||\}}||kSrrOrPrrr__ge___rRzDateTime.__ge__cCs||\}}||kSrrOrPrrr__eq__crRzDateTime.__eq__cCs||\}}||kSrrOrPrrr__ne__grRzDateTime.__ne__cCst|jdSNz%Y%m%dT%H:%M:%S)rAstrptimer<rrrrrFkzDateTime.timetuplecC|jSrr;rrrrr szDateTime.__str__cCsdt|jt|fS)Nz)rr<idrrrrr,vzDateTime.__repr__cCst||_dSr)r stripr<rdatarrrdecodeyzDateTime.decodecCs$|d||j|ddSNzz )writer<)routrrrencode|s  zDateTime.encodeN)r)r!r"r#r$r'rNrQrSrTrUrVrWrFr r,rbrgrrrrrE2s  rEcCt}|||Sr)rErbrar<rrr _datetime rjcCs t|dSrX)r rY)rarrr_datetime_type rlc@sBeZdZdZdddZddZddZd d Zd d Zd dZ dS)BinaryzWrapper for binary data.NcCs>|durd}nt|ttfstd|jjt|}||_dS)Nz#expected bytes or bytearray, not %s)r?r bytearrayrJrGr!rar`rrrr's zBinary.__init__cCs t|jdS)Nzlatin-1)r rarrrrr rmzBinary.__str__cCst|tr|j}|j|kSrr?rnrarrKrrrrVr3z Binary.__eq__cCst|tr|j}|j|kSrrqrrrrrrWr3z Binary.__ne__cCst||_dSr)base64 decodebytesrar`rrrrbz Binary.decodecCs4|dt|j}||d|ddSNz asciiz )rers encodebytesrarb)rrfencodedrrrrgs  z Binary.encoder) r!r"r#r$r'r rVrWrbrgrrrrrns  rncCrhr)rnrbrirrr_binaryrkrzc@$eZdZddZddZddZdS) ExpatParsercCsDtdd|_}||_|j|_|j|_|j|_ d}| |ddSr) r ParserCreate_parser_targetstartStartElementHandlerendEndElementHandlerraCharacterDataHandlerxml)rtargetparserencodingrrrr'szExpatParser.__init__cCs|j|ddSNr)r~Parser`rrrfeedrczExpatParser.feedcCs|jdd|`|`dS)N)r~rrrrrrcloses zExpatParser.closeN)r!r"r#r'rrrrrrr|s r|c@seZdZdZdddZiZddZdd Zd d Zeee d<d d Z e ee <ddZ e ee <e ZddZeee<efddZeee<ddZeee<eee<ddZeee<eee<efddZeee<ddZeee<ddZeee<eee <eed<dS) MarshalleravGenerate an XML-RPC params chunk from a Python data structure. Create a Marshaller instance for each set of parameters, and use the "dumps" method to convert your data (represented as a tuple) to an XML-RPC params chunk. To write a fault response, pass a Fault instance instead. You may prefer to use the "dumps" module function for this purpose. NFcCsi|_d|_||_||_dSr)memorar allow_none)rrrrrrr' zMarshaller.__init__cCsg}|j}|j}t|tr |d||j|jd||dn|d|D]}|d||||dq&|dd|}t|S) Nz )r0r1z z z z z r)append_Marshaller__dumpr?r/r0r1joinr )rvaluesrfredumpvresultrrrdumpss&     zMarshaller.dumpscCsz |jtt|}Wn2ty=t|dstdt|t|jD]}||jvr5tdt|q$|jd}Ynw||||dS)N__dict__zcannot marshal %s objects_arbitrary_instance)dispatchrIrKeyErrorrHrJ__mro__keys)rr<reftype_rrr__dumps   zMarshaller.__dumpcCs|jstd|ddS)Nz0cannot marshal None unless allow_none is enabledz)rrJrr<rerrrdump_nil!s zMarshaller.dump_nilcCs$|d||r dp d|ddS)Nz10z rrrrr dump_bool' zMarshaller.dump_boolcCs<|tks|tkr td|d|tt||ddS)Nzlong int exceeds XML-RPC limitsz z )MAXINTMININT OverflowErrorr rrrrr dump_long-s  zMarshaller.dump_longcCs$|d|tt||ddS)Nzz )rrrrrr dump_double8rzMarshaller.dump_doublecCs |d||||ddS)Nzz r)rr<rerrrr dump_unicode>  zMarshaller.dump_unicodecCs,|dt|}||d|ddSrv)rsrxrb)rr<reryrrr dump_bytesDs  zMarshaller.dump_bytescCsZt|}||jvr tdd|j|<|j}|d|D]}|||q|d|j|=dS)Nz"cannot marshal recursive sequencesz z )r]rrJr)rr<reirrrrr dump_arrayLs    zMarshaller.dump_arraycCst|}||jvr tdd|j|<|j}|d|D]"\}}|dt|ts.td|d||||||dq|d|j|=dS)Nz%cannot marshal recursive dictionariesz z zdictionary key must be stringz%s z z )r]rrJritemsr?r )rr<rerrrkrrrr dump_structZs      zMarshaller.dump_structcCs |d|t||ddSrd)rDrrrr dump_datetimelrzMarshaller.dump_datetimecCs4|jtvr||_|||`dS||j|dSr)rGWRAPPERSrergrrrrrr dump_instancers  zMarshaller.dump_instancer)NF)!r!r"r#r$r'rrrrrIrboolrrdump_intrfloatrrr rrrprr@listrrrr rrErnrrrrrs>       rc@s>eZdZdZd>ddZddZddZd d Zd d Zd dZ ddZ ddZ iZ ddZ e e d<ddZee d<ddZee d<ee d<ee d<ddZee d <d!d"Zee d#<ee d$<d%d&Zee d'<d(d)Zee d*<d+d,Zee d-<d.d/Zee d0<d1d2Zee d3<d4d5Zee d6<d7d8Zee d9<d:d;Zee d<<d=S)? UnmarshalleraUnmarshal an XML-RPC response, based on incoming XML event messages (start, data, end). Call close() to get the resulting data structure. Note that this reader is fairly tolerant, and gladly accepts bogus XML-RPC data without complaining (but not bogus XML). FcCsBd|_g|_g|_g|_d|_d|_|jj|_|p||_||_dS)Nutf-8) _type_stack_marks_data _methodname _encodingr _use_datetime _use_bytesr use_datetimeuse_builtin_typesrrrr's   zUnmarshaller.__init__cCs>|jdus|jr t|jdkrtdi|jdt|jS)Nfaultrr)rrr.r/rr@rrrrrs   zUnmarshaller.closecCr[r)rrrrr getmethodnamer\zUnmarshaller.getmethodnamecC ||_dSr)r)rr standalonerrrr zUnmarshaller.xmlcCs6|dks|dkr|jt|jg|_|dk|_dS)Narraystructr<)rrlenrr_value)rtagattrsrrrrszUnmarshaller.startcCs|j|dSr)rr)rtextrrrraruzUnmarshaller.datacCs6z|j|}Wn tyYdSw||d|jS)Nr)rrrr)rrrrrrrs  zUnmarshaller.endcCs.z|j|}Wn tyYdSw|||Sr)rr)rrrarrrr end_dispatchs   zUnmarshaller.end_dispatchcCs|dd|_dSr)rrr`rrrend_nils  zUnmarshaller.end_nilnilcCs:|dkr |dn|dkr|dntdd|_dS)NrFrTzbad boolean valuer)rrJrr`rrr end_booleans    zUnmarshaller.end_booleanbooleancC|t|d|_dSr)rrrr`rrrend_int zUnmarshaller.end_inti4i8rcCrr)rrrr`rrr end_doublerzUnmarshaller.end_doubledoublecCs&|jr ||j}||d|_dSr)rrbrrr`rrr end_strings   zUnmarshaller.end_stringstringnamecCs.|j}|j|dg|j|d<d|_dSr)rpoprr)rramarkrrr end_arrays  zUnmarshaller.end_arrayrcCs`|j}i}|j|d}tdt|dD] }||d|||<q|g|j|d<d|_dS)Nrr)rrrr rr)rrarrrrrrr end_structs  zUnmarshaller.end_structrcCs6t}||d|jr|j}||d|_dS)Nrwr)rnrbrgrrarrrrar<rrr end_base64s   zUnmarshaller.end_base64rscCs,t}|||jrt|}||dSr)rErbrrlrrrrr end_dateTimes  zUnmarshaller.end_dateTimezdateTime.iso8601cCs|jr ||dSdSr)rrr`rrr end_valueszUnmarshaller.end_valuer<cC d|_dS)Nparamsrr`rrr end_params rzUnmarshaller.end_paramsrcCr)Nrrr`rrr end_fault$rzUnmarshaller.end_faultrcCs"|jr ||j}||_d|_dS)N methodName)rrbrrr`rrrend_methodName(s  zUnmarshaller.end_methodNamerNFF)r!r"r#r$r'rrrrrarrrrrrrrrrrrrrrrrrrrrsP      rc@r{)_MultiCallMethodcC||_||_dSr)_MultiCallMethod__call_list_MultiCallMethod__name)r call_listrrrrr'5 z_MultiCallMethod.__init__cCt|jd|j|fSNz%s.%s)rrrrrrrr __getattr__8r^z_MultiCallMethod.__getattr__cGs|j|j|fdSr)rrrrargsrrr__call__:r^z_MultiCallMethod.__call__Nr!r"r#r'rrrrrrr2 rc@r%)MultiCallIteratorzaIterates over the results of a multicall. Exceptions are raised in response to xmlrpc faults.cCrr)results)rrrrrr'ArzMultiCallIterator.__init__cCsJ|j|}tt|trt|d|dt|tgkr!|dStd)Nr0r1rz#unexpected type in multicall result)rr?rIrr/ ValueError)rritemrrr __getitem__Ds zMultiCallIterator.__getitem__N)r!r"r#r$r'r rrrrr=s rc@s4eZdZdZddZddZeZddZdd Zd S) MultiCalla}server -> a object used to boxcar method calls server should be a ServerProxy object. Methods can be added to the MultiCall using normal method call syntax e.g.: multicall = MultiCall(server_proxy) multicall.add(2,3) multicall.get_address("Guido") To execute the multicall, call the MultiCall object e.g.: add_result, address = multicall() cCs||_g|_dSr)_MultiCall__server_MultiCall__call_list)rserverrrrr'^rzMultiCall.__init__cCs dt|S)Nz)r]rrrrr,brmzMultiCall.__repr__cC t|j|Sr)rr rrrrrgrmzMultiCall.__getattr__cCs6g}|jD] \}}|||dqt|jj|S)N)rr)r rrr system multicall)rmarshalled_listrrrrrrjszMultiCall.__call__N) r!r"r#r$r'r,r rrrrrrr Ms r FcCs~tr'tr'|r t}tj}n |rt}t}nt}t}tdd||t}t|}||fSt||d}tr7t|}||fSt |}||fS)zgetparser() -> parser, unmarshaller Create an instance of the fastest available parser, and attach it to an unmarshalling object. Return both objects. TFrr) FastParserFastUnmarshallerrlrsrtrzrjr/rr|)rr mkdatetimemkbytesrrrrr getparser|s$ rcCst|ttfs Jdt|trd}n|r$t|tr$t|dks$Jd|s(d}tr/t|}nt||}||}|dkrDdt|}nd}|r[t|tsR||}|d|d|d f}n |rd|d |d f}n|Std  |S) adata [,options] -> marshalled data Convert an argument tuple or a Fault instance to an XML-RPC request (or response, if the methodresponse option is used). In addition to the data object, the following options can be given as keyword arguments: methodname: the method name for a methodCall packet methodresponse: true to create a methodResponse packet. If this option is used with a tuple, the tuple must be a singleton (i.e. it can contain only one element). encoding: the packet encoding (default is UTF-8) All byte strings in the data structure are assumed to use the packet encoding. Unicode strings are automatically converted, where necessary. z(argument must be tuple or Fault instancerz"response tuple must be a singletonrz$ z z z z z z r) r?r@r/rFastMarshallerrrr rgr)r methodnamemethodresponserrmra xmlheaderrrrrs>      rcCs2t||d\}}|||||fS)zdata -> unmarshalled data, method name Convert an XML-RPC packet to unmarshalled data plus a method name (None if not present). If the XML-RPC packet represents a fault condition, this function raises a Fault exception. r)rrrr)rarrpurrrloadss r cCsDtstt}tjd|dd}||||}||S)zhdata -> gzip encoded data Encode data using the gzip content encoding as described in RFC 1952 wbr)modefileobj compresslevel)gzipNotImplementedErrorrGzipFilerergetvalue)rargzfryrrr gzip_encodes r*cCsVtstt|}tjd|d}z|}Wn ty tdw|||S)zrgzip encoded data -> unencoded data Decode data using the gzip content encoding as described in RFC 1952 rbr"r#z invalid data)r%r&rr'readIOErrorrr)rarr)decodedrrr gzip_decodes  r0c@r%)GzipDecodedResponsezha file-like object to decode a response encoded with the gzip method, as described in RFC 1952. cCs.tstt||_tjj|d|jddS)Nr+r,)r%r&rr-ior'r')rresponserrrr':szGzipDecodedResponse.__init__cCstj||jdSr)r%r'rr2rrrrrBs zGzipDecodedResponse.closeN)r!r"r#r$r'rrrrrr16s r1c@r{)_MethodcCrr _Method__send _Method__name)rsendrrrrr'Mrz_Method.__init__cCrr)r4r6r7rrrrrPr^z_Method.__getattr__cGs||j|Srr5rrrrrRrZz_Method.__call__Nrrrrrr4Jrr4c@s~eZdZdZdeZdZdZdddZddd Z dd d Z d d Z ddZ ddZ ddZddZddZddZddZdS) Transportz1Handles an HTTP transaction to an XML-RPC server.zPython-xmlrpc/%sTNFcCs||_||_d|_g|_dS)NNN)r_use_builtin_types _connection_extra_headersrrrrr'irzTransport.__init__c Cs~dD]:}z |||||WStjy0}z|s%|jtjtjtjfvr&WYd}~qd}~wtjy<|r:YqwdS)N)rr) single_requestsocketerrorerrno ECONNRESET ECONNABORTEDEPIPE http_client BadStatusLine)rhosthandler request_bodyverbosererrrrequestys zTransport.requestcCsz|||||}|}|jdkr||_||WSWnty$ty/|w|ddr:| t |||j|j t | )Nzcontent-lengthr) send_request getresponsestatusrJparse_responser/ Exceptionr getheaderr-r&reasonr getheaders)rrGrHrIrJ http_connresprrrr>s(      zTransport.single_requestcCst|j|jdS)Nr)rrr;rrrrrszTransport.getparsercCsni}t|tr |\}}t|\}}|r0t|}t|d}d| }dd|fg}ng}|||fS)Nrr AuthorizationzBasic ) r?r@ urllib_parse splituserunquote_to_bytesrsrxrbrsplit)rrGx509auth extra_headersrrr get_host_infos    zTransport.get_host_infocCsJ|jr||jdkr|jdS||\}|_}|t|f|_|jdS)Nrr)r<r`r=rEHTTPConnectionrrGchostr]rrrmake_connections   zTransport.make_connectioncCs&|jdr|jdd|_dSdS)Nrr:)r<rrrrrrs  zTransport.closecCs||}|jdd}|r|d|jr&tr&|jd|dd|dn|d||d|d|jf|||| |||S)NrPOSTT)skip_accept_encoding)zAccept-Encodingr%)z Content-Typeztext/xmlz User-Agent) rdr=set_debuglevelaccept_gzip_encodingr% putrequestr user_agent send_headers send_content)rrGrHrIdebug connectionr+rrrrNs        zTransport.send_requestcCs|D] \}}|||qdSr) putheader)rrnr+keyvalrrrrks zTransport.send_headerscCsR|jdur|jt|krtr|ddt|}|dtt|||dS)NContent-Encodingr%zContent-Length)encode_thresholdrr%ror*r endheaders)rrnrIrrrrl s  zTransport.send_contentcCst|dr|dddkrt|}n|}n|}|\}} |d}|s&n|jr0tdt|||q||ur>| | | S)NrSrrrr%rizbody:) rHrSr1rr-rJprintrrr)rr3streamrrrarrrrQs$     zTransport.parse_responser)F)r!r"r#r$ __version__rjrhrsr'rLr>rr`rdrrNrkrlrQrrrrr9[s    ! r9c@r) SafeTransportz2Handles an HTTPS transaction to an XML-RPC server.cCsj|jr||jdkr|jdSttdstd||\}|_}|tj|dfi|p+if|_|jdS)NrrHTTPSConnectionz1your version of http.client doesn't support HTTPS)r<rHrEr&r`r=ryrbrrrrdAs   zSafeTransport.make_connectionN)r!r"r#r$rdrrrrrx<s rxc@sJeZdZdZ  dddZddZdd Zd d ZeZd d Z ddZ dS) ServerProxyauri [,options] -> a logical connection to an XML-RPC server uri is the connection point on the server, given as scheme://host/target. The standard implementation always supports the "http" scheme. If SSL socket support is available (Python 2.0), it also supports "https". If the target part and the slash preceding it are both omitted, "/RPC2" is assumed. The following options can be given as keyword arguments: transport: a transport factory encoding: the request encoding (default is UTF-8) All 8-bit strings passed to the server proxy are assumed to use the given encoding. NFc Cst|\}}|dvrtdt|\|_|_|jsd|_|dur1|dkr)t} nt} | ||d}||_|p7d|_ ||_ ||_ dS)N)httphttpszunsupported XML-RPC protocolz/RPC2r|rr) rY splittyper. splithost_ServerProxy__host_ServerProxy__handlerrxr9_ServerProxy__transport_ServerProxy__encoding_ServerProxy__verbose_ServerProxy__allow_none) ruri transportrrJrrrrIrHrrrr'vs"  zServerProxy.__init__cCs|jdSr)rrrrrr__closerZzServerProxy.__closecCsNt|||j|jd|j}|jj|j|j||jd}t |dkr%|d}|S)N)rr)rJrr) rrrrgrrLrrrr)rrrrLr3rrr __requests  zServerProxy.__requestcCsd|j|jfS)Nz)rrrrrrr,s zServerProxy.__repr__cCrr)r4_ServerProxy__requestrrrrrs zServerProxy.__getattr__cCs*|dkr|jS|dkr|jStd|f)z|A workaround to get special attributes on the ServerProxy without interfering with the magic __getattr__ rrzAttribute %r not found)_ServerProxy__closerAttributeError)rattrrrrrs zServerProxy.__call__)NNFFFF) r!r"r#r$r'rrr,r rrrrrrrz`s  rz__main__zhttp://localhost:8000ERRORr rr)NNNF)fr$ __future__rrrrfuture.builtinsrrrr r rs encodestringrx decodestringrtsysrAr future.backports.httpr rEfuture.backports.urllibr rY future.utilsr xml.parsersrr?rAr2rr% ImportErrorrversionrwrr PARSE_ERROR SERVER_ERRORAPPLICATION_ERROR SYSTEM_ERRORTRANSPORT_ERRORNOT_WELLFORMED_ERRORUNSUPPORTED_ENCODINGINVALID_ENCODING_CHARINVALID_XMLRPCMETHOD_NOT_FOUNDINVALID_METHOD_PARAMSINTERNAL_ERRORrRrr&r.r/rrBooleanr=rDobjectrErjrlrnrzrr|rrrrr rrrrrr r*r0r'r1r4r9rxrzServerr!rru currentTimegetCurrentTimermultigetDatapowaddr3rrrrsW,          O ((-  ' ' Mb$_