mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-10 23:42:37 -07:00
Update websocket-client to 0.57.0
This commit is contained in:
parent
4ae09774f7
commit
060dff0162
16 changed files with 1153 additions and 5423 deletions
|
@ -20,8 +20,12 @@ Copyright (C) 2010 Hiroki Ohtani(liris)
|
|||
|
||||
"""
|
||||
|
||||
from six.moves.urllib.parse import urlparse
|
||||
import os
|
||||
import socket
|
||||
import struct
|
||||
|
||||
from six.moves.urllib.parse import urlparse
|
||||
|
||||
|
||||
__all__ = ["parse_url", "get_proxy_info"]
|
||||
|
||||
|
@ -66,24 +70,55 @@ def parse_url(url):
|
|||
if parsed.query:
|
||||
resource += "?" + parsed.query
|
||||
|
||||
return (hostname, port, resource, is_secure)
|
||||
return hostname, port, resource, is_secure
|
||||
|
||||
|
||||
DEFAULT_NO_PROXY_HOST = ["localhost", "127.0.0.1"]
|
||||
|
||||
|
||||
def _is_ip_address(addr):
|
||||
try:
|
||||
socket.inet_aton(addr)
|
||||
except socket.error:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
def _is_subnet_address(hostname):
|
||||
try:
|
||||
addr, netmask = hostname.split("/")
|
||||
return _is_ip_address(addr) and 0 <= int(netmask) < 32
|
||||
except ValueError:
|
||||
return False
|
||||
|
||||
|
||||
def _is_address_in_network(ip, net):
|
||||
ipaddr = struct.unpack('I', socket.inet_aton(ip))[0]
|
||||
netaddr, bits = net.split('/')
|
||||
netmask = struct.unpack('I', socket.inet_aton(netaddr))[0] & ((2 << int(bits) - 1) - 1)
|
||||
return ipaddr & netmask == netmask
|
||||
|
||||
|
||||
def _is_no_proxy_host(hostname, no_proxy):
|
||||
if not no_proxy:
|
||||
v = os.environ.get("no_proxy", "").replace(" ", "")
|
||||
no_proxy = v.split(",")
|
||||
if v:
|
||||
no_proxy = v.split(",")
|
||||
if not no_proxy:
|
||||
no_proxy = DEFAULT_NO_PROXY_HOST
|
||||
|
||||
return hostname in no_proxy
|
||||
if hostname in no_proxy:
|
||||
return True
|
||||
elif _is_ip_address(hostname):
|
||||
return any([_is_address_in_network(hostname, subnet) for subnet in no_proxy if _is_subnet_address(subnet)])
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def get_proxy_info(hostname, is_secure,
|
||||
proxy_host=None, proxy_port=0, proxy_auth=None, no_proxy=None):
|
||||
def get_proxy_info(
|
||||
hostname, is_secure, proxy_host=None, proxy_port=0, proxy_auth=None,
|
||||
no_proxy=None, proxy_type='http'):
|
||||
"""
|
||||
try to retrieve proxy host and port from environment
|
||||
if not provided in options.
|
||||
|
@ -100,9 +135,12 @@ def get_proxy_info(hostname, is_secure,
|
|||
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 infomation.
|
||||
"http_proxy_auth" - http proxy auth information.
|
||||
tuple of username and password.
|
||||
defualt is None
|
||||
default is None
|
||||
"proxy_type" - if set to "socks5" PySocks wrapper
|
||||
will be used in place of a http proxy.
|
||||
default is "http"
|
||||
"""
|
||||
if _is_no_proxy_host(hostname, no_proxy):
|
||||
return None, 0, None
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue