3 gY@sndZddlZddlZddlZddlmZddgZddZddgZd d Z d d Z d dZ ddZ dddZ dS)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_urlget_proxy_infocCsd|krtd|jdd\}}t|dd}|jr:|j}ntdd}|jrR|j}d}|dkrh|sd }n"|d kr~d }|sd }n td ||jr|j}nd}|jr|d|j7}||||fS)z parse url and the result is tuple of (hostname, port, resource path and the flag of secure mode) url: url string. :zurl is invalidws)schemezhostname is invalidrFPwssTizscheme %s is invalid/?) ValueErrorsplitrhostnameportpathquery)urlrparsedrr is_secureresourcer?/Users/olari/OneDrive/sandbox/awsBlog2/lambda/websocket/_url.pyr!s2   localhostz 127.0.0.1c Cs.ytj|Wntjk r$dSXdSdS)NFT)socket inet_atonerror)addrrrr_is_ip_addressOs rc CsLy2|jd\}}t|o2dt|ko.dkSStk rFdSXdS)Nr r F)rrintr )rrnetmaskrrr_is_subnet_addressXs $r"cCsZtjdtj|d}|jd\}}tjdtj|ddt|d>d@}||@|kS)NIrr r)structunpackrrrr )ipnetipaddrnetaddrbitsr!rrr_is_address_in_network`s*r,csZ|s$tjjddjdd}|jd}|s,t}|kr8dStrVtfdd|DSdS) Nno_proxy ,Tcsg|]}t|rt|qSr)r"r,).0Zsubnet)rrr qsz%_is_no_proxy_host..F)osenvirongetreplacerDEFAULT_NO_PROXY_HOSTrany)rr-vr)rr_is_no_proxy_hostgs r:c Cst||rdS|r$|}|}|||fSdg}|r:|jddxJ|D]B} tjj| d} | r@t| } | jrp| j| jfnd}| j| j |fSq@WdS)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 NrZ http_proxyZ https_proxy)NrN)NrN) r:insertr3r4r5rusernamepasswordrr) rrZ proxy_hostZ proxy_port proxy_authr-rauthZenv_keyskeyvalueproxyrrrrvs     )NrNN)__doc__r3rr%six.moves.urllib.parser__all__rr7rr"r,r:rrrrrs +