Пример #1
0
 def test_get_set_event_loop(self):
     set_event_loop(None)
     self.assertIsNone(_hub._current_loop)
     self.assertIsNone(get_event_loop())
     hub = Hub()
     set_event_loop(hub)
     self.assertIs(_hub._current_loop, hub)
     self.assertIs(get_event_loop(), hub)
Пример #2
0
 def test_get_set_event_loop(self):
     set_event_loop(None)
     self.assertIsNone(_hub._current_loop)
     self.assertIsNone(get_event_loop())
     hub = Hub()
     set_event_loop(hub)
     self.assertIs(_hub._current_loop, hub)
     self.assertIs(get_event_loop(), hub)
Пример #3
0
 def test_get_set_event_loop(self):
     set_event_loop(None)
     assert _hub._current_loop is None
     assert get_event_loop() is None
     hub = Hub()
     set_event_loop(hub)
     assert _hub._current_loop is hub
     assert get_event_loop() is hub
Пример #4
0
 def test_get_set_event_loop(self):
     set_event_loop(None)
     assert _hub._current_loop is None
     assert get_event_loop() is None
     hub = Hub()
     set_event_loop(hub)
     assert _hub._current_loop is hub
     assert get_event_loop() is hub
Пример #5
0
    def __init__(self, hub=None, max_clients=10):
        if pycurl is None:
            raise ImportError('The curl client requires the pycurl library.')
        hub = hub or get_event_loop()
        super(CurlClient, self).__init__(hub)
        self.max_clients = max_clients

        self._multi = pycurl.CurlMulti()
        self._multi.setopt(pycurl.M_TIMERFUNCTION, self._set_timeout)
        self._multi.setopt(pycurl.M_SOCKETFUNCTION, self._handle_socket)
        self._curls = [self.Curl() for i in range(max_clients)]
        self._free_list = self._curls[:]
        self._pending = deque()
        self._fds = {}

        self._socket_action = self._multi.socket_action
        self._timeout_check_tref = self.hub.call_repeatedly(
            1.0,
            self._timeout_check,
        )

        # pycurl 7.29.0 workaround
        dummy_curl_handle = pycurl.Curl()
        self._multi.add_handle(dummy_curl_handle)
        self._multi.remove_handle(dummy_curl_handle)
Пример #6
0
 def _establish_connection(self):
     self._debug('establishing connection...')
     conn = self.transport.establish_connection()
     loop = get_event_loop()
     if loop:
         self.transport.register_with_event_loop(conn, loop)
     self._debug('connection established: %r', conn)
     return conn
Пример #7
0
    def __init__(self, hub=None, max_clients=10):
        if pycurl is None:
            raise ImportError('The curl client requires the pycurl library.')
        hub = hub or get_event_loop()
        super(CurlClient, self).__init__(hub)
        self.max_clients = max_clients

        self._multi = pycurl.CurlMulti()
        self._multi.setopt(pycurl.M_TIMERFUNCTION, self._set_timeout)
        self._multi.setopt(pycurl.M_SOCKETFUNCTION, self._handle_socket)
        self._curls = [self.Curl() for i in range(max_clients)]
        self._free_list = self._curls[:]
        self._pending = deque()
        self._fds = {}

        self._socket_action = self._multi.socket_action
        self._timeout_check_tref = self.hub.call_repeatedly(
            1.0, self._timeout_check,
        )

        # pycurl 7.29.0 workaround
        dummy_curl_handle = pycurl.Curl()
        self._multi.add_handle(dummy_curl_handle)
        self._multi.remove_handle(dummy_curl_handle)
Пример #8
0
 def setup(self):
     self._prev_loop = get_event_loop()
Пример #9
0
 def setup(self):
     self._prev_loop = get_event_loop()