Esempio n. 1
0
 def test_max_redirects_validator_when_negative(self):
     with pytest.raises(
             ValueError,
             match=
             r"http_settings.max_redirects must be None or a POSITIVE integer"
     ):
         config_.HTTPSettings(max_redirects=-1)
Esempio n. 2
0
    def __init__(
        self,
        token: typing.Union[str, rest_api.TokenStrategy],
        token_type: typing.Union[applications.TokenType, str, None] = None,
        public_key: typing.Union[bytes, str, None] = None,
        *,
        allow_color: bool = True,
        banner: typing.Optional[str] = "hikari",
        executor: typing.Optional[concurrent.futures.Executor] = None,
        force_color: bool = False,
        http_settings: typing.Optional[config_impl.HTTPSettings] = None,
        logs: typing.Union[None, int, str, typing.Dict[str, typing.Any]] = "INFO",
        max_rate_limit: float = 300.0,
        max_retries: int = 3,
        proxy_settings: typing.Optional[config_impl.ProxySettings] = None,
        rest_url: typing.Optional[str] = None,
    ) -> None:
        if isinstance(public_key, str):
            public_key = bytes.fromhex(public_key)

        if isinstance(token, str):
            token = token.strip()

        # Beautification and logging
        ux.init_logging(logs, allow_color, force_color)
        self.print_banner(banner, allow_color, force_color)

        # Settings and state
        self._close_event: typing.Optional[asyncio.Event] = None
        self._executor = executor
        self._http_settings = http_settings if http_settings is not None else config_impl.HTTPSettings()
        self._is_closing = False
        self._proxy_settings = proxy_settings if proxy_settings is not None else config_impl.ProxySettings()

        # Entity creation
        self._entity_factory = entity_factory_impl.EntityFactoryImpl(self)

        # RESTful API.
        self._rest = rest_impl.RESTClientImpl(
            cache=None,
            entity_factory=self._entity_factory,
            executor=self._executor,
            http_settings=self._http_settings,
            max_rate_limit=max_rate_limit,
            max_retries=max_retries,
            proxy_settings=self._proxy_settings,
            rest_url=rest_url,
            token=token,
            token_type=token_type,
        )

        # IntegrationServer
        self._server = interaction_server_impl.InteractionServer(
            entity_factory=self._entity_factory,
            public_key=public_key,
            rest_client=self._rest,
        )
Esempio n. 3
0
    def test_ssl(self):
        mock_ssl = ssl.create_default_context()
        config = config_.HTTPSettings(ssl=mock_ssl)

        assert config.ssl is mock_ssl
Esempio n. 4
0
 def test_max_redirects_validator(self, value):
     config_.HTTPSettings(max_redirects=value)