def _apply_base_uri(self, uri): assert uri parsed = urlsplit(uri) if parsed.scheme is None: self.__secure = None self.__verify = None self.__scheme = None else: self.__scheme = parsed.scheme if self.__scheme in [ "bolt+s", "bolt+ssc", "https", "http+s", "http+ssc" ]: self.__secure = True elif self.__scheme in ["bolt", "http"]: self.__secure = False else: raise ValueError("Unsupported scheme %r " "(for routing, use routing=True)" % self.__scheme) if self.__scheme in ["bolt+ssc", "http+ssc"]: self.__verify = False else: self.__verify = True self.__user = parsed.username or None self.__password = parsed.password or None netloc = parsed.netloc if "@" in netloc: self.__address = Address.parse(netloc.partition("@")[-1]) else: self.__address = Address.parse(netloc)
def addresses(self): addresses = { "neo4j": Address(("localhost", self.bolt_port)), "bolt": Address(("localhost", self.bolt_port)), "http": Address(("localhost", self.http_port)), } if self.service.secured: addresses["neo4j+s"] = Address(("localhost", self.bolt_port)) addresses["neo4j+ssc"] = Address(("localhost", self.bolt_port)) addresses["bolt+s"] = Address(("localhost", self.bolt_port)) addresses["bolt+ssc"] = Address(("localhost", self.bolt_port)) addresses["https"] = Address(("localhost", self.https_port)) addresses["http+s"] = Address(("localhost", self.https_port)) addresses["http+ssc"] = Address(("localhost", self.https_port)) return addresses
def _apply_base_defaults(self): self.__secure = None self.__verify = None self.__scheme = None self.__user = None self.__password = None self.__address = Address.parse("")
def _apply_components(self, **settings): self.__secure = self._coalesce(settings.get("secure"), self.secure, NEO4J_SECURE) self.__verify = self._coalesce(settings.get("verify"), self.verify, NEO4J_VERIFY) self.__scheme = self._coalesce(settings.get("scheme"), self.scheme) self.__user = self._coalesce(settings.get("user"), self.user) self.__password = self._coalesce(settings.get("password"), self.password) if "address" in settings: address = settings.get("address") if isinstance(address, tuple): self.__address = Address(address) else: self.__address = Address.parse(settings.get("address")) if "host" in settings and "port" in settings: self.__address = Address.parse("%s:%s" % (settings.get("host"), settings.get("port"))) elif "host" in settings: self.__address = Address.parse("%s:%s" % (settings.get("host"), self.port)) elif "port" in settings: self.__address = Address.parse("%s:%s" % (self.host, settings.get("port")))
def _apply_base_uri(self, uri): assert uri parsed = urlsplit(uri) if parsed.scheme is not None: self.__scheme = parsed.scheme if self.__scheme in [ "bolt+s", "bolt+ssc", "https", "http+s", "http+ssc" ]: self.__secure = True elif self.__scheme in ["bolt", "http"]: self.__secure = False if self.__scheme in ["bolt+ssc", "http+ssc"]: self.__verify = False else: self.__verify = True self.__user = parsed.username or None self.__password = parsed.password or None netloc = parsed.netloc if "@" in netloc: self.__address = Address.parse(netloc.partition("@")[-1]) else: self.__address = Address.parse(netloc)
def _apply_fallback_defaults(self): if not self.user: self.__user = DEFAULT_USER if not self.password: self.__password = DEFAULT_PASSWORD if not self.address.port: bits = list(self.address) if self.scheme == "http": bits[1] = DEFAULT_HTTP_PORT elif self.scheme in ("https", "http+s", "http+ssc"): bits[1] = DEFAULT_HTTPS_PORT else: bits[1] = DEFAULT_BOLT_PORT self.__address = Address(bits)
def _get_instance_by_address(self, address): address = Address((address.host, address.port_number)) for instance in self.instances: if instance.addresses["bolt"] == address: return instance
def test_address_parse_ipv6(): parsed = Address.parse("[::1]:7687") assert parsed.family == AF_INET6 assert parsed.host == "::1" assert parsed.port_number == 7687
def test_address_parse_ipv4(): parsed = Address.parse("127.0.0.1:7687") assert parsed.family == AF_INET assert parsed.host == "127.0.0.1" assert parsed.port_number == 7687