3 |��\� � @ s" d Z ddlmZmZ ddlZddlmZmZmZm Z e rzdZ ddlmZ ddl mZ dd l mZ dd lmZ ddlmZ n4dZ ddlmZ ddlZdZdd lmZ ddlmZ yddlZW n ek r� dZY nX dZddd�ZG dd� de� r�ejne�ZG dd� de�Zdd� Zdd� Z dS )z*Defused xmlrpclib Also defuses gzip bomb � )�print_function�absolute_importN� )�DTDForbidden�EntitiesForbidden�ExternalReferenceForbidden�PY3z xmlrpc.client)�ExpatParser)�client)�server)�gzip_decode)�GzipDecodedResponse� xmlrpclib� i c C s� t st�|dkrt}tj| �}t jd|d�}y$|dk r@|j� }n|j|d �}W n tk rl td��Y nX |j � |j � |dkr�t |�|kr�td��|S )zrgzip encoded data -> unencoded data Decode data using the gzip content encoding as described in RFC 1952 N�rb)�mode�fileobjr r zinvalid dataz#max gzipped payload length exceeded)�gzip�NotImplementedError�MAX_DATA�io�BytesIO�GzipFile�read�IOError� ValueError�close�len)�data�limit�fZgzfZdecoded� r! �/usr/lib/python3.6/xmlrpc.py�defused_gzip_decode- s"