Beispiel #1
0
 def _async(future, loop):
     # trollius iscoroutine() accepts trollius and asyncio coroutine
     # objects
     if trollius.iscoroutine(future):
         return _create_task(future, loop)
     else:
         return future
Beispiel #2
0
    def run_event(self):
        """get the asyncio.Event or threading.Event"""

        cf = inspect.currentframe()
        caller_name = cf.f_back.f_code.co_name
        caller = cf.f_back.f_globals[caller_name]
        if asyncio.iscoroutinefunction(caller) or asyncio.iscoroutine(caller):
            return self._aio_run_event
        else:
            return self._thr_run_event
Beispiel #3
0
    def run_event(self):
        """get the asyncio.Event or threading.Event"""

        cf = inspect.currentframe()
        caller_name = cf.f_back.f_code.co_name
        caller = cf.f_back.f_globals[caller_name]
        if asyncio.iscoroutinefunction(caller) or asyncio.iscoroutine(caller):
            return self._aio_run_event
        else:
            return self._thr_run_event
Beispiel #4
0
    def write_body(self, file, length=None):
        '''Send the request's content body.

        Coroutine.
        '''
        _logger.debug('Sending body.')

        file_is_async = (trollius.iscoroutine(file.read) or
                         trollius.iscoroutinefunction(file.read))

        _logger.debug(__('Body is async: {0}', file_is_async))

        if length is not None:
            bytes_left = length

        while True:
            if length is not None:
                if bytes_left <= 0:
                    break
                read_size = min(bytes_left, self._read_size)
            else:
                read_size = self._read_size

            if file_is_async:
                data = yield From(file.read(read_size))
            else:
                data = file.read(read_size)

            if not data:
                break

            self._data_observer.notify('request_body', data)

            if bytes_left <= self._read_size:
                # XXX: Connection lost is raised too early on Python 3.2, 3.3
                # so don't flush on the last chunk but check for connection
                # closed on reads
                drain = False
            else:
                drain = True

            yield From(self._connection.write(data, drain=drain))

            if length is not None:
                bytes_left -= len(data)
Beispiel #5
0
    def write_body(self, file, length=None):
        '''Send the request's content body.

        Coroutine.
        '''
        _logger.debug('Sending body.')

        file_is_async = (trollius.iscoroutine(file.read) or
                         trollius.iscoroutinefunction(file.read))

        _logger.debug(__('Body is async: {0}', file_is_async))

        if length is not None:
            bytes_left = length

        while True:
            if length is not None:
                if bytes_left <= 0:
                    break
                read_size = min(bytes_left, self._read_size)
            else:
                read_size = self._read_size

            if file_is_async:
                data = yield From(file.read(read_size))
            else:
                data = file.read(read_size)

            if not data:
                break

            self._data_observer.notify('request_body', data)

            if bytes_left <= self._read_size:
                # XXX: Connection lost is raised too early on Python 3.2, 3.3
                # so don't flush on the last chunk but check for connection
                # closed on reads
                drain = False
            else:
                drain = True

            yield From(self._connection.write(data, drain=drain))

            if length is not None:
                bytes_left -= len(data)
 def _coroutine_wrapper(self, func, *args, **kw):
     result = func(*args, **kw)
     if trollius.iscoroutine(result):
         result = aioeventlet.yield_future(result, loop=self._loop)
     return result
 def _coroutine_wrapper(self, func, *args, **kw):
     result = func(*args, **kw)
     if trollius.iscoroutine(result):
         result = aioeventlet.yield_future(result, loop=self._loop)
     return result