3
‡Œðil  ã               @   sp   d Z ddlmZmZmZ ddlmZ G dd„ deƒZG dd„ deƒZG dd	„ d	eƒZ	G d
d„ deƒZ
[[[[dS )a  Response classes used by urllib.

The base class, addbase, defines a minimal file-like interface,
including read() and readline().  The typical response object is an
addinfourl instance, which defines an info() method that returns
headers and a geturl() method that returns the url.
é    )Úabsolute_importÚdivisionÚunicode_literals)Úobjectc               @   s@   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dS )Úaddbasez(Base class for addinfo and addclosehook.c             C   sV   || _ | j j| _| j j| _t| j dƒr0| j j| _t| j dƒrH| j j| _n
dd„ | _d S )NÚ	readlinesÚfilenoc               S   s   d S )N© r	   r	   r	   úB/tmp/pip-build-6m2fasei/future/future/backports/urllib/response.pyÚ<lambda>   s    z"addbase.__init__.<locals>.<lambda>)ÚfpÚreadÚreadlineÚhasattrr   r   )Úselfr   r	   r	   r
   Ú__init__   s    


zaddbase.__init__c             C   s
   t | jƒS )N)Úiterr   )r   r	   r	   r
   Ú__iter__   s    zaddbase.__iter__c             C   s   d| j jt| ƒ| jf S )Nz<%s at %r whose fp = %r>)Ú	__class__Ú__name__Úidr   )r   r	   r	   r
   Ú__repr__%   s    zaddbase.__repr__c             C   s>   | j r| j jƒ  d | _ d | _d | _d | _d | _d | _d | _d S )N)r   Úcloser   r   r   r   r   Ú__next__)r   r	   r	   r
   r   )   s    
zaddbase.closec             C   s   | j d krtdƒ‚| S )NzI/O operation on closed file)r   Ú
ValueError)r   r	   r	   r
   Ú	__enter__4   s    
zaddbase.__enter__c             C   s   | j ƒ  d S )N)r   )r   ÚtypeÚvalueÚ	tracebackr	   r	   r
   Ú__exit__9   s    zaddbase.__exit__N)
r   Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r	   r	   r	   r
   r      s   r   c               @   s    e Zd ZdZdd„ Zdd„ ZdS )Úaddclosehookz*Class to add a close hook to an open file.c             G   s   t j| |ƒ || _|| _d S )N)r   r   Ú	closehookÚhookargs)r   r   r$   r%   r	   r	   r
   r   ?   s    zaddclosehook.__init__c             C   s,   | j r| j | jŽ  d | _ d | _tj| ƒ d S )N)r$   r%   r   r   )r   r	   r	   r
   r   D   s
    zaddclosehook.closeN)r   r    r!   r"   r   r   r	   r	   r	   r
   r#   <   s   r#   c               @   s    e Zd ZdZdd„ Zdd„ ZdS )Úaddinfoz.class to add an info() method to an open file.c             C   s   t j| |ƒ || _d S )N)r   r   Úheaders)r   r   r'   r	   r	   r
   r   N   s    zaddinfo.__init__c             C   s   | j S )N)r'   )r   r	   r	   r
   ÚinfoR   s    zaddinfo.infoN)r   r    r!   r"   r   r(   r	   r	   r	   r
   r&   K   s   r&   c               @   s2   e Zd ZdZddd„Zdd„ Zdd„ Zd	d
„ ZdS )Ú
addinfourlz9class to add info() and geturl() methods to an open file.Nc             C   s"   t j| |ƒ || _|| _|| _d S )N)r   r   r'   ÚurlÚcode)r   r   r'   r*   r+   r	   r	   r
   r   X   s    zaddinfourl.__init__c             C   s   | j S )N)r'   )r   r	   r	   r
   r(   ^   s    zaddinfourl.infoc             C   s   | j S )N)r+   )r   r	   r	   r
   Úgetcodea   s    zaddinfourl.getcodec             C   s   | j S )N)r*   )r   r	   r	   r
   Úgeturld   s    zaddinfourl.geturl)N)r   r    r!   r"   r   r(   r,   r-   r	   r	   r	   r
   r)   U   s
   
r)   N)r"   Ú
__future__r   r   r   Zfuture.builtinsr   r   r#   r&   r)   r	   r	   r	   r
   Ú<module>   s   1
