Example #1
0
    def __new__(cls, uri, **config):
        cls._check_uri(uri)
        if SocketAddress.parse_routing_context(uri):
            raise ValueError(
                "Parameters are not supported with scheme 'bolt'. Given URI: '%s'."
                % uri)
        instance = object.__new__(cls)
        # We keep the address containing the host name or IP address exactly
        # as-is from the original URI. This means that every new connection
        # will carry out DNS resolution, leading to the possibility that
        # the connection pool may contain multiple IP address keys, one for
        # an old address and one for a new address.
        instance.address = SocketAddress.from_uri(uri, DEFAULT_PORT)
        instance.security_plan = security_plan = SecurityPlan.build(**config)
        instance.encrypted = security_plan.encrypted

        def connector(address, error_handler):
            return connect(address, security_plan.ssl_context, error_handler,
                           **config)

        pool = DirectConnectionPool(connector, instance.address, **config)
        pool.release(pool.acquire())
        instance._pool = pool
        instance._max_retry_time = config.get("max_retry_time",
                                              default_config["max_retry_time"])
        return instance
Example #2
0
    def __init__(self, uri, **config):
        self.initial_address = initial_address = SocketAddress.from_uri(
            uri, DEFAULT_PORT)
        self.security_plan = security_plan = SecurityPlan.build(**config)
        self.encrypted = security_plan.encrypted
        routing_context = SocketAddress.parse_routing_context(uri)
        if not security_plan.routing_compatible:
            # this error message is case-specific as there is only one incompatible
            # scenario right now
            raise ValueError(
                "TRUST_ON_FIRST_USE is not compatible with routing")

        def connector(address, error_handler):
            return connect(address, security_plan.ssl_context, error_handler,
                           **config)

        pool = RoutingConnectionPool(connector, initial_address,
                                     routing_context, initial_address,
                                     **config)
        try:
            pool.update_routing_table()
        except:
            pool.close()
            raise
        else:
            Driver.__init__(self, pool, **config)
Example #3
0
    def __new__(cls, uri, **config):
        cls._check_uri(uri)
        instance = object.__new__(cls)
        instance.initial_address = initial_address = SocketAddress.from_uri(
            uri, DEFAULT_PORT)
        instance.security_plan = security_plan = SecurityPlan.build(**config)
        instance.encrypted = security_plan.encrypted
        routing_context = SocketAddress.parse_routing_context(uri)
        if not security_plan.routing_compatible:
            # this error message is case-specific as there is only one incompatible
            # scenario right now
            raise ValueError(
                "TRUST_ON_FIRST_USE is not compatible with routing")

        def connector(address, error_handler):
            return connect(address, security_plan.ssl_context, error_handler,
                           **config)

        pool = RoutingConnectionPool(connector, initial_address,
                                     routing_context, initial_address,
                                     **config)
        try:
            pool.update_routing_table()
        except:
            pool.close()
            raise
        else:
            instance._pool = pool
            instance._max_retry_time = config.get(
                "max_retry_time", default_config["max_retry_time"])
            return instance
Example #4
0
 def __init__(self, uri, **config):
     # We keep the address containing the host name or IP address exactly
     # as-is from the original URI. This means that every new connection
     # will carry out DNS resolution, leading to the possibility that
     # the connection pool may contain multiple IP address keys, one for
     # an old address and one for a new address.
     if SocketAddress.parse_routing_context(uri):
         raise ValueError("Parameters are not supported with scheme 'bolt'. Given URI: '%s'." % uri)
     self.address = SocketAddress.from_uri(uri, DEFAULT_PORT)
     self.security_plan = security_plan = SecurityPlan.build(**config)
     self.encrypted = security_plan.encrypted
     pool = DirectConnectionPool(lambda a: connect(a, security_plan.ssl_context, **config), self.address)
     pool.release(pool.acquire())
     Driver.__init__(self, pool, **config)
def verify_routing_context(expected, uri):
    context = SocketAddress.parse_routing_context(uri)
    assert context == expected
 def test_should_error_when_key_duplicate(self):
     with self.assertRaises(ValueError):
         SocketAddress.parse_routing_context("bolt+routing://127.0.0.1/?name=molly&name=white")
 def test_should_error_when_value_missing(self):
     with self.assertRaises(ValueError):
         SocketAddress.parse_routing_context("bolt+routing://127.0.0.1/?name=&color=white")