Пример #1
0
    def test_conn_noname_err(self):
        client = HttpClient(loop=self.loop)
        exchange = client.exchange()
        @on(exchange)
        def error(err_msg):
            self.assertEqual(err_msg.__class__, thor.http.error.ConnectError)
            self.loop.stop()

        req_uri = b"http://foo.bar/conn_noname_err"
        exchange.request_start(b"GET", req_uri, [])
        exchange.request_done([])
Пример #2
0
    def test_url_port_range(self):
        client = HttpClient(loop=self.loop)
        exchange = client.exchange()
        @on(exchange)
        def error(err_msg):
            self.assertEqual(err_msg.__class__, thor.http.error.UrlError)
            self.loop.stop()

        req_uri = b"http://%s:80000/" % (test_host)
        exchange.request_start(b"GET", req_uri, [])
        exchange.request_done([])
Пример #3
0
    def test_url_long_hostname(self):
        client = HttpClient(loop=self.loop)
        exchange = client.exchange()
        @on(exchange)
        def error(err_msg):
            self.assertEqual(err_msg.__class__, thor.http.error.UrlError)
            self.loop.stop()

        req_uri = b"http://wwww.%s.example.com:80000/" % (b"t" * 64)
        exchange.request_start(b"GET", req_uri, [])
        exchange.request_done([])
Пример #4
0
    def test_url_startingdigit_label(self):
        client = HttpClient(loop=self.loop)
        exchange = client.exchange()
        @on(exchange)
        def error(err_msg):
            self.assertEqual(err_msg.__class__, thor.http.error.UrlError)
            self.loop.stop()

        req_uri = b"http://www.5test.example.com:80000/"
        exchange.request_start(b"GET", req_uri, [])
        exchange.request_done([])
Пример #5
0
    def test_url_nonascii_host(self):
        client = HttpClient(loop=self.loop)
        exchange = client.exchange()
        @on(exchange)
        def error(err_msg):
            self.assertEqual(err_msg.__class__, thor.http.error.UrlError)
            self.loop.stop()

        req_uri = "http://www.ü.example.com:80000/".encode("utf-8")
        exchange.request_start(b"GET", req_uri, [])
        exchange.request_done([])
Пример #6
0
    def test_url_unsupported_scheme(self):
        client = HttpClient(loop=self.loop)
        exchange = client.exchange()
        @on(exchange)
        def error(err_msg):
            self.assertEqual(err_msg.__class__, thor.http.error.UrlError)
            self.loop.stop()

        req_uri = b"notascheme://www.example.com:80000/"
        exchange.request_start(b"GET", req_uri, [])
        exchange.request_done([])
Пример #7
0
class HeaderGetter(EventEmitter):
    "Get the specified header for a single ip:port."
    connect_timeout = 3
    wait_timeout = 5

    def __init__(self, header):
        """
        Given an IP address and port, try the magic on it, emitting a 'result' event.
        """
        EventEmitter.__init__(self)
        self.header = header.lower()
        self.client = HttpClient()
        self.client.connect_timeout = self.connect_timeout
        self.client.read_timeout = self.wait_timeout
        self.client.idle_timeout = 0 # Don't need no steenkin pconns

    def check(self, host, port):
        x = self.client.exchange()        

        @on(x)
        def response_start(status, phrase, headers):
            header = ", ".join(header_dict(headers).get(self.header, ['-']))
            self.emit("result", "OK", header, host, port)
            if x.tcp_conn:
                x.tcp_conn.close()
            
        @on(x)
        def error(err):
            self.emit("result", "ERR", err.desc, host, port)
            if x.tcp_conn:
                x.tcp_conn.close()
                
        x.request_start("HEAD", "http://%s/" % host, [("User-Agent", UA)])
        x.request_done([])
Пример #8
0
 def __init__(self, header):
     """
     Given an IP address and port, try the magic on it, emitting a 'result' event.
     """
     EventEmitter.__init__(self)
     self.header = header.lower()
     self.client = HttpClient()
     self.client.connect_timeout = self.connect_timeout
     self.client.read_timeout = self.wait_timeout
     self.client.idle_timeout = 0 # Don't need no steenkin pconns
Пример #9
0
 def create_client(self, host, port, client_side):
     client = HttpClient(loop=self.loop)
     client.connect_timeout = 1
     client_side(client)
Пример #10
0
import hmac
from http import cookies
import json
from typing import Callable, TYPE_CHECKING
from urllib.parse import urlencode

import thor
from thor.http import HttpClient, get_header
from thor.http.error import HttpError

from redbot.resource import HttpResource
from redbot.type import RawHeaderListType

token_client = HttpClient()
token_client.idle_timeout = 30
token_client.connect_timeout = 10
token_client.read_timeout = 10
token_client.max_server_conn = 30

if TYPE_CHECKING:
    from redbot.webui import RedWebUi  # pylint: disable=cyclic-import,unused-import


class CaptchaHandler:
    def __init__(
        self,
        webui: "RedWebUi",
        client_id: str,
        continue_test: Callable,
        error_response: Callable,
    ) -> None: