
    f                     6   d Z ddlmZmZ ddlZddlmZmZmZm	Z	 e	r!dZ
ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ndZ
ddlmZ ddlZdZdd
lmZ ddlmZ 	 ddlZdZddZ G d derej6                  ne      Z G d de      Zd Zd Z y# e$ r dZY :w xY w)z*Defused xmlrpclib

Also defuses gzip bomb
    )print_functionabsolute_importN   )DTDForbiddenEntitiesForbiddenExternalReferenceForbiddenPY3zxmlrpc.client)ExpatParser)client)server)gzip_decode)GzipDecodedResponse	xmlrpclibi  c                    t         st        |t        }t        j                  |       }t        j
                  d|      }	 |dk  r|j                         }n|j                  |dz         }|j                          |j                          |dk\  rt        |      |kD  rt        d      |S # t        $ r t        d      w xY w)zrgzip encoded data -> unencoded data

    Decode data using the gzip content encoding as described in RFC 1952
    rbmodefileobjr   r   zinvalid dataz#max gzipped payload length exceeded)gzipNotImplementedErrorMAX_DATAioBytesIOGzipFilereadIOError
ValueErrorcloselen)datalimitfgzfdecodeds        L/var/www/cvtools/html/venv/lib/python3.12/site-packages/defusedxml/xmlrpc.pydefused_gzip_decoder&   -   s    
 !!}


4A
--T1
-C)19hhjGhhuqy)G GGIIIKzc'lU*>??N  )(()s   *B, ,Cc                   $    e Zd ZdZddZd Zd Zy)DefusedGzipDecodedResponsezha file-like object to decode a response encoded with the gzip
    method, as described in RFC 1952.
    Nc                 v   t         st        ||nt        x| _        }|dk  r|j	                         }d | _        n|j	                  |dz         }d| _        |dk\  rt        |      |kD  rt        d      t        j                  |      | _
        t         j                  j                  | d| j                         y )Nr   r   max payload length exceededr   r   )r   r   r   r!   r   
readlengthr   r   r   r   stringior   __init__)selfresponser!   r    s       r%   r-   z#DefusedGzipDecodedResponse.__init__K   s     %%&+&7UXE
U19==?D"DO==+DDOA:#d)e+:;;

4(t$F    c                 x   | j                   dk\  r| j                   | j                  z
  }t        ||dz         }t        j                  j                  | |      }| xj                  t        |      z  c_        | j                  | j                   kD  rt        d      |S t        j                  j                  | |      S )Nr   r   r*   )r!   r+   minr   r   r   r   r   )r.   nleftr    s       r%   r   zDefusedGzipDecodedResponse.read\   s    ::?::/DAtax A==%%dA.DOOs4y(O+ !>??K==%%dA..r0   c                 v    t         j                  j                  |        | j                  j                          y N)r   r   r   r,   )r.   s    r%   r   z DefusedGzipDecodedResponse.closeh   s$    D!r0   r6   )__name__
__module____qualname____doc__r-   r   r    r0   r%   r(   r(   F   s    G"
/r0   r(   c                   ,    e Zd ZddZd Zd Zd Zd Zy)DefusedExpatParserc                 D   t        j                  | |       || _        || _        || _        | j
                  }| j                  r| j                  |_        | j                  r"| j                  |_	        | j                  |_        | j                  r| j                  |_        y y r6   )r
   r-   
forbid_dtdforbid_entitiesforbid_external_parserdefused_start_doctype_declStartDoctypeDeclHandlerdefused_entity_declEntityDeclHandlerdefused_unparsed_entity_declUnparsedEntityDeclHandler#defused_external_entity_ref_handlerExternalEntityRefHandler)r.   targetr?   r@   rA   parsers         r%   r-   zDefusedExpatParser.__init__n   s    T6*$..??-1-L-LF*'+'?'?F$/3/P/PF,.2.V.VF+  r0   c                     t        |||      r6   )r   )r.   namesysidpubidhas_internal_subsets        r%   rC   z-DefusedExpatParser.defused_start_doctype_decl|   s    4..r0   c                 "    t        ||||||      r6   r   )r.   rN   is_parameter_entityvaluebaserO   rP   notation_names           r%   rE   z&DefusedExpatParser.defused_entity_decl   s      eT5%OOr0   c                 "    t        |d ||||      r6   rS   )r.   rN   rV   rO   rP   rW   s         r%   rG   z/DefusedExpatParser.defused_unparsed_entity_decl   s    dD%NNr0   c                     t        ||||      r6   )r   )r.   contextrV   rO   rP   s        r%   rI   z6DefusedExpatParser.defused_external_entity_ref_handler   s    ($uEEr0   N)FTT)r7   r8   r9   r-   rC   rE   rG   rI   r;   r0   r%   r=   r=   m   s    W/P
OFr0   r=   c                      t         t        _        t        t        _        t
        t        _        t        rt
        t        _        y y r6   )r=   xmlrpc_client
FastParserr(   r   r&   r   xmlrpc_serverr;   r0   r%   monkey_patchr_      s*    1M(BM% 3M$7! r0   c                      d t         _        t        t         _        t        t         _        t        rt        t        _        y y r6   )r\   r]   _OrigGzipDecodedResponser   _orig_gzip_decoder   r^   r;   r0   r%   unmonkey_patchrc      s*    #M(@M% 1M$5! r0   r6   )!r:   
__future__r   r   r   commonr   r   r   r	   
__origin__xmlrpc.clientr
   xmlrpcr   r\   r   r^   r   rb   r   ra   r   r   ImportErrorr   r&   r   objectr(   r=   r_   rc   r;   r0   r%   <module>rk      s    7 	 T T J)..>MJ%%M:I 2$$F $NF F>86e  Ds   B BB