3 \\&@sfddlZddlZddlZddlmZddlmZddlZddlZ ddl m Z ddl Z ddl mZy ddlZWnek rdZYnXddZdejdd ZdXZdZZd[Zd\Zd]Zd^Zd_Zd`ZdaZdbZdcZddZdeZ dfZ!Gddde"Z#Gddde#Z$Gddde#Z%Gddde#Z&e'Z(Z)ed d d Z*e*j+ddkrFd d!Z,n"e*j+d"dkr`d#d!Z,nd$d!Z,[*d%d&Z-Gd'd(d(Z.d)d*Z/d+d,Z0Gd-d.d.Z1d/d0Z2e.e1fZ3Gd1d2d2Z4Gd3d4d4Z5Gd5d6d6Z6Gd7d8d8Z7Gd9d:d:Z8Gd;d<d<Z9dZ:Z;Zd?Z=dhd@dAZ>didBdCZ?dDdEZ@djdGdHZAGdIdJdJerTejBneCZDGdKdLdLZEGdMdNdNZFGdOdPdPeFZGGdQdRdRZHeHZIeJdSkrbeHdTZKyeLeKjMjNWn.e#k rZOzeLdUeOWYddZO[OXnXe9eKZPePjQePjRd dVePjSd d yxePD]ZTeLeTqWWn.e#k r`ZOzeLdUeOWYddZO[OXnXdS)kN)datetime)Decimal)expat)BytesIOcCs$|jdd}|jdd}|jddS)N&z&z>)replace)sr %/usr/lib64/python3.6/xmlrpc/client.pyescapes  r z%d.%diiXi~i~i,~iiiYiZi[c@seZdZddZdS)ErrorcCst|S)N)repr)selfr r r __str__sz Error.__str__N)__name__ __module__ __qualname__rr r r r rsrc@seZdZddZddZdS) ProtocolErrorcCs&tj|||_||_||_||_dS)N)r__init__urlerrcodeerrmsgheaders)rrrrrr r r rs  zProtocolError.__init__cCsd|jj|j|j|jfS)Nz<%s for %s: %s %s>) __class__rrrr)rr r r __repr__szProtocolError.__repr__N)rrrrrr r r r rsrc@s eZdZdS) ResponseErrorN)rrrr r r r r sr c@seZdZddZddZdS)FaultcKstj|||_||_dS)N)rr faultCode faultString)rr"r#Zextrar r r rs zFault.__init__cCsd|jj|j|jfS)Nz <%s %s: %r>)rrr"r#)rr r r rszFault.__repr__N)rrrrrr r r r r!sr!z%YZ0001cCs |jdS)Nz%Y%m%dT%H:%M:%S)strftime)valuer r r _iso8601_format sr&z%4YcCs |jdS)Nz%4Y%m%dT%H:%M:%S)r$)r%r r r r&scCs|jdjdS)Nz%Y%m%dT%H:%M:%S)r$zfill)r%r r r r&scCsLt|trt|St|ttjfs<|dkr2tj}tj|}d|ddS)Nrz%04d%02d%02dT%02d:%02d:%02d) isinstancerr&tupletimeZ struct_timeZ localtime)r%r r r _strftimes  r-c@sneZdZdddZddZddZdd Zd d Zd d ZddZ ddZ ddZ ddZ ddZ ddZdS)DateTimercCs t|tr||_n t||_dS)N)r*strr%r-)rr%r r r r)s zDateTime.__init__cCst|tr|j}|j}nzt|tr2|j}t|}n`t|trH|j}|}nJt|drd|j}|j}n.t|drv|jj p|t |}t d|jj |f||fS)N timetuplerzCan't compare %s and %s) r*r.r%rr&r/hasattrr0rrtype TypeError)rotherr oZotyper r r make_comparable/s$       zDateTime.make_comparablecCs|j|\}}||kS)N)r6)rr4r r5r r r __lt__DszDateTime.__lt__cCs|j|\}}||kS)N)r6)rr4r r5r r r __le__HszDateTime.__le__cCs|j|\}}||kS)N)r6)rr4r r5r r r __gt__LszDateTime.__gt__cCs|j|\}}||kS)N)r6)rr4r r5r r r __ge__PszDateTime.__ge__cCs|j|\}}||kS)N)r6)rr4r r5r r r __eq__TszDateTime.__eq__cCstj|jdS)Nz%Y%m%dT%H:%M:%S)r,strptimer%)rr r r r0XszDateTime.timetuplecCs|jS)N)r%)rr r r r`szDateTime.__str__cCsd|jj|jt|fS)Nz<%s %r at %#x>)rrr%id)rr r r rcszDateTime.__repr__cCst|j|_dS)N)r/stripr%)rdatar r r decodefszDateTime.decodecCs$|jd|j|j|jddS)Nzz )writer%)routr r r encodeis  zDateTime.encodeN)r)rrrrr6r7r8r9r:r;r0rrr@rCr r r r r.#s r.cCst}|j||S)N)r.r@)r?r%r r r _datetimens rDcCs tj|dS)Nz%Y%m%dT%H:%M:%S)rr<)r?r r r _datetime_typetsrEc@s6eZdZd ddZddZddZdd Zd d ZdS) BinaryNcCs>|dkrd}n&t|ttfs,td|jjt|}||_dS)Nz#expected bytes or bytearray, not %s)r*bytes bytearrayr3rrr?)rr?r r r rs zBinary.__init__cCs t|jdS)Nzlatin-1)r/r?)rr r r rszBinary.__str__cCst|tr|j}|j|kS)N)r*rFr?)rr4r r r r;s z Binary.__eq__cCstj||_dS)N)base64 decodebytesr?)rr?r r r r@sz Binary.decodecCs4|jdtj|j}|j|jd|jddS)Nz asciiz )rArJ encodebytesr?r@)rrBencodedr r r rCs  z Binary.encode)N)rrrrrr;r@rCr r r r rF}s  rFcCst}|j||S)N)rFr@)r?r%r r r _binarys rOc@s$eZdZddZddZddZdS) ExpatParsercCsDtjdd|_}||_|j|_|j|_|j|_ d}|j |ddS)N) rZ ParserCreate_parser_targetstartZStartElementHandlerendZEndElementHandlerr?ZCharacterDataHandlerxml)rtargetparserencodingr r r rszExpatParser.__init__cCs|jj|ddS)Nr)rQParse)rr?r r r feedszExpatParser.feedc Cs8y |j}Wntk rYnX|`|`|jdddS)NrGT)rQAttributeErrorrRrY)rrWr r r closes  zExpatParser.closeN)rrrrrZr\r r r r rPs rPc@seZdZdddZiZddZddZd d Zeeed<d d Z e ee <d dZ e ee <e Z ddZeee<efddZeee<ddZeee<eee<ddZeee<eee<efddZeee<ddZeee<ddZeee<eee<eed<dS) MarshallerNFcCsi|_d|_||_||_dS)N)memor?rX allow_none)rrXr_r r r rszMarshaller.__init__cCsg}|j}|j}t|tr@|d||j|jd||dn8|dx&|D]}|d||||dqNW|ddj|}|S) Nz )r"r#z z z z z )append_Marshaller__dumpr*r!r"r#join)rvaluesrBrAdumpvresultr r r dumpss"      zMarshaller.dumpsc Csy|jt|}Wnjtk r|t|ds)r_r3)rr%rAr r r dump_nilszMarshaller.dump_nilcCs$|d||rdpd|ddS)Nz10z r )rr%rAr r r dump_boolszMarshaller.dump_boolcCs<|tks|tkrtd|d|tt||ddS)Nzint exceeds XML-RPC limitsz z )MAXINTMININT OverflowErrorr/int)rr%rAr r r dump_longs zMarshaller.dump_longcCs |d|t||ddS)Nzz )r)rr%rAr r r dump_double%s zMarshaller.dump_doublecCs |d||||ddS)Nzz r )rr%rAr r r r dump_unicode+s zMarshaller.dump_unicodecCs,|dtj|}||jd|ddS)Nz rLz )rJrMr@)rr%rArNr r r dump_bytes1s zMarshaller.dump_bytescCs^t|}||jkrtdd|j|<|j}|dx|D]}|||q8W|d|j|=dS)Nz"cannot marshal recursive sequencesz z )r=r^r3rb)rr%rAirerfr r r dump_array9s   zMarshaller.dump_arraycCst|}||jkrtdd|j|<|j}|dxP|jD]D\}}|dt|ts^td|d||||||dq z zdictionary key must be stringz%s z z )r=r^r3rbitemsr*r/)rr%rAr r|rekrfr r r dump_structGs     zMarshaller.dump_structcCs |d|t||ddS)Nzz )r-)rr%rAr r r dump_datetimeYs zMarshaller.dump_datetimecCs2|jtkr ||_|j||`n|j|j|dS)N)rWRAPPERSrArCrri)rr%rAr r r dump_instance_s   zMarshaller.dump_instancerj)NF) rrrrrkrhrbrpr2rsboolrxrwZdump_intryfloatr rzr/r{rHrIr}r+listrdictrrrr.rFr r r r r]s:      r]c@sjeZdZdDddZddZddZdd Zd d Zd d ZddZ ddZ iZ ddZ e e d<ddZ e e d<ddZee d<ee d<ee d<ee d<ee d<ee d<d d!Zee d"<ee d#<d$d%Zee d&<d'd(Zee d)<ee d*<d+d,Zee d-<d.d/Zee d0<d1d2Zee d3<d4d5Zee d6<d7d8Zee d9<d:d;Zee d<<d=d>Zee d?<d@dAZee dB<dCS)E UnmarshallerFcCsHd|_g|_g|_g|_d|_d|_d|_|jj|_|p:||_||_ dS)NFzutf-8) _type_stack_marks_data_value _methodname _encodingra _use_datetime _use_bytes)r use_datetimeuse_builtin_typesr r r rs  zUnmarshaller.__init__cCs:|jdks|jrt|jdkr0tf|jdt|jS)Nfaultr)rrr r!rr+)rr r r r\s  zUnmarshaller.closecCs|jS)N)r)rr r r getmethodnameszUnmarshaller.getmethodnamecCs ||_dS)N)r)rrXZ standaloner r r rUszUnmarshaller.xmlcCshd|kr|jdd}|dks&|dkr8|jjt|jg|_|jrZ||jkrZtd||dk|_dS)N:rarraystructzunknown tag %rr%) splitrralenrrrrkr )rtagZattrsr r r rSs zUnmarshaller.startcCs|jj|dS)N)rra)rtextr r r r?szUnmarshaller.datacCspy|j|}WnNtk r\d|kr*dSy|j|jdd}Wntk rVdSXYnX||dj|jS)Nrrr`r)rkrlrrcr)rrror r r rTs zUnmarshaller.endcCshy|j|}WnNtk r\d|kr*dSy|j|jdd}Wntk rVdSXYnX|||S)Nrrr)rkrlr)rrr?ror r r end_dispatchs zUnmarshaller.end_dispatchcCs|jdd|_dS)Nr)rar)rr?r r r end_nils zUnmarshaller.end_nilZnilcCs:|dkr|jdn|dkr(|jdntdd|_dS)NrrFrqTzbad boolean valuer)rar3r)rr?r r r end_booleans   zUnmarshaller.end_booleanbooleancCs|jt|d|_dS)Nr)rarwr)rr?r r r end_intszUnmarshaller.end_intZi1Zi2Zi4Zi8rwZ bigintegercCs|jt|d|_dS)Nr)rarr)rr?r r r end_doubleszUnmarshaller.end_doubleZdoublercCs|jt|d|_dS)Nr)rarr)rr?r r r end_bigdecimalszUnmarshaller.end_bigdecimalZ bigdecimalcCs&|jr|j|j}|j|d|_dS)Nr)rr@rar)rr?r r r end_strings  zUnmarshaller.end_stringstringnamecCs.|jj}|j|dg|j|d<d|_dS)Nr)rpoprr)rr?markr r r end_arrays zUnmarshaller.end_arrayrcCsd|jj}i}|j|d}x,tdt|dD]}||d|||<q.W|g|j|d<d|_dS)Nrrr)rrrrangerr)rr?rrr~r|r r r end_structs zUnmarshaller.end_structrcCs6t}|j|jd|jr"|j}|j|d|_dS)NrLr)rFr@rCrr?rar)rr?r%r r r end_base64 s  zUnmarshaller.end_base64rJcCs,t}|j||jrt|}|j|dS)N)r.r@rrEra)rr?r%r r r end_dateTimes  zUnmarshaller.end_dateTimezdateTime.iso8601cCs|jr|j|dS)N)rr)rr?r r r end_valueszUnmarshaller.end_valuer%cCs d|_dS)Nparams)r)rr?r r r end_params#szUnmarshaller.end_paramsrcCs d|_dS)Nr)r)rr?r r r end_fault'szUnmarshaller.end_faultrcCs"|jr|j|j}||_d|_dS)N methodName)rr@rr)rr?r r r end_methodName+s zUnmarshaller.end_methodNamerN)FF)rrrrr\rrUrSr?rTrrkrrrrrrrrrrrrrrr r r r rssX   rc@s$eZdZddZddZddZdS)_MultiCallMethodcCs||_||_dS)N)_MultiCallMethod__call_list_MultiCallMethod__name)rZ call_listrr r r r8sz_MultiCallMethod.__init__cCst|jd|j|fS)Nz%s.%s)rrr)rrr r r __getattr__;sz_MultiCallMethod.__getattr__cGs|jj|j|fdS)N)rrar)rargsr r r __call__=sz_MultiCallMethod.__call__N)rrrrrrr r r r r5src@seZdZddZddZdS)MultiCallIteratorcCs ||_dS)N)results)rrr r r rDszMultiCallIterator.__init__cCsR|j|}t|tikr.t|d|dn t|tgkrF|dStddS)Nr"r#rz#unexpected type in multicall result)rr2r! ValueError)rr|itemr r r __getitem__Gs  zMultiCallIterator.__getitem__N)rrrrrr r r r r@src@s0eZdZddZddZeZddZddZd S) MultiCallcCs||_g|_dS)N)_MultiCall__server_MultiCall__call_list)rserverr r r raszMultiCall.__init__cCsd|jjt|fS)Nz <%s at %#x>)rrr=)rr r r reszMultiCall.__repr__cCs t|j|S)N)rr)rrr r r rjszMultiCall.__getattr__cCs:g}x"|jD]\}}|j||dq Wt|jjj|S)N)rr)rrarrsystemZ multicall)rZmarshalled_listrrr r r rmszMultiCall.__call__N)rrrrrrrrr r r r rPs rFcCsrtrHtrH|rt}tj}n|r&t}t}nt}t}tdd||t}t|}n"t||d}trbt|}nt |}||fS)NTF)rr) FastParserFastUnmarshallerrErJrKrOrDr!rrP)rrZ mkdatetimeZmkbytesrVrWr r r getparsers    rcCst|trd}n|rt|tr|s&d}tr4t|}n t||}|j|}|dkr^dt|}nd}|rx|d|d|df}n|r|d|d f}n|Sd j|S) Nrzutf-8z$ z z z z z z r`)r*r!r+FastMarshallerr]rhr/rc)r methodnameZmethodresponserXr_mr?Z xmlheaderr r r rhs2    rhcCs2t||d\}}|j||j|j|jfS)N)rr)rrZr\r)r?rrpur r r loadss  rc Cs<tstt}tjd|dd}|j|WdQRX|jS)Nwbr)modefileobjZ compresslevel)gzipNotImplementedErrorrGzipFilerAgetvalue)r?rogzfr r r gzip_encodes r@cCststtjdt|dH}y$|dkr0|j}n|j|d}Wntk r\tdYnXWdQRX|dkrt||krtd|S)Nrb)rrrrz invalid dataz#max gzipped payload length exceeded)rrrrreadOSErrorrr)r?Z max_decoderZdecodedr r r gzip_decodes rc@seZdZddZddZdS)GzipDecodedResponsecCs.tstt|j|_tjj|d|jddS)Nr)rr)rrrriorr)rresponser r r r=szGzipDecodedResponse.__init__c Cs"ztjj|Wd|jjXdS)N)rrr\r)rr r r r\EszGzipDecodedResponse.closeN)rrrrr\r r r r r9src@s$eZdZddZddZddZdS)_MethodcCs||_||_dS)N) _Method__send _Method__name)rsendrr r r rRsz_Method.__init__cCst|jd|j|fS)Nz%s.%s)rrr)rrr r r rUsz_Method.__getattr__cGs|j|j|S)N)rr)rrr r r rWsz_Method.__call__N)rrrrrrr r r r rOsrc@szeZdZdeZdZdZdddZdddZdd d Z d d Z d dZ ddZ ddZ ddZddZddZddZdS) TransportzPython-xmlrpc/%sTNFcCs||_||_d|_g|_dS)N)NN)r_use_builtin_types _connection_extra_headers)rrrr r r rnszTransport.__init__cCs~xxdD]p}y|j||||Stjjk r8|r4Yqtk rt}z"|sb|jtjtjtjfkrdWYdd}~XqXqWdS)Nrr)rr) single_requesthttpclientZRemoteDisconnectedrerrnoZ ECONNRESETZ ECONNABORTEDZEPIPE)rhosthandler request_bodyverboser|er r r request~s  zTransport.requestcCsy6|j||||}|j}|jdkr4||_|j|SWn2tk rLYntk rh|jYnX|jddr~|j t |||j|j t |j dS)Nzcontent-lengthr`) send_requestZ getresponseZstatusrparse_responser! Exceptionr\ getheaderrrreasonrZ getheaders)rrrrrZ http_connZrespr r r rs"  zTransport.single_requestcCst|j|jdS)N)rr)rrr)rr r r rszTransport.getparsercCsri}t|tr|\}}tjj|\}}|rdtjj|}tj|jd}dj |j }dd|fg}ng}|||fS)Nzutf-8r`Z AuthorizationzBasic ) r*r+urllibparseZ splituserZunquote_to_bytesrJrMr@rcr)rrx509ZauthZ extra_headersr r r get_host_infos  zTransport.get_host_infocCsL|jr||jdkr|jdS|j|\}|_}|tjj|f|_|jdS)Nrr)rrrrrZHTTPConnection)rrchostrr r r make_connections  zTransport.make_connectioncCs |j\}}|rd|_|jdS)N)NN)rr\)rr connectionr r r r\s zTransport.closecCs|j|}|jdd}|r&|jd|jrLtrL|jd|dd|jd n |jd||jd |jd |jf|j|||j |||S) NrZPOSTT)Zskip_accept_encodingAccept-Encodingr Content-Typetext/xmlz User-Agent)rr)rr) rrZset_debuglevelaccept_gzip_encodingrZ putrequestra user_agent send_headers send_content)rrrrdebugrrr r r rs        zTransport.send_requestcCs"x|D]\}}|j||qWdS)N) putheader)rrrkeyvalr r r r szTransport.send_headerscCsR|jdk r0|jt|kr0tr0|jddt|}|jdtt||j|dS)NzContent-EncodingrzContent-Length)encode_thresholdrrrrr/Z endheaders)rrrr r r rs  zTransport.send_contentcCst|dr*|jdddkr$t|}q.|}n|}|j\}}x2|jd}|sLP|jr`tdt||j|q)rrrr)rr r r rszServerProxy.__repr__cCs t|j|S)N)r_ServerProxy__request)rrr r r rszServerProxy.__getattr__cCs.|dkr|jS|dkr|jStd|fdS)Nr\rzAttribute %r not found)_ServerProxy__closerr[)rattrr r r rs zServerProxy.__call__cCs|S)Nr )rr r r __enter__szServerProxy.__enter__cGs |jdS)N)r)rrr r r __exit__szServerProxy.__exit__)NNFFFF) rrrrrrrrrrrr r r r r rls r__main__zhttp://localhost:8000ZERROR liliiDii ipiԁiDiCiBiiii)FF)NNNF)FF)r)UrJsysr,rdecimalrZ http.clientrZ urllib.parserZ xml.parsersrrrrr ImportErrorr version_infor rtruZ PARSE_ERRORZ SERVER_ERRORZAPPLICATION_ERRORZ SYSTEM_ERRORZTRANSPORT_ERRORZNOT_WELLFORMED_ERRORZUNSUPPORTED_ENCODINGZINVALID_ENCODING_CHARZINVALID_XMLRPCZMETHOD_NOT_FOUNDZINVALID_METHOD_PARAMSZINTERNAL_ERRORrrrr r!rrZBooleanZ_day0r$r&r-r.rDrErFrOrrPr]rrrrrrrrrhrrrrobjectrrrr rZServerrrr Z currentTimeZgetCurrentTimerfZmultiZgetDatapowaddrr r r r s           K #!(C '  ' J  d)i