σ
]'v_c           @@  sk  d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l m Z m	 Z
 d  d l Z d  d l Z y$ d  d l m Z d  d l m Z Wn1 e k
 rΡ d  d l m Z d  d l m Z n Xy d  d l Z e j Z Wn3 e e f k
 r d Z d e f d     YZ n Xy
 e Z Wn' e k
 rTd e f d	     YZ n Xd
 d l m Z m Z m Z m  Z  d
 d l! m" Z" d
 d l# m$ Z$ m% Z% m& Z& m' Z' d
 d l( m) Z) i d d 6d d 6Z* e j+ d d
 d
  Z, d e- f d     YZ. e j/ d  Z0 d e e- f d     YZ d e f d     YZ1 d e1 f d     YZ2 e rae1 Z3 e2 Z1 n e. Z1 d S(   i    (   t   absolute_importN(   t   errort   timeout(   t   HTTPConnection(   t   HTTPExceptiont   BaseSSLErrorc           B@  s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s6   /usr/lib/python2.7/dist-packages/urllib3/connection.pyR      s   t   ConnectionErrorc           B@  s   e  Z RS(    (   R   R   (    (    (    s6   /usr/lib/python2.7/dist-packages/urllib3/connection.pyR       s   i   (   t   NewConnectionErrort   ConnectTimeoutErrort   SubjectAltNameWarningt   SystemTimeWarning(   t   match_hostname(   t   resolve_cert_reqst   resolve_ssl_versiont   ssl_wrap_sockett   assert_fingerprint(   t
   connectioniP   t   httpi»  t   httpsiή  t   DummyConnectionc           B@  s   e  Z d  Z RS(   s-   Used to detect a failed ConnectionCls import.(   R   R   t   __doc__(    (    (    s6   /usr/lib/python2.7/dist-packages/urllib3/connection.pyR   >   s   s   [^-!#$%&'*+.^_`|~0-9a-zA-Z]R   c           B@  sc   e  Z d  Z e d Z e j e j d f g Z e	 Z
 d   Z d   Z d   Z d   Z d   Z RS(   s{  
    Based on httplib.HTTPConnection but provides an extra constructor
    backwards-compatibility layer between older and newer Pythons.

    Additional keyword parameters are used to configure attributes of the connection.
    Accepted parameters include:

      - ``strict``: See the documentation on :class:`urllib3.connectionpool.HTTPConnectionPool`
      - ``source_address``: Set the source address for the current connection.

        .. note:: This is ignored for Python 2.6. It is only applied for 2.7 and 3.x

      - ``socket_options``: Set specific options on the underlying socket. If not specified, then
        defaults are loaded from ``HTTPConnection.default_socket_options`` which includes disabling
        Nagle's algorithm (sets TCP_NODELAY to 1) unless the connection is behind a proxy.

        For example, if you wish to enable TCP Keep Alive in addition to the defaults,
        you might pass::

            HTTPConnection.default_socket_options + [
                (socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1),
            ]

        Or you may want to disable the defaults by passing an empty list (e.g., ``[]``).
    R   i   c         O@  s   t  j r | j d d   n  | j d  |  _ t j d k  rP | j d d   n  | j d |  j  |  _	 t
 j |  | |  d  S(   Nt   strictt   source_addressi   i   t   socket_options(   i   i   (   t   sixt   PY3t   popt   Nonet   getR   t   syst   version_infot   default_socket_optionsR   t   _HTTPConnectiont   __init__(   t   selft   argst   kw(    (    s6   /usr/lib/python2.7/dist-packages/urllib3/connection.pyR#   i   s    	c         C@  sΌ   i  } |  j  r |  j  | d <n  |  j r8 |  j | d <n  y( t j |  j |  j f |  j |  } WnU t k
 r t |  d |  j |  j f   n& t	 k
 r· } t
 |  d |   n X| S(   sp    Establish a socket connection and set nodelay settings on it.

        :return: New socket connection.
        R   R   s0   Connection to %s timed out. (connect timeout=%s)s(   Failed to establish a new connection: %s(   R   R   R   t   create_connectiont   hostt   portR   t   SocketTimeoutR
   t   SocketErrorR	   (   R$   t   extra_kwt   connt   e(    (    s6   /usr/lib/python2.7/dist-packages/urllib3/connection.pyt	   _new_conn~   s     		"c         C@  s5   | |  _  t |  d d   r1 |  j   d |  _ n  d  S(   Nt   _tunnel_hosti    (   t   sockt   getattrR   t   _tunnelt	   auto_open(   R$   R-   (    (    s6   /usr/lib/python2.7/dist-packages/urllib3/connection.pyt   _prepare_conn   s    	
c         C@  s   |  j    } |  j |  d  S(   N(   R/   R5   (   R$   R-   (    (    s6   /usr/lib/python2.7/dist-packages/urllib3/connection.pyt   connect€   s    c         O@  sM   t  j |  } | r4 t d | | j   f   n  t j |  | | | |  S(   s   Send a request to the serversA   Method cannot contain non-token characters %r (found at least %r)(   t   _CONTAINS_CONTROL_CHAR_REt   searcht
   ValueErrort   groupR"   t
   putrequest(   R$   t   methodt   urlR%   t   kwargst   match(    (    s6   /usr/lib/python2.7/dist-packages/urllib3/connection.pyR;   ¨   s    (   R   R   R   t   port_by_schemet   default_portt   sockett   IPPROTO_TCPt   TCP_NODELAYR!   t   Falset   is_verifiedR#   R/   R5   R6   R;   (    (    (    s6   /usr/lib/python2.7/dist-packages/urllib3/connection.pyR   E   s   
				t   HTTPSConnectionc           B@  s6   e  Z e d  Z d d d d e j d  Z d   Z RS(   R   c      	   K@  sA   t  j |  | | d | d | | | |  _ | |  _ d |  _ d  S(   NR   R   R   (   R   R#   t   key_filet	   cert_filet	   _protocol(   R$   R(   R)   RH   RI   R   R   R&   (    (    s6   /usr/lib/python2.7/dist-packages/urllib3/connection.pyR#   ·   s
    
		c         C@  s;   |  j    } |  j |  t j | |  j |  j  |  _ d  S(   N(   R/   R5   t   sslt   wrap_socketRH   RI   R1   (   R$   R-   (    (    s6   /usr/lib/python2.7/dist-packages/urllib3/connection.pyR6   Δ   s    N(	   R   R   R@   RA   R   RB   t   _GLOBAL_DEFAULT_TIMEOUTR#   R6   (    (    (    s6   /usr/lib/python2.7/dist-packages/urllib3/connection.pyRG   ΄   s   
	t   VerifiedHTTPSConnectionc           B@  sS   e  Z d  Z d Z d Z d Z d Z d Z d d d d d d d d  Z	 d   Z
 RS(   s[   
    Based on httplib.HTTPSConnection but wraps the socket with
    SSL certification.
    c         C@  s   | s | r! | d  k r! d } n  | |  _ | |  _ | |  _ | |  _ | |  _ | oc t j j |  |  _	 | o~ t j j |  |  _
 d  S(   Nt   CERT_REQUIRED(   R   RH   RI   t	   cert_reqst   assert_hostnameR   t   ost   patht
   expandusert   ca_certst   ca_cert_dir(   R$   RH   RI   RP   RU   RQ   R   RV   (    (    s6   /usr/lib/python2.7/dist-packages/urllib3/connection.pyt   set_certΥ   s    						c         C@  sΌ  |  j    } t |  j  } t |  j  } |  j } t |  d d   rm | |  _ |  j	   d |  _
 |  j } n  t j j   t k  } | r€ t j d j t  t  n  t | |  j |  j d | d |  j d |  j d | d | |  _ |  j rt |  j j d	 t  |  j  n | t j k r|  j t k	 r|  j j   } | j  d
 d  sit j d j |  t!  n  |  j pu| } | j" d  } t# | |  n  | t j$ k p²|  j d  k	 |  _% d  S(   NR0   i    sW   System time is way off (before {0}). This will probably lead to SSL verification errorsRP   RU   RV   t   server_hostnamet   ssl_versiont   binary_formt   subjectAltNamesκ   Certificate for {0} has no `subjectAltName`, falling back to check for a `commonName` for now. This feature is being removed by major browsers and deprecated by RFC 2818. (See https://github.com/shazow/urllib3/issues/497 for details.)s   [](    (&   R/   R   RP   R   RY   R(   R2   R   R1   R3   R4   R0   t   datetimet   datet   todayt   RECENT_DATEt   warningst   warnt   formatR   R   RH   RI   RU   RV   R   t   getpeercertt   TrueRK   t	   CERT_NONERQ   RE   R   R   t   stripR   RO   RF   (   R$   R-   t   resolved_cert_reqst   resolved_ssl_versiont   hostnamet   is_time_offt   certt   asserted_hostname(    (    s6   /usr/lib/python2.7/dist-packages/urllib3/connection.pyR6   ε   sJ    		
	
			
	N(   R   R   R   R   RP   RU   RV   RY   R   RW   R6   (    (    (    s6   /usr/lib/python2.7/dist-packages/urllib3/connection.pyRN   Κ   s   (4   t
   __future__R    t   reR\   RR   R   RB   R   R+   R   R*   R`   R   t   http.clientR   R"   R   t   ImportErrort   httplibRK   t   SSLErrorR   t   AttributeErrorR   t   BaseExceptionR   t	   NameErrort	   Exceptiont
   exceptionsR	   R
   R   R   t   packages.ssl_match_hostnameR   t	   util.ssl_R   R   R   R   t   utilR   R@   R]   R_   t   objectR   t   compileR7   RG   RN   t   UnverifiedHTTPSConnection(    (    (    s6   /usr/lib/python2.7/dist-packages/urllib3/connection.pyt   <module>   sR   
""
o_	