def _url_ip_address(url): # type: (str) -> ipaddress._IPAddressBase try: return ip_address(text_type(url)) except ValueError: host = urlparse(url).hostname return ip_address(text_type(socket.gethostbyname(host)))
def validate_port(recipient_url): # type: (str) -> None port = urlparse(recipient_url).port if port and int(port) not in allowed: raise SecurityError( 'Port of recipient URL {0} not allowed ({1} only)'.format( recipient_url, allowed))
def _url_ip_address(url): # type: (str) -> ipaddress._IPAddressBase try: return ip_address(text_type(url)) except ValueError: host = urlparse(url).hostname return ip_address(text_type(socket.gethostbyname(host)))
def validate_port(recipient_url): # type: (str) -> None port = urlparse(recipient_url).port if port and int(port) not in allowed: raise SecurityError( 'Port of recipient URL {0} not allowed ({1} only)'.format( recipient_url, allowed))
def _ensure_mongodb_uri_compliance(url): parsed_url = urlparse(url) if not parsed_url.scheme.startswith('mongodb'): url = 'mongodb+{}'.format(url) if url == 'mongodb://': url += 'localhost' return url
def _ensure_mongodb_uri_compliance(url): parsed_url = urlparse(url) if not parsed_url.scheme.startswith("mongodb"): url = "mongodb+{}".format(url) if url == "mongodb://": url += "localhost" return url
def _ensure_mongodb_uri_compliance(url): parsed_url = urlparse(url) if not parsed_url.scheme.startswith('mongodb'): url = 'mongodb+{}'.format(url) if url == 'mongodb://': url += 'localhost' return url
def _url_ip_address(url): try: return ip_address(text_type(url)) except ValueError: host = urlparse(url).hostname return ip_address(text_type(socket.gethostbyname(host)))