
    c                     f    d Z ddlZddlZddlZddlmZ ddgZd ZddgZd	 Z	d
 Z
d Zd Z	 	 ddZy)aL  
websocket - WebSocket client library for Python

Copyright (C) 2010 Hiroki Ohtani(liris)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA  02110-1335  USA

    N)urlparse	parse_urlget_proxy_infoc                    d| vrt        d      | j                  dd      \  }} t        | d      }|j                  r|j                  }nt        d      d}|j                  r|j                  }d}|dk(  r|sd	}n|d
k(  rd}|sd}nt        d|z        |j
                  r|j
                  }nd}|j                  r|d|j                  z   z  }||||fS )z
    parse url and the result is tuple of
    (hostname, port, resource path and the flag of secure mode)

    url: url string.
    :zurl is invalid   ws)schemezhostname is invalidr   FP   wssTi  zscheme %s is invalid/?)
ValueErrorsplitr   hostnameportpathquery)urlr
   parsedr   r   	is_secureresources          !lib/third_party/websocket/_url.pyr   r   !   s     #~)**))C#KFCc$'F??.//D{{{{I~D	5	D/&899{{;;||C&,,&&T8Y..    	localhostz	127.0.0.1c                 b    	 t        j                  |        y# t         j                  $ r Y yw xY w)NTF)socket	inet_atonerror)addrs    r   _is_ip_addressr!   O   s2      << s    ..c                     	 | j                  d      \  }}t        |      xr dt        |      cxk  xr dk  S c S # t        $ r Y yw xY w)Nr   r       F)r   r!   intr   )r   r    netmasks      r   _is_subnet_addressr&   X   sO     s+gd#>S\(>B(>>(>> s   6< < 	AAc                    t        j                  dt        j                  |             d   }|j	                  d      \  }}t        j                  dt        j                  |            d   dt        |      dz
  z  dz
  z  }||z  |k(  S )NIr   r      r   )structunpackr   r   r   r$   )ipnetipaddrnetaddrbitsr%   s         r   _is_address_in_networkr1   `   s|    ]]3 0 0 45a8FIIcNMGTmmC!1!1'!:;A>1D	TUCUYZBZ[GGw&&r   c           	      "   |sAt         j                  j                  dd      j                  dd      }|j	                  d      }|st
        }| |v ryt        |       r/t        |D cg c]  }t        |      st        | |       c}      S yc c}w )Nno_proxy  ,TF)
osenvirongetreplacer   DEFAULT_NO_PROXY_HOSTr!   anyr&   r1   )r   r3   vsubnets       r   _is_no_proxy_hostr?   g   s    JJNN:r*223;773<(8		!8r8WijpWq*8V<8rss ss   %B6Bc                 L   t        | |      ry|r	|}|}|||fS dg}	|r|	j                  dd       |	D ]p  }
t        j                  j	                  |
d      }|s&t        |      }|j                  r|j                  |j                  fnd}|j                  |j                  |fc S  y)a  
    try to retrieve proxy host and port from environment
    if not provided in options.
    result is (proxy_host, proxy_port, proxy_auth).
    proxy_auth is tuple of username and password
     of proxy authentication information.

    hostname: websocket server name.

    is_secure:  is the connection secure? (wss)
                looks for "https_proxy" in env
                before falling back to "http_proxy"

    options:    "http_proxy_host" - http proxy host name.
                "http_proxy_port" - http proxy port.
                "http_no_proxy"   - host names, which doesn't use proxy.
                "http_proxy_auth" - http proxy auth information.
                                    tuple of username and password.
                                    default is None
                "proxy_type"      - if set to "socks5" PySocks wrapper
                                    will be used in place of a http proxy.
                                    default is "http"
    )Nr   N
http_proxyr   https_proxyN)
r?   insertr7   r8   r9   r   usernamepasswordr   r   )r   r   
proxy_host
proxy_port
proxy_authr3   
proxy_typer   authenv_keyskeyvalueproxys                r   r   r   v   s    4 8,4%%~H=)

sD)UOE7<~~ENNENN34D>>5::t33  r   )Nr   NNhttp)__doc__r7   r   r*   six.moves.urllib.parser   __all__r   r;   r!   r&   r1   r?   r    r   r   <module>rT      s[   , 
   + (
)(/V %k2 '  HL"(-r   