Пример #1
0
    def __init__(self, profile=None, **settings):
        # TODO: recognise IPv6 addresses explicitly
        self.__protocol = DEFAULT_PROTOCOL
        self.__secure = DEFAULT_SECURE
        self.__verify = DEFAULT_VERIFY
        self.__user = DEFAULT_USER
        self.__password = DEFAULT_PASSWORD
        self.__address = Address.parse("")

        self._apply_env_vars()

        if profile is None:
            pass
        elif isinstance(profile, string_types):
            self._apply_uri(profile)
        elif isinstance(profile, self.__class__):
            self._apply_settings(**{k: profile[k] for k in self._hash_keys})
        elif isinstance(profile, Mapping):
            self._apply_settings(**profile)
        else:
            raise TypeError("Profile %r is neither a ConnectionProfile "
                            "nor a string URI" % profile)

        self._apply_settings(**settings)

        if not self.address.port:
            addr = list(self.address)
            if self.protocol == "http":
                addr[1] = DEFAULT_HTTPS_PORT if self.secure else DEFAULT_HTTP_PORT
            else:
                addr[1] = DEFAULT_BOLT_PORT
            self.__address = Address(addr)
Пример #2
0
def test_parsing_ipv6_address_with_named_port():
    a = Address.parse("[::1]:http")
    assert isinstance(a, IPv6Address)
    assert a.host == "::1"
    assert a.port == "http"
    assert a.port_number == 80
    assert repr(a)
    assert str(a) == "[::1]:http"
Пример #3
0
def test_parsing_simple_ipv6_address():
    a = Address.parse("[::1]:80")
    assert isinstance(a, IPv6Address)
    assert a.host == "::1"
    assert a.port == 80
    assert a.port_number == 80
    assert repr(a)
    assert str(a) == "[::1]:80"
Пример #4
0
def test_parsing_address_with_named_bolt_port():
    a = Address.parse("localhost:bolt")
    assert isinstance(a, IPv4Address)
    assert a.host == "localhost"
    assert a.port == "bolt"
    assert a.port_number == 7687
    assert repr(a)
    assert str(a) == "localhost:bolt"
Пример #5
0
def test_parsing_address_with_named_port():
    a = Address.parse("localhost:http")
    assert isinstance(a, IPv4Address)
    assert a.host == "localhost"
    assert a.port == "http"
    assert a.port_number == 80
    assert repr(a)
    assert str(a) == "localhost:http"
Пример #6
0
def test_parsing_simple_address():
    a = Address.parse("localhost:80")
    assert isinstance(a, IPv4Address)
    assert a.host == "localhost"
    assert a.port == 80
    assert a.port_number == 80
    assert repr(a)
    assert str(a) == "localhost:80"
Пример #7
0
    def _apply_settings(self, uri=None, scheme=None, protocol=None, secure=None, verify=None,
                        address=None, host=None, port=None, port_number=None,
                        auth=None, user=None, password=None, **other):
        if uri:
            self._apply_uri(uri)

        if scheme:
            self._apply_scheme(scheme)
        if protocol:
            self._apply_protocol(protocol)
        if secure is not None:
            self.__secure = secure
        if verify is not None:
            self.__verify = verify

        if isinstance(address, tuple):
            self.__address = Address(address)
        elif address:
            self.__address = Address.parse(address)
        if host and port:
            self.__address = Address.parse("%s:%s" % (host, port))
        elif host:
            self.__address = Address.parse("%s:%s" % (host, self.port))
        elif port:
            self.__address = Address.parse("%s:%s" % (self.host, port))

        if isinstance(auth, tuple):
            self.__user, self.__password = auth
        elif auth:
            self.__user, _, self.__password = auth.partition(":")
        if user:
            self.__user = user
        if password:
            self.__password = password

        if other:
            raise ValueError("The following settings are not supported: %r" % other)
Пример #8
0
def test_address_from_address():
    a1 = Address.parse("[::1]:http")
    a2 = Address(a1)
    assert a2 is a1