Python errno 模块,WSAEINTR 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用errno.WSAEINTR

项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def writeSomeData(self, data):
        """Connection.writeSomeData(data) -> #of bytes written | CONNECTION_LOST
        This writes as much data as possible to the socket and returns either
        the number of bytes read (which is positive) or a connection error code
        (which is negative)
        """
        try:
            # Limit length of buffer to try to send, because some OSes are too
            # stupid to do so themselves (ahem windows)
            return self.socket.send(buffer(data, 0, self.SEND_LIMIT))
        except socket.error, se:
            if se.args[0] == EINTR:
                return self.writeSomeData(data)
            elif se.args[0] in (EWOULDBLOCK, ENOBUFS):
                return 0
            else:
                return main.CONNECTION_LOST
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def doRead(self):
        """Called when my socket is ready for reading."""
        read = 0
        while read < self.maxThroughput:
            try:
                data, addr = self.socket.recvfrom(self.maxPacketSize)
            except socket.error, se:
                no = se.args[0]
                if no in (EAGAIN, EINTR, EWOULDBLOCK):
                    return
                if (no == ECONNREFUSED) or (platformType == "win32" and no == WSAECONNRESET):
                    if self._connectedAddr:
                        self.protocol.connectionRefused()
                else:
                    raise
            else:
                read += len(data)
                try:
                    self.protocol.datagramReceived(data, addr)
                except:
                    log.err()
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def doRead(self):
        """Called when my socket is ready for reading."""
        read = 0
        while read < self.maxThroughput:
            try:
                data, addr = self.socket.recvfrom(self.maxPacketSize)
                read += len(data)
                self.protocol.datagramReceived(data)
            except socket.error, se:
                no = se.args[0]
                if no in (EAGAIN, EINTR, EWOULDBLOCK):
                    return
                if (no == ECONNREFUSED) or (platformType == "win32" and no == WSAECONNRESET):
                    self.protocol.connectionRefused()
                else:
                    raise
            except:
                log.deferr()
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def writeSomeData(self, data):
        """Connection.writeSomeData(data) -> #of bytes written | CONNECTION_LOST
        This writes as much data as possible to the socket and returns either
        the number of bytes read (which is positive) or a connection error code
        (which is negative)
        """
        try:
            # Limit length of buffer to try to send, because some OSes are too
            # stupid to do so themselves (ahem windows)
            return self.socket.send(buffer(data, 0, self.SEND_LIMIT))
        except socket.error, se:
            if se.args[0] == EINTR:
                return self.writeSomeData(data)
            elif se.args[0] in (EWOULDBLOCK, ENOBUFS):
                return 0
            else:
                return main.CONNECTION_LOST
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def doRead(self):
        """Called when my socket is ready for reading."""
        read = 0
        while read < self.maxThroughput:
            try:
                data, addr = self.socket.recvfrom(self.maxPacketSize)
            except socket.error, se:
                no = se.args[0]
                if no in (EAGAIN, EINTR, EWOULDBLOCK):
                    return
                if (no == ECONNREFUSED) or (platformType == "win32" and no == WSAECONNRESET):
                    if self._connectedAddr:
                        self.protocol.connectionRefused()
                else:
                    raise
            else:
                read += len(data)
                try:
                    self.protocol.datagramReceived(data, addr)
                except:
                    log.err()
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def doRead(self):
        """Called when my socket is ready for reading."""
        read = 0
        while read < self.maxThroughput:
            try:
                data, addr = self.socket.recvfrom(self.maxPacketSize)
                read += len(data)
                self.protocol.datagramReceived(data)
            except socket.error, se:
                no = se.args[0]
                if no in (EAGAIN, EINTR, EWOULDBLOCK):
                    return
                if (no == ECONNREFUSED) or (platformType == "win32" and no == WSAECONNRESET):
                    self.protocol.connectionRefused()
                else:
                    raise
            except:
                log.deferr()
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def write(self, datagram, addr=None):
        """Write a datagram.

        @param addr: should be a tuple (ip, port), can be None in connected mode.
        """
        if self._connectedAddr:
            assert addr in (None, self._connectedAddr)
            try:
                return self.socket.send(datagram)
            except socket.error, se:
                no = se.args[0]
                if no == EINTR:
                    return self.write(datagram)
                elif no == EMSGSIZE:
                    raise error.MessageLengthError, "message too long"
                elif no == ECONNREFUSED:
                    self.protocol.connectionRefused()
                else:
                    raise
        else:
            assert addr != None
            if not addr[0].replace(".", "").isdigit():
                warnings.warn("Please only pass IPs to write(), not hostnames", DeprecationWarning, stacklevel=2)
            try:
                return self.socket.sendto(datagram, addr)
            except socket.error, se:
                no = se.args[0]
                if no == EINTR:
                    return self.write(datagram, addr)
                elif no == EMSGSIZE:
                    raise error.MessageLengthError, "message too long"
                elif no == ECONNREFUSED:
                    # in non-connected UDP ECONNREFUSED is platform dependent, I think
                    # and the info is not necessarily useful. Nevertheless maybe we
                    # should call connectionRefused? XXX
                    return
                else:
                    raise
项目:SameKeyProxy    作者:xzhou    | 项目源码 | 文件源码
def sock_recvmsg(sock, size, timeout=0):
    while True:
        try:
            return _recv_msg(sock,size,timeout)
        except socket.timeout:
            raise TimeoutError("connection timeout receiving")
        except socket.error,x:
            if x.args[0] == errno.EINTR or (hasattr(errno, 'WSAEINTR') and x.args[0] == errno.WSAEINTR):
                # interrupted system call, just retry
                continue
            raise ConnectionClosedError('connection lost: %s' % x)
        except SSLError,x:
            raise ConnectionClosedError('connection lost: %s' % x)

# select the optimal recv() implementation
项目:SameKeyProxy    作者:xzhou    | 项目源码 | 文件源码
def safe_select(r,w,e,timeout=None):
    delay=timeout
    while True:
        try:
            # Make sure we don't delay longer than requested
            start=time.time()
            if delay is not None:
                return _selectfunction(r,w,e,delay)
            else:
                return _selectfunction(r,w,e)
        except select.error,x:
            if x.args[0] == errno.EINTR or (hasattr(errno, 'WSAEINTR') and x.args[0] == errno.WSAEINTR):
                delay=max(0.0,time.time()-start)
            else:
                raise
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def write(self, datagram, addr=None):
        """Write a datagram.

        @param addr: should be a tuple (ip, port), can be None in connected mode.
        """
        if self._connectedAddr:
            assert addr in (None, self._connectedAddr)
            try:
                return self.socket.send(datagram)
            except socket.error, se:
                no = se.args[0]
                if no == EINTR:
                    return self.write(datagram)
                elif no == EMSGSIZE:
                    raise error.MessageLengthError, "message too long"
                elif no == ECONNREFUSED:
                    self.protocol.connectionRefused()
                else:
                    raise
        else:
            assert addr != None
            if not addr[0].replace(".", "").isdigit():
                warnings.warn("Please only pass IPs to write(), not hostnames", DeprecationWarning, stacklevel=2)
            try:
                return self.socket.sendto(datagram, addr)
            except socket.error, se:
                no = se.args[0]
                if no == EINTR:
                    return self.write(datagram, addr)
                elif no == EMSGSIZE:
                    raise error.MessageLengthError, "message too long"
                elif no == ECONNREFUSED:
                    # in non-connected UDP ECONNREFUSED is platform dependent, I think
                    # and the info is not necessarily useful. Nevertheless maybe we
                    # should call connectionRefused? XXX
                    return
                else:
                    raise
项目:my-first-blog    作者:AnkurBegining    | 项目源码 | 文件源码
def _syscall_wrapper(func, recalc_timeout, *args, **kwargs):
        """ Wrapper function for syscalls that could fail due to EINTR.
        All functions should be retried if there is time left in the timeout
        in accordance with PEP 475. """
        timeout = kwargs.get("timeout", None)
        if timeout is None:
            expires = None
            recalc_timeout = False
        else:
            timeout = float(timeout)
            if timeout < 0.0:  # Timeout less than 0 treated as no timeout.
                expires = None
            else:
                expires = monotonic() + timeout

        args = list(args)
        if recalc_timeout and "timeout" not in kwargs:
            raise ValueError(
                "Timeout must be in args or kwargs to be recalculated")

        result = _SYSCALL_SENTINEL
        while result is _SYSCALL_SENTINEL:
            try:
                result = func(*args, **kwargs)
            # OSError is thrown by select.select
            # IOError is thrown by select.epoll.poll
            # select.error is thrown by select.poll.poll
            # Aren't we thankful for Python 3.x rework for exceptions?
            except (OSError, IOError, select.error) as e:
                # select.error wasn't a subclass of OSError in the past.
                errcode = None
                if hasattr(e, "errno"):
                    errcode = e.errno
                elif hasattr(e, "args"):
                    errcode = e.args[0]

                # Also test for the Windows equivalent of EINTR.
                is_interrupt = (errcode == errno.EINTR or (hasattr(errno, "WSAEINTR") and
                                                           errcode == errno.WSAEINTR))

                if is_interrupt:
                    if expires is not None:
                        current_time = monotonic()
                        if current_time > expires:
                            raise OSError(errno=errno.ETIMEDOUT)
                        if recalc_timeout:
                            if "timeout" in kwargs:
                                kwargs["timeout"] = expires - current_time
                    continue
                if errcode:
                    raise SelectorError(errcode)
                else:
                    raise
        return result
项目:googletranslate.popclipext    作者:wizyoung    | 项目源码 | 文件源码
def _syscall_wrapper(func, recalc_timeout, *args, **kwargs):
        """ Wrapper function for syscalls that could fail due to EINTR.
        All functions should be retried if there is time left in the timeout
        in accordance with PEP 475. """
        timeout = kwargs.get("timeout", None)
        if timeout is None:
            expires = None
            recalc_timeout = False
        else:
            timeout = float(timeout)
            if timeout < 0.0:  # Timeout less than 0 treated as no timeout.
                expires = None
            else:
                expires = monotonic() + timeout

        args = list(args)
        if recalc_timeout and "timeout" not in kwargs:
            raise ValueError(
                "Timeout must be in args or kwargs to be recalculated")

        result = _SYSCALL_SENTINEL
        while result is _SYSCALL_SENTINEL:
            try:
                result = func(*args, **kwargs)
            # OSError is thrown by select.select
            # IOError is thrown by select.epoll.poll
            # select.error is thrown by select.poll.poll
            # Aren't we thankful for Python 3.x rework for exceptions?
            except (OSError, IOError, select.error) as e:
                # select.error wasn't a subclass of OSError in the past.
                errcode = None
                if hasattr(e, "errno"):
                    errcode = e.errno
                elif hasattr(e, "args"):
                    errcode = e.args[0]

                # Also test for the Windows equivalent of EINTR.
                is_interrupt = (errcode == errno.EINTR or (hasattr(errno, "WSAEINTR") and
                                                           errcode == errno.WSAEINTR))

                if is_interrupt:
                    if expires is not None:
                        current_time = monotonic()
                        if current_time > expires:
                            raise OSError(errno=errno.ETIMEDOUT)
                        if recalc_timeout:
                            if "timeout" in kwargs:
                                kwargs["timeout"] = expires - current_time
                    continue
                if errcode:
                    raise SelectorError(errcode)
                else:
                    raise
        return result
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def _syscall_wrapper(func, recalc_timeout, *args, **kwargs):
        """ Wrapper function for syscalls that could fail due to EINTR.
        All functions should be retried if there is time left in the timeout
        in accordance with PEP 475. """
        timeout = kwargs.get("timeout", None)
        if timeout is None:
            expires = None
            recalc_timeout = False
        else:
            timeout = float(timeout)
            if timeout < 0.0:  # Timeout less than 0 treated as no timeout.
                expires = None
            else:
                expires = monotonic() + timeout

        args = list(args)
        if recalc_timeout and "timeout" not in kwargs:
            raise ValueError(
                "Timeout must be in args or kwargs to be recalculated")

        result = _SYSCALL_SENTINEL
        while result is _SYSCALL_SENTINEL:
            try:
                result = func(*args, **kwargs)
            # OSError is thrown by select.select
            # IOError is thrown by select.epoll.poll
            # select.error is thrown by select.poll.poll
            # Aren't we thankful for Python 3.x rework for exceptions?
            except (OSError, IOError, select.error) as e:
                # select.error wasn't a subclass of OSError in the past.
                errcode = None
                if hasattr(e, "errno"):
                    errcode = e.errno
                elif hasattr(e, "args"):
                    errcode = e.args[0]

                # Also test for the Windows equivalent of EINTR.
                is_interrupt = (errcode == errno.EINTR or (hasattr(errno, "WSAEINTR") and
                                                           errcode == errno.WSAEINTR))

                if is_interrupt:
                    if expires is not None:
                        current_time = monotonic()
                        if current_time > expires:
                            raise OSError(errno=errno.ETIMEDOUT)
                        if recalc_timeout:
                            if "timeout" in kwargs:
                                kwargs["timeout"] = expires - current_time
                    continue
                if errcode:
                    raise SelectorError(errcode)
                else:
                    raise
        return result
项目:pip-update-requirements    作者:alanhamlett    | 项目源码 | 文件源码
def _syscall_wrapper(func, recalc_timeout, *args, **kwargs):
        """ Wrapper function for syscalls that could fail due to EINTR.
        All functions should be retried if there is time left in the timeout
        in accordance with PEP 475. """
        timeout = kwargs.get("timeout", None)
        if timeout is None:
            expires = None
            recalc_timeout = False
        else:
            timeout = float(timeout)
            if timeout < 0.0:  # Timeout less than 0 treated as no timeout.
                expires = None
            else:
                expires = monotonic() + timeout

        args = list(args)
        if recalc_timeout and "timeout" not in kwargs:
            raise ValueError(
                "Timeout must be in args or kwargs to be recalculated")

        result = _SYSCALL_SENTINEL
        while result is _SYSCALL_SENTINEL:
            try:
                result = func(*args, **kwargs)
            # OSError is thrown by select.select
            # IOError is thrown by select.epoll.poll
            # select.error is thrown by select.poll.poll
            # Aren't we thankful for Python 3.x rework for exceptions?
            except (OSError, IOError, select.error) as e:
                # select.error wasn't a subclass of OSError in the past.
                errcode = None
                if hasattr(e, "errno"):
                    errcode = e.errno
                elif hasattr(e, "args"):
                    errcode = e.args[0]

                # Also test for the Windows equivalent of EINTR.
                is_interrupt = (errcode == errno.EINTR or (hasattr(errno, "WSAEINTR") and
                                                           errcode == errno.WSAEINTR))

                if is_interrupt:
                    if expires is not None:
                        current_time = monotonic()
                        if current_time > expires:
                            raise OSError(errno=errno.ETIMEDOUT)
                        if recalc_timeout:
                            if "timeout" in kwargs:
                                kwargs["timeout"] = expires - current_time
                    continue
                if errcode:
                    raise SelectorError(errcode)
                else:
                    raise
        return result
项目:jira_worklog_scanner    作者:pgarneau    | 项目源码 | 文件源码
def _syscall_wrapper(func, recalc_timeout, *args, **kwargs):
        """ Wrapper function for syscalls that could fail due to EINTR.
        All functions should be retried if there is time left in the timeout
        in accordance with PEP 475. """
        timeout = kwargs.get("timeout", None)
        if timeout is None:
            expires = None
            recalc_timeout = False
        else:
            timeout = float(timeout)
            if timeout < 0.0:  # Timeout less than 0 treated as no timeout.
                expires = None
            else:
                expires = monotonic() + timeout

        args = list(args)
        if recalc_timeout and "timeout" not in kwargs:
            raise ValueError(
                "Timeout must be in args or kwargs to be recalculated")

        result = _SYSCALL_SENTINEL
        while result is _SYSCALL_SENTINEL:
            try:
                result = func(*args, **kwargs)
            # OSError is thrown by select.select
            # IOError is thrown by select.epoll.poll
            # select.error is thrown by select.poll.poll
            # Aren't we thankful for Python 3.x rework for exceptions?
            except (OSError, IOError, select.error) as e:
                # select.error wasn't a subclass of OSError in the past.
                errcode = None
                if hasattr(e, "errno"):
                    errcode = e.errno
                elif hasattr(e, "args"):
                    errcode = e.args[0]

                # Also test for the Windows equivalent of EINTR.
                is_interrupt = (errcode == errno.EINTR or (hasattr(errno, "WSAEINTR") and
                                                           errcode == errno.WSAEINTR))

                if is_interrupt:
                    if expires is not None:
                        current_time = monotonic()
                        if current_time > expires:
                            raise OSError(errno=errno.ETIMEDOUT)
                        if recalc_timeout:
                            if "timeout" in kwargs:
                                kwargs["timeout"] = expires - current_time
                    continue
                if errcode:
                    raise SelectorError(errcode)
                else:
                    raise
        return result
项目:workflows.kyoyue    作者:wizyoung    | 项目源码 | 文件源码
def _syscall_wrapper(func, recalc_timeout, *args, **kwargs):
        """ Wrapper function for syscalls that could fail due to EINTR.
        All functions should be retried if there is time left in the timeout
        in accordance with PEP 475. """
        timeout = kwargs.get("timeout", None)
        if timeout is None:
            expires = None
            recalc_timeout = False
        else:
            timeout = float(timeout)
            if timeout < 0.0:  # Timeout less than 0 treated as no timeout.
                expires = None
            else:
                expires = monotonic() + timeout

        args = list(args)
        if recalc_timeout and "timeout" not in kwargs:
            raise ValueError(
                "Timeout must be in args or kwargs to be recalculated")

        result = _SYSCALL_SENTINEL
        while result is _SYSCALL_SENTINEL:
            try:
                result = func(*args, **kwargs)
            # OSError is thrown by select.select
            # IOError is thrown by select.epoll.poll
            # select.error is thrown by select.poll.poll
            # Aren't we thankful for Python 3.x rework for exceptions?
            except (OSError, IOError, select.error) as e:
                # select.error wasn't a subclass of OSError in the past.
                errcode = None
                if hasattr(e, "errno"):
                    errcode = e.errno
                elif hasattr(e, "args"):
                    errcode = e.args[0]

                # Also test for the Windows equivalent of EINTR.
                is_interrupt = (errcode == errno.EINTR or (hasattr(errno, "WSAEINTR") and
                                                           errcode == errno.WSAEINTR))

                if is_interrupt:
                    if expires is not None:
                        current_time = monotonic()
                        if current_time > expires:
                            raise OSError(errno=errno.ETIMEDOUT)
                        if recalc_timeout:
                            if "timeout" in kwargs:
                                kwargs["timeout"] = expires - current_time
                    continue
                if errcode:
                    raise SelectorError(errcode)
                else:
                    raise
        return result
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def _sendCloseAlert(self):
        # Okay, *THIS* is a bit complicated.

        # Basically, the issue is, OpenSSL seems to not actually return
        # errors from SSL_shutdown. Therefore, the only way to
        # determine if the close notification has been sent is by 
        # SSL_shutdown returning "done". However, it will not claim it's
        # done until it's both sent *and* received a shutdown notification.

        # I don't actually want to wait for a received shutdown
        # notification, though, so, I have to set RECEIVED_SHUTDOWN
        # before calling shutdown. Then, it'll return True once it's
        # *SENT* the shutdown.

        # However, RECEIVED_SHUTDOWN can't be left set, because then
        # reads will fail, breaking half close.

        # Also, since shutdown doesn't report errors, an empty write call is
        # done first, to try to detect if the connection has gone away.
        # (*NOT* an SSL_write call, because that fails once you've called
        # shutdown)
        try:
            os.write(self.socket.fileno(), '')
        except OSError, se:
            if se.args[0] in (EINTR, EWOULDBLOCK, ENOBUFS):
                return 0
            # Write error, socket gone
            return main.CONNECTION_LOST

        try:
            if hasattr(self.socket, 'set_shutdown'):
                laststate = self.socket.get_shutdown()
                self.socket.set_shutdown(laststate | SSL.RECEIVED_SHUTDOWN)
                done = self.socket.shutdown()
                if not (laststate & SSL.RECEIVED_SHUTDOWN):
                    self.socket.set_shutdown(SSL.SENT_SHUTDOWN)
            else:
                #warnings.warn("SSL connection shutdown possibly unreliable, "
                #              "please upgrade to ver 0.XX", category=UserWarning)
                self.socket.shutdown()
                done = True
        except SSL.Error, e:
            return e

        if done:
            self.stopWriting()
            # Note that this is tested for by identity below.
            return main.CONNECTION_DONE
        else:
            self.startWriting()
            return None
项目:purelove    作者:hucmosin    | 项目源码 | 文件源码
def _syscall_wrapper(func, recalc_timeout, *args, **kwargs):
    """ Wrapper function for syscalls that could fail due to EINTR.
    All functions should be retried if there is time left in the timeout
    in accordance with PEP 475. """
    timeout = kwargs.get("timeout", None)
    if timeout is None:
        expires = None
        recalc_timeout = False
    else:
        timeout = float(timeout)
        if timeout < 0.0:  # Timeout less than 0 treated as no timeout.
            expires = None
        else:
            expires = monotonic() + timeout

    args = list(args)
    if recalc_timeout and "timeout" not in kwargs:
        raise ValueError(
            "Timeout must be in args or kwargs to be recalculated")

    result = _SYSCALL_SENTINEL
    while result is _SYSCALL_SENTINEL:
        try:
            result = func(*args, **kwargs)
        # OSError is thrown by select.select
        # IOError is thrown by select.epoll.poll
        # select.error is thrown by select.poll.poll
        # Aren't we thankful for Python 3.x rework for exceptions?
        except (OSError, IOError, select.error) as e:
            # select.error wasn't a subclass of OSError in the past.
            errcode = None
            if hasattr(e, "errno"):
                errcode = e.errno
            elif hasattr(e, "args"):
                errcode = e.args[0]

            # Also test for the Windows equivalent of EINTR.
            is_interrupt = (errcode == errno.EINTR or (hasattr(errno, "WSAEINTR") and
                                                       errcode == errno.WSAEINTR))

            if is_interrupt:
                if expires is not None:
                    current_time = monotonic()
                    if current_time > expires:
                        raise OSError(errno=errno.ETIMEDOUT)
                    if recalc_timeout:
                        if "timeout" in kwargs:
                            kwargs["timeout"] = expires - current_time
                continue
            if errcode:
                raise SelectorError(errcode)
            else:
                raise
    return result
项目:harbour-sailfinder    作者:DylanVanAssche    | 项目源码 | 文件源码
def _syscall_wrapper(func, recalc_timeout, *args, **kwargs):
    """ Wrapper function for syscalls that could fail due to EINTR.
    All functions should be retried if there is time left in the timeout
    in accordance with PEP 475. """
    timeout = kwargs.get("timeout", None)
    if timeout is None:
        expires = None
        recalc_timeout = False
    else:
        timeout = float(timeout)
        if timeout < 0.0:  # Timeout less than 0 treated as no timeout.
            expires = None
        else:
            expires = monotonic() + timeout

    args = list(args)
    if recalc_timeout and "timeout" not in kwargs:
        raise ValueError(
            "Timeout must be in args or kwargs to be recalculated")

    result = _SYSCALL_SENTINEL
    while result is _SYSCALL_SENTINEL:
        try:
            result = func(*args, **kwargs)
        # OSError is thrown by select.select
        # IOError is thrown by select.epoll.poll
        # select.error is thrown by select.poll.poll
        # Aren't we thankful for Python 3.x rework for exceptions?
        except (OSError, IOError, select.error) as e:
            # select.error wasn't a subclass of OSError in the past.
            errcode = None
            if hasattr(e, "errno"):
                errcode = e.errno
            elif hasattr(e, "args"):
                errcode = e.args[0]

            # Also test for the Windows equivalent of EINTR.
            is_interrupt = (errcode == errno.EINTR or (hasattr(errno, "WSAEINTR") and
                                                       errcode == errno.WSAEINTR))

            if is_interrupt:
                if expires is not None:
                    current_time = monotonic()
                    if current_time > expires:
                        raise OSError(errno=errno.ETIMEDOUT)
                    if recalc_timeout:
                        if "timeout" in kwargs:
                            kwargs["timeout"] = expires - current_time
                continue
            if errcode:
                raise SelectorError(errcode)
            else:
                raise
    return result
项目:harbour-sailfinder    作者:DylanVanAssche    | 项目源码 | 文件源码
def _syscall_wrapper(func, recalc_timeout, *args, **kwargs):
    """ Wrapper function for syscalls that could fail due to EINTR.
    All functions should be retried if there is time left in the timeout
    in accordance with PEP 475. """
    timeout = kwargs.get("timeout", None)
    if timeout is None:
        expires = None
        recalc_timeout = False
    else:
        timeout = float(timeout)
        if timeout < 0.0:  # Timeout less than 0 treated as no timeout.
            expires = None
        else:
            expires = monotonic() + timeout

    args = list(args)
    if recalc_timeout and "timeout" not in kwargs:
        raise ValueError(
            "Timeout must be in args or kwargs to be recalculated")

    result = _SYSCALL_SENTINEL
    while result is _SYSCALL_SENTINEL:
        try:
            result = func(*args, **kwargs)
        # OSError is thrown by select.select
        # IOError is thrown by select.epoll.poll
        # select.error is thrown by select.poll.poll
        # Aren't we thankful for Python 3.x rework for exceptions?
        except (OSError, IOError, select.error) as e:
            # select.error wasn't a subclass of OSError in the past.
            errcode = None
            if hasattr(e, "errno"):
                errcode = e.errno
            elif hasattr(e, "args"):
                errcode = e.args[0]

            # Also test for the Windows equivalent of EINTR.
            is_interrupt = (errcode == errno.EINTR or (hasattr(errno, "WSAEINTR") and
                                                       errcode == errno.WSAEINTR))

            if is_interrupt:
                if expires is not None:
                    current_time = monotonic()
                    if current_time > expires:
                        raise OSError(errno=errno.ETIMEDOUT)
                    if recalc_timeout:
                        if "timeout" in kwargs:
                            kwargs["timeout"] = expires - current_time
                continue
            if errcode:
                raise SelectorError(errcode)
            else:
                raise
    return result
项目:ghostlines-robofont    作者:ghostlines    | 项目源码 | 文件源码
def _syscall_wrapper(func, recalc_timeout, *args, **kwargs):
    """ Wrapper function for syscalls that could fail due to EINTR.
    All functions should be retried if there is time left in the timeout
    in accordance with PEP 475. """
    timeout = kwargs.get("timeout", None)
    if timeout is None:
        expires = None
        recalc_timeout = False
    else:
        timeout = float(timeout)
        if timeout < 0.0:  # Timeout less than 0 treated as no timeout.
            expires = None
        else:
            expires = monotonic() + timeout

    args = list(args)
    if recalc_timeout and "timeout" not in kwargs:
        raise ValueError(
            "Timeout must be in args or kwargs to be recalculated")

    result = _SYSCALL_SENTINEL
    while result is _SYSCALL_SENTINEL:
        try:
            result = func(*args, **kwargs)
        # OSError is thrown by select.select
        # IOError is thrown by select.epoll.poll
        # select.error is thrown by select.poll.poll
        # Aren't we thankful for Python 3.x rework for exceptions?
        except (OSError, IOError, select.error) as e:
            # select.error wasn't a subclass of OSError in the past.
            errcode = None
            if hasattr(e, "errno"):
                errcode = e.errno
            elif hasattr(e, "args"):
                errcode = e.args[0]

            # Also test for the Windows equivalent of EINTR.
            is_interrupt = (errcode == errno.EINTR or (hasattr(errno, "WSAEINTR") and
                                                       errcode == errno.WSAEINTR))

            if is_interrupt:
                if expires is not None:
                    current_time = monotonic()
                    if current_time > expires:
                        raise OSError(errno=errno.ETIMEDOUT)
                    if recalc_timeout:
                        if "timeout" in kwargs:
                            kwargs["timeout"] = expires - current_time
                continue
            if errcode:
                raise SelectorError(errcode)
            else:
                raise
    return result
项目:ghostlines-robofont    作者:ghostlines    | 项目源码 | 文件源码
def _syscall_wrapper(func, recalc_timeout, *args, **kwargs):
    """ Wrapper function for syscalls that could fail due to EINTR.
    All functions should be retried if there is time left in the timeout
    in accordance with PEP 475. """
    timeout = kwargs.get("timeout", None)
    if timeout is None:
        expires = None
        recalc_timeout = False
    else:
        timeout = float(timeout)
        if timeout < 0.0:  # Timeout less than 0 treated as no timeout.
            expires = None
        else:
            expires = monotonic() + timeout

    args = list(args)
    if recalc_timeout and "timeout" not in kwargs:
        raise ValueError(
            "Timeout must be in args or kwargs to be recalculated")

    result = _SYSCALL_SENTINEL
    while result is _SYSCALL_SENTINEL:
        try:
            result = func(*args, **kwargs)
        # OSError is thrown by select.select
        # IOError is thrown by select.epoll.poll
        # select.error is thrown by select.poll.poll
        # Aren't we thankful for Python 3.x rework for exceptions?
        except (OSError, IOError, select.error) as e:
            # select.error wasn't a subclass of OSError in the past.
            errcode = None
            if hasattr(e, "errno"):
                errcode = e.errno
            elif hasattr(e, "args"):
                errcode = e.args[0]

            # Also test for the Windows equivalent of EINTR.
            is_interrupt = (errcode == errno.EINTR or (hasattr(errno, "WSAEINTR") and
                                                       errcode == errno.WSAEINTR))

            if is_interrupt:
                if expires is not None:
                    current_time = monotonic()
                    if current_time > expires:
                        raise OSError(errno=errno.ETIMEDOUT)
                    if recalc_timeout:
                        if "timeout" in kwargs:
                            kwargs["timeout"] = expires - current_time
                continue
            if errcode:
                raise SelectorError(errcode)
            else:
                raise
    return result
项目:wow-addon-updater    作者:kuhnerdm    | 项目源码 | 文件源码
def _syscall_wrapper(func, recalc_timeout, *args, **kwargs):
        """ Wrapper function for syscalls that could fail due to EINTR.
        All functions should be retried if there is time left in the timeout
        in accordance with PEP 475. """
        timeout = kwargs.get("timeout", None)
        if timeout is None:
            expires = None
            recalc_timeout = False
        else:
            timeout = float(timeout)
            if timeout < 0.0:  # Timeout less than 0 treated as no timeout.
                expires = None
            else:
                expires = monotonic() + timeout

        args = list(args)
        if recalc_timeout and "timeout" not in kwargs:
            raise ValueError(
                "Timeout must be in args or kwargs to be recalculated")

        result = _SYSCALL_SENTINEL
        while result is _SYSCALL_SENTINEL:
            try:
                result = func(*args, **kwargs)
            # OSError is thrown by select.select
            # IOError is thrown by select.epoll.poll
            # select.error is thrown by select.poll.poll
            # Aren't we thankful for Python 3.x rework for exceptions?
            except (OSError, IOError, select.error) as e:
                # select.error wasn't a subclass of OSError in the past.
                errcode = None
                if hasattr(e, "errno"):
                    errcode = e.errno
                elif hasattr(e, "args"):
                    errcode = e.args[0]

                # Also test for the Windows equivalent of EINTR.
                is_interrupt = (errcode == errno.EINTR or (hasattr(errno, "WSAEINTR") and
                                                           errcode == errno.WSAEINTR))

                if is_interrupt:
                    if expires is not None:
                        current_time = monotonic()
                        if current_time > expires:
                            raise OSError(errno=errno.ETIMEDOUT)
                        if recalc_timeout:
                            if "timeout" in kwargs:
                                kwargs["timeout"] = expires - current_time
                    continue
                if errcode:
                    raise SelectorError(errcode)
                else:
                    raise
        return result
项目:carnival-ecs-parrot    作者:carnivalmobile    | 项目源码 | 文件源码
def _syscall_wrapper(func, recalc_timeout, *args, **kwargs):
    """ Wrapper function for syscalls that could fail due to EINTR.
    All functions should be retried if there is time left in the timeout
    in accordance with PEP 475. """
    timeout = kwargs.get("timeout", None)
    if timeout is None:
        expires = None
        recalc_timeout = False
    else:
        timeout = float(timeout)
        if timeout < 0.0:  # Timeout less than 0 treated as no timeout.
            expires = None
        else:
            expires = monotonic() + timeout

    args = list(args)
    if recalc_timeout and "timeout" not in kwargs:
        raise ValueError(
            "Timeout must be in args or kwargs to be recalculated")

    result = _SYSCALL_SENTINEL
    while result is _SYSCALL_SENTINEL:
        try:
            result = func(*args, **kwargs)
        # OSError is thrown by select.select
        # IOError is thrown by select.epoll.poll
        # select.error is thrown by select.poll.poll
        # Aren't we thankful for Python 3.x rework for exceptions?
        except (OSError, IOError, select.error) as e:
            # select.error wasn't a subclass of OSError in the past.
            errcode = None
            if hasattr(e, "errno"):
                errcode = e.errno
            elif hasattr(e, "args"):
                errcode = e.args[0]

            # Also test for the Windows equivalent of EINTR.
            is_interrupt = (errcode == errno.EINTR or (hasattr(errno, "WSAEINTR") and
                                                       errcode == errno.WSAEINTR))

            if is_interrupt:
                if expires is not None:
                    current_time = monotonic()
                    if current_time > expires:
                        raise OSError(errno=errno.ETIMEDOUT)
                    if recalc_timeout:
                        if "timeout" in kwargs:
                            kwargs["timeout"] = expires - current_time
                continue
            if errcode:
                raise SelectorError(errcode)
            else:
                raise
    return result
项目:infraview    作者:a-dekker    | 项目源码 | 文件源码
def _syscall_wrapper(func, recalc_timeout, *args, **kwargs):
        """ Wrapper function for syscalls that could fail due to EINTR.
        All functions should be retried if there is time left in the timeout
        in accordance with PEP 475. """
        timeout = kwargs.get("timeout", None)
        if timeout is None:
            expires = None
            recalc_timeout = False
        else:
            timeout = float(timeout)
            if timeout < 0.0:  # Timeout less than 0 treated as no timeout.
                expires = None
            else:
                expires = monotonic() + timeout

        args = list(args)
        if recalc_timeout and "timeout" not in kwargs:
            raise ValueError(
                "Timeout must be in args or kwargs to be recalculated")

        result = _SYSCALL_SENTINEL
        while result is _SYSCALL_SENTINEL:
            try:
                result = func(*args, **kwargs)
            # OSError is thrown by select.select
            # IOError is thrown by select.epoll.poll
            # select.error is thrown by select.poll.poll
            # Aren't we thankful for Python 3.x rework for exceptions?
            except (OSError, IOError, select.error) as e:
                # select.error wasn't a subclass of OSError in the past.
                errcode = None
                if hasattr(e, "errno"):
                    errcode = e.errno
                elif hasattr(e, "args"):
                    errcode = e.args[0]

                # Also test for the Windows equivalent of EINTR.
                is_interrupt = (errcode == errno.EINTR or (hasattr(errno, "WSAEINTR") and
                                                           errcode == errno.WSAEINTR))

                if is_interrupt:
                    if expires is not None:
                        current_time = monotonic()
                        if current_time > expires:
                            raise OSError(errno=errno.ETIMEDOUT)
                        if recalc_timeout:
                            if "timeout" in kwargs:
                                kwargs["timeout"] = expires - current_time
                    continue
                if errcode:
                    raise SelectorError(errcode)
                else:
                    raise
        return result
项目:RPoint    作者:george17-meet    | 项目源码 | 文件源码
def _syscall_wrapper(func, recalc_timeout, *args, **kwargs):
        """ Wrapper function for syscalls that could fail due to EINTR.
        All functions should be retried if there is time left in the timeout
        in accordance with PEP 475. """
        timeout = kwargs.get("timeout", None)
        if timeout is None:
            expires = None
            recalc_timeout = False
        else:
            timeout = float(timeout)
            if timeout < 0.0:  # Timeout less than 0 treated as no timeout.
                expires = None
            else:
                expires = monotonic() + timeout

        args = list(args)
        if recalc_timeout and "timeout" not in kwargs:
            raise ValueError(
                "Timeout must be in args or kwargs to be recalculated")

        result = _SYSCALL_SENTINEL
        while result is _SYSCALL_SENTINEL:
            try:
                result = func(*args, **kwargs)
            # OSError is thrown by select.select
            # IOError is thrown by select.epoll.poll
            # select.error is thrown by select.poll.poll
            # Aren't we thankful for Python 3.x rework for exceptions?
            except (OSError, IOError, select.error) as e:
                # select.error wasn't a subclass of OSError in the past.
                errcode = None
                if hasattr(e, "errno"):
                    errcode = e.errno
                elif hasattr(e, "args"):
                    errcode = e.args[0]

                # Also test for the Windows equivalent of EINTR.
                is_interrupt = (errcode == errno.EINTR or (hasattr(errno, "WSAEINTR") and
                                                           errcode == errno.WSAEINTR))

                if is_interrupt:
                    if expires is not None:
                        current_time = monotonic()
                        if current_time > expires:
                            raise OSError(errno=errno.ETIMEDOUT)
                        if recalc_timeout:
                            if "timeout" in kwargs:
                                kwargs["timeout"] = expires - current_time
                    continue
                if errcode:
                    raise SelectorError(errcode)
                else:
                    raise
        return result
项目:selectors2    作者:SethMichaelLarson    | 项目源码 | 文件源码
def _syscall_wrapper(func, recalc_timeout, *args, **kwargs):
        """ Wrapper function for syscalls that could fail due to EINTR.
        All functions should be retried if there is time left in the timeout
        in accordance with PEP 475. """
        timeout = kwargs.get("timeout", None)
        if timeout is None:
            expires = None
            recalc_timeout = False
        else:
            timeout = float(timeout)
            if timeout < 0.0:  # Timeout less than 0 treated as no timeout.
                expires = None
            else:
                expires = monotonic() + timeout

        if recalc_timeout and 'timeout' not in kwargs:
            raise ValueError(
                'Timeout must be in kwargs to be recalculated')

        result = _SYSCALL_SENTINEL
        while result is _SYSCALL_SENTINEL:
            try:
                result = func(*args, **kwargs)
            # OSError is thrown by select.select
            # IOError is thrown by select.epoll.poll
            # select.error is thrown by select.poll.poll
            # Aren't we thankful for Python 3.x rework for exceptions?
            except (OSError, IOError, select.error) as e:
                # select.error wasn't a subclass of OSError in the past.
                errcode = None
                if hasattr(e, 'errno') and e.errno is not None:
                    errcode = e.errno
                elif hasattr(e, 'args'):
                    errcode = e.args[0]

                # Also test for the Windows equivalent of EINTR.
                is_interrupt = (errcode == errno.EINTR or (hasattr(errno, 'WSAEINTR') and
                                                           errcode == errno.WSAEINTR))

                if is_interrupt:
                    if expires is not None:
                        current_time = monotonic()
                        if current_time > expires:
                            raise OSError(errno.ETIMEDOUT, 'Connection timed out')
                        if recalc_timeout:
                            kwargs["timeout"] = expires - current_time
                    continue
                raise
        return result


# Choose the best implementation, roughly:
# kqueue == devpoll == epoll > poll > select
# select() also can't accept a FD > FD_SETSIZE (usually around 1024)
项目:flickr_downloader    作者:Denisolt    | 项目源码 | 文件源码
def _syscall_wrapper(func, recalc_timeout, *args, **kwargs):
        """ Wrapper function for syscalls that could fail due to EINTR.
        All functions should be retried if there is time left in the timeout
        in accordance with PEP 475. """
        timeout = kwargs.get("timeout", None)
        if timeout is None:
            expires = None
            recalc_timeout = False
        else:
            timeout = float(timeout)
            if timeout < 0.0:  # Timeout less than 0 treated as no timeout.
                expires = None
            else:
                expires = monotonic() + timeout

        args = list(args)
        if recalc_timeout and "timeout" not in kwargs:
            raise ValueError(
                "Timeout must be in args or kwargs to be recalculated")

        result = _SYSCALL_SENTINEL
        while result is _SYSCALL_SENTINEL:
            try:
                result = func(*args, **kwargs)
            # OSError is thrown by select.select
            # IOError is thrown by select.epoll.poll
            # select.error is thrown by select.poll.poll
            # Aren't we thankful for Python 3.x rework for exceptions?
            except (OSError, IOError, select.error) as e:
                # select.error wasn't a subclass of OSError in the past.
                errcode = None
                if hasattr(e, "errno"):
                    errcode = e.errno
                elif hasattr(e, "args"):
                    errcode = e.args[0]

                # Also test for the Windows equivalent of EINTR.
                is_interrupt = (errcode == errno.EINTR or (hasattr(errno, "WSAEINTR") and
                                                           errcode == errno.WSAEINTR))

                if is_interrupt:
                    if expires is not None:
                        current_time = monotonic()
                        if current_time > expires:
                            raise OSError(errno=errno.ETIMEDOUT)
                        if recalc_timeout:
                            if "timeout" in kwargs:
                                kwargs["timeout"] = expires - current_time
                    continue
                if errcode:
                    raise SelectorError(errcode)
                else:
                    raise
        return result
项目:SHAREOpenRefineWkshop    作者:cmh2166    | 项目源码 | 文件源码
def _syscall_wrapper(func, recalc_timeout, *args, **kwargs):
        """ Wrapper function for syscalls that could fail due to EINTR.
        All functions should be retried if there is time left in the timeout
        in accordance with PEP 475. """
        timeout = kwargs.get("timeout", None)
        if timeout is None:
            expires = None
            recalc_timeout = False
        else:
            timeout = float(timeout)
            if timeout < 0.0:  # Timeout less than 0 treated as no timeout.
                expires = None
            else:
                expires = monotonic() + timeout

        args = list(args)
        if recalc_timeout and "timeout" not in kwargs:
            raise ValueError(
                "Timeout must be in args or kwargs to be recalculated")

        result = _SYSCALL_SENTINEL
        while result is _SYSCALL_SENTINEL:
            try:
                result = func(*args, **kwargs)
            # OSError is thrown by select.select
            # IOError is thrown by select.epoll.poll
            # select.error is thrown by select.poll.poll
            # Aren't we thankful for Python 3.x rework for exceptions?
            except (OSError, IOError, select.error) as e:
                # select.error wasn't a subclass of OSError in the past.
                errcode = None
                if hasattr(e, "errno"):
                    errcode = e.errno
                elif hasattr(e, "args"):
                    errcode = e.args[0]

                # Also test for the Windows equivalent of EINTR.
                is_interrupt = (errcode == errno.EINTR or (hasattr(errno, "WSAEINTR") and
                                                           errcode == errno.WSAEINTR))

                if is_interrupt:
                    if expires is not None:
                        current_time = monotonic()
                        if current_time > expires:
                            raise OSError(errno=errno.ETIMEDOUT)
                        if recalc_timeout:
                            if "timeout" in kwargs:
                                kwargs["timeout"] = expires - current_time
                    continue
                if errcode:
                    raise SelectorError(errcode)
                else:
                    raise
        return result
项目:Liljimbo-Chatbot    作者:chrisjim316    | 项目源码 | 文件源码
def _syscall_wrapper(func, recalc_timeout, *args, **kwargs):
        """ Wrapper function for syscalls that could fail due to EINTR.
        All functions should be retried if there is time left in the timeout
        in accordance with PEP 475. """
        timeout = kwargs.get("timeout", None)
        if timeout is None:
            expires = None
            recalc_timeout = False
        else:
            timeout = float(timeout)
            if timeout < 0.0:  # Timeout less than 0 treated as no timeout.
                expires = None
            else:
                expires = monotonic() + timeout

        args = list(args)
        if recalc_timeout and "timeout" not in kwargs:
            raise ValueError(
                "Timeout must be in args or kwargs to be recalculated")

        result = _SYSCALL_SENTINEL
        while result is _SYSCALL_SENTINEL:
            try:
                result = func(*args, **kwargs)
            # OSError is thrown by select.select
            # IOError is thrown by select.epoll.poll
            # select.error is thrown by select.poll.poll
            # Aren't we thankful for Python 3.x rework for exceptions?
            except (OSError, IOError, select.error) as e:
                # select.error wasn't a subclass of OSError in the past.
                errcode = None
                if hasattr(e, "errno"):
                    errcode = e.errno
                elif hasattr(e, "args"):
                    errcode = e.args[0]

                # Also test for the Windows equivalent of EINTR.
                is_interrupt = (errcode == errno.EINTR or (hasattr(errno, "WSAEINTR") and
                                                           errcode == errno.WSAEINTR))

                if is_interrupt:
                    if expires is not None:
                        current_time = monotonic()
                        if current_time > expires:
                            raise OSError(errno=errno.ETIMEDOUT)
                        if recalc_timeout:
                            if "timeout" in kwargs:
                                kwargs["timeout"] = expires - current_time
                    continue
                if errcode:
                    raise SelectorError(errcode)
                else:
                    raise
        return result
项目:leetcode    作者:thomasyimgit    | 项目源码 | 文件源码
def _syscall_wrapper(func, recalc_timeout, *args, **kwargs):
    """ Wrapper function for syscalls that could fail due to EINTR.
    All functions should be retried if there is time left in the timeout
    in accordance with PEP 475. """
    timeout = kwargs.get("timeout", None)
    if timeout is None:
        expires = None
        recalc_timeout = False
    else:
        timeout = float(timeout)
        if timeout < 0.0:  # Timeout less than 0 treated as no timeout.
            expires = None
        else:
            expires = monotonic() + timeout

    args = list(args)
    if recalc_timeout and "timeout" not in kwargs:
        raise ValueError(
            "Timeout must be in args or kwargs to be recalculated")

    result = _SYSCALL_SENTINEL
    while result is _SYSCALL_SENTINEL:
        try:
            result = func(*args, **kwargs)
        # OSError is thrown by select.select
        # IOError is thrown by select.epoll.poll
        # select.error is thrown by select.poll.poll
        # Aren't we thankful for Python 3.x rework for exceptions?
        except (OSError, IOError, select.error) as e:
            # select.error wasn't a subclass of OSError in the past.
            errcode = None
            if hasattr(e, "errno"):
                errcode = e.errno
            elif hasattr(e, "args"):
                errcode = e.args[0]

            # Also test for the Windows equivalent of EINTR.
            is_interrupt = (errcode == errno.EINTR or (hasattr(errno, "WSAEINTR") and
                                                       errcode == errno.WSAEINTR))

            if is_interrupt:
                if expires is not None:
                    current_time = monotonic()
                    if current_time > expires:
                        raise OSError(errno=errno.ETIMEDOUT)
                    if recalc_timeout:
                        if "timeout" in kwargs:
                            kwargs["timeout"] = expires - current_time
                continue
            if errcode:
                raise SelectorError(errcode)
            else:
                raise
    return result
项目:open-ledger    作者:creativecommons    | 项目源码 | 文件源码
def _syscall_wrapper(func, recalc_timeout, *args, **kwargs):
    """ Wrapper function for syscalls that could fail due to EINTR.
    All functions should be retried if there is time left in the timeout
    in accordance with PEP 475. """
    timeout = kwargs.get("timeout", None)
    if timeout is None:
        expires = None
        recalc_timeout = False
    else:
        timeout = float(timeout)
        if timeout < 0.0:  # Timeout less than 0 treated as no timeout.
            expires = None
        else:
            expires = monotonic() + timeout

    args = list(args)
    if recalc_timeout and "timeout" not in kwargs:
        raise ValueError(
            "Timeout must be in args or kwargs to be recalculated")

    result = _SYSCALL_SENTINEL
    while result is _SYSCALL_SENTINEL:
        try:
            result = func(*args, **kwargs)
        # OSError is thrown by select.select
        # IOError is thrown by select.epoll.poll
        # select.error is thrown by select.poll.poll
        # Aren't we thankful for Python 3.x rework for exceptions?
        except (OSError, IOError, select.error) as e:
            # select.error wasn't a subclass of OSError in the past.
            errcode = None
            if hasattr(e, "errno"):
                errcode = e.errno
            elif hasattr(e, "args"):
                errcode = e.args[0]

            # Also test for the Windows equivalent of EINTR.
            is_interrupt = (errcode == errno.EINTR or (hasattr(errno, "WSAEINTR") and
                                                       errcode == errno.WSAEINTR))

            if is_interrupt:
                if expires is not None:
                    current_time = monotonic()
                    if current_time > expires:
                        raise OSError(errno=errno.ETIMEDOUT)
                    if recalc_timeout:
                        if "timeout" in kwargs:
                            kwargs["timeout"] = expires - current_time
                continue
            if errcode:
                raise SelectorError(errcode)
            else:
                raise
    return result
项目:strack_python_api    作者:cine-use    | 项目源码 | 文件源码
def _syscall_wrapper(func, recalc_timeout, *args, **kwargs):
    """ Wrapper function for syscalls that could fail due to EINTR.
    All functions should be retried if there is time left in the timeout
    in accordance with PEP 475. """
    timeout = kwargs.get("timeout", None)
    if timeout is None:
        expires = None
        recalc_timeout = False
    else:
        timeout = float(timeout)
        if timeout < 0.0:  # Timeout less than 0 treated as no timeout.
            expires = None
        else:
            expires = monotonic() + timeout

    args = list(args)
    if recalc_timeout and "timeout" not in kwargs:
        raise ValueError(
            "Timeout must be in args or kwargs to be recalculated")

    result = _SYSCALL_SENTINEL
    while result is _SYSCALL_SENTINEL:
        try:
            result = func(*args, **kwargs)
        # OSError is thrown by select.select
        # IOError is thrown by select.epoll.poll
        # select.error is thrown by select.poll.poll
        # Aren't we thankful for Python 3.x rework for exceptions?
        except (OSError, IOError, select.error) as e:
            # select.error wasn't a subclass of OSError in the past.
            errcode = None
            if hasattr(e, "errno"):
                errcode = e.errno
            elif hasattr(e, "args"):
                errcode = e.args[0]

            # Also test for the Windows equivalent of EINTR.
            is_interrupt = (errcode == errno.EINTR or (hasattr(errno, "WSAEINTR") and
                                                       errcode == errno.WSAEINTR))

            if is_interrupt:
                if expires is not None:
                    current_time = monotonic()
                    if current_time > expires:
                        raise OSError(errno=errno.ETIMEDOUT)
                    if recalc_timeout:
                        if "timeout" in kwargs:
                            kwargs["timeout"] = expires - current_time
                continue
            if errcode:
                raise SelectorError(errcode)
            else:
                raise
    return result
项目:aws-ec2rescue-linux    作者:awslabs    | 项目源码 | 文件源码
def _syscall_wrapper(func, recalc_timeout, *args, **kwargs):
        """ Wrapper function for syscalls that could fail due to EINTR.
        All functions should be retried if there is time left in the timeout
        in accordance with PEP 475. """
        timeout = kwargs.get("timeout", None)
        if timeout is None:
            expires = None
            recalc_timeout = False
        else:
            timeout = float(timeout)
            if timeout < 0.0:  # Timeout less than 0 treated as no timeout.
                expires = None
            else:
                expires = monotonic() + timeout

        args = list(args)
        if recalc_timeout and "timeout" not in kwargs:
            raise ValueError(
                "Timeout must be in args or kwargs to be recalculated")

        result = _SYSCALL_SENTINEL
        while result is _SYSCALL_SENTINEL:
            try:
                result = func(*args, **kwargs)
            # OSError is thrown by select.select
            # IOError is thrown by select.epoll.poll
            # select.error is thrown by select.poll.poll
            # Aren't we thankful for Python 3.x rework for exceptions?
            except (OSError, IOError, select.error) as e:
                # select.error wasn't a subclass of OSError in the past.
                errcode = None
                if hasattr(e, "errno"):
                    errcode = e.errno
                elif hasattr(e, "args"):
                    errcode = e.args[0]

                # Also test for the Windows equivalent of EINTR.
                is_interrupt = (errcode == errno.EINTR or (hasattr(errno, "WSAEINTR") and
                                                           errcode == errno.WSAEINTR))

                if is_interrupt:
                    if expires is not None:
                        current_time = monotonic()
                        if current_time > expires:
                            raise OSError(errno=errno.ETIMEDOUT)
                        if recalc_timeout:
                            if "timeout" in kwargs:
                                kwargs["timeout"] = expires - current_time
                    continue
                if errcode:
                    raise SelectorError(errcode)
                else:
                    raise
        return result
项目:ShelbySearch    作者:Agentscreech    | 项目源码 | 文件源码
def _syscall_wrapper(func, recalc_timeout, *args, **kwargs):
        """ Wrapper function for syscalls that could fail due to EINTR.
        All functions should be retried if there is time left in the timeout
        in accordance with PEP 475. """
        timeout = kwargs.get("timeout", None)
        if timeout is None:
            expires = None
            recalc_timeout = False
        else:
            timeout = float(timeout)
            if timeout < 0.0:  # Timeout less than 0 treated as no timeout.
                expires = None
            else:
                expires = monotonic() + timeout

        args = list(args)
        if recalc_timeout and "timeout" not in kwargs:
            raise ValueError(
                "Timeout must be in args or kwargs to be recalculated")

        result = _SYSCALL_SENTINEL
        while result is _SYSCALL_SENTINEL:
            try:
                result = func(*args, **kwargs)
            # OSError is thrown by select.select
            # IOError is thrown by select.epoll.poll
            # select.error is thrown by select.poll.poll
            # Aren't we thankful for Python 3.x rework for exceptions?
            except (OSError, IOError, select.error) as e:
                # select.error wasn't a subclass of OSError in the past.
                errcode = None
                if hasattr(e, "errno"):
                    errcode = e.errno
                elif hasattr(e, "args"):
                    errcode = e.args[0]

                # Also test for the Windows equivalent of EINTR.
                is_interrupt = (errcode == errno.EINTR or (hasattr(errno, "WSAEINTR") and
                                                           errcode == errno.WSAEINTR))

                if is_interrupt:
                    if expires is not None:
                        current_time = monotonic()
                        if current_time > expires:
                            raise OSError(errno=errno.ETIMEDOUT)
                        if recalc_timeout:
                            if "timeout" in kwargs:
                                kwargs["timeout"] = expires - current_time
                    continue
                if errcode:
                    raise SelectorError(errcode)
                else:
                    raise
        return result
项目:Tencent_Cartoon_Download    作者:Fretice    | 项目源码 | 文件源码
def _syscall_wrapper(func, recalc_timeout, *args, **kwargs):
    """ Wrapper function for syscalls that could fail due to EINTR.
    All functions should be retried if there is time left in the timeout
    in accordance with PEP 475. """
    timeout = kwargs.get("timeout", None)
    if timeout is None:
        expires = None
        recalc_timeout = False
    else:
        timeout = float(timeout)
        if timeout < 0.0:  # Timeout less than 0 treated as no timeout.
            expires = None
        else:
            expires = monotonic() + timeout

    args = list(args)
    if recalc_timeout and "timeout" not in kwargs:
        raise ValueError(
            "Timeout must be in args or kwargs to be recalculated")

    result = _SYSCALL_SENTINEL
    while result is _SYSCALL_SENTINEL:
        try:
            result = func(*args, **kwargs)
        # OSError is thrown by select.select
        # IOError is thrown by select.epoll.poll
        # select.error is thrown by select.poll.poll
        # Aren't we thankful for Python 3.x rework for exceptions?
        except (OSError, IOError, select.error) as e:
            # select.error wasn't a subclass of OSError in the past.
            errcode = None
            if hasattr(e, "errno"):
                errcode = e.errno
            elif hasattr(e, "args"):
                errcode = e.args[0]

            # Also test for the Windows equivalent of EINTR.
            is_interrupt = (errcode == errno.EINTR or (hasattr(errno, "WSAEINTR") and
                                                       errcode == errno.WSAEINTR))

            if is_interrupt:
                if expires is not None:
                    current_time = monotonic()
                    if current_time > expires:
                        raise OSError(errno=errno.ETIMEDOUT)
                    if recalc_timeout:
                        if "timeout" in kwargs:
                            kwargs["timeout"] = expires - current_time
                continue
            if errcode:
                raise SelectorError(errcode)
            else:
                raise
    return result
项目:plex-stieve    作者:wernerkarlheisenberg    | 项目源码 | 文件源码
def _syscall_wrapper(func, recalc_timeout, *args, **kwargs):
        """ Wrapper function for syscalls that could fail due to EINTR.
        All functions should be retried if there is time left in the timeout
        in accordance with PEP 475. """
        timeout = kwargs.get("timeout", None)
        if timeout is None:
            expires = None
            recalc_timeout = False
        else:
            timeout = float(timeout)
            if timeout < 0.0:  # Timeout less than 0 treated as no timeout.
                expires = None
            else:
                expires = monotonic() + timeout

        args = list(args)
        if recalc_timeout and "timeout" not in kwargs:
            raise ValueError(
                "Timeout must be in args or kwargs to be recalculated")

        result = _SYSCALL_SENTINEL
        while result is _SYSCALL_SENTINEL:
            try:
                result = func(*args, **kwargs)
            # OSError is thrown by select.select
            # IOError is thrown by select.epoll.poll
            # select.error is thrown by select.poll.poll
            # Aren't we thankful for Python 3.x rework for exceptions?
            except (OSError, IOError, select.error) as e:
                # select.error wasn't a subclass of OSError in the past.
                errcode = None
                if hasattr(e, "errno"):
                    errcode = e.errno
                elif hasattr(e, "args"):
                    errcode = e.args[0]

                # Also test for the Windows equivalent of EINTR.
                is_interrupt = (errcode == errno.EINTR or (hasattr(errno, "WSAEINTR") and
                                                           errcode == errno.WSAEINTR))

                if is_interrupt:
                    if expires is not None:
                        current_time = monotonic()
                        if current_time > expires:
                            raise OSError(errno=errno.ETIMEDOUT)
                        if recalc_timeout:
                            if "timeout" in kwargs:
                                kwargs["timeout"] = expires - current_time
                    continue
                if errcode:
                    raise SelectorError(errcode)
                else:
                    raise
        return result
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def _sendCloseAlert(self):
        # Okay, *THIS* is a bit complicated.

        # Basically, the issue is, OpenSSL seems to not actually return
        # errors from SSL_shutdown. Therefore, the only way to
        # determine if the close notification has been sent is by 
        # SSL_shutdown returning "done". However, it will not claim it's
        # done until it's both sent *and* received a shutdown notification.

        # I don't actually want to wait for a received shutdown
        # notification, though, so, I have to set RECEIVED_SHUTDOWN
        # before calling shutdown. Then, it'll return True once it's
        # *SENT* the shutdown.

        # However, RECEIVED_SHUTDOWN can't be left set, because then
        # reads will fail, breaking half close.

        # Also, since shutdown doesn't report errors, an empty write call is
        # done first, to try to detect if the connection has gone away.
        # (*NOT* an SSL_write call, because that fails once you've called
        # shutdown)
        try:
            os.write(self.socket.fileno(), '')
        except OSError, se:
            if se.args[0] in (EINTR, EWOULDBLOCK, ENOBUFS):
                return 0
            # Write error, socket gone
            return main.CONNECTION_LOST

        try:
            if hasattr(self.socket, 'set_shutdown'):
                laststate = self.socket.get_shutdown()
                self.socket.set_shutdown(laststate | SSL.RECEIVED_SHUTDOWN)
                done = self.socket.shutdown()
                if not (laststate & SSL.RECEIVED_SHUTDOWN):
                    self.socket.set_shutdown(SSL.SENT_SHUTDOWN)
            else:
                #warnings.warn("SSL connection shutdown possibly unreliable, "
                #              "please upgrade to ver 0.XX", category=UserWarning)
                self.socket.shutdown()
                done = True
        except SSL.Error, e:
            return e

        if done:
            self.stopWriting()
            # Note that this is tested for by identity below.
            return main.CONNECTION_DONE
        else:
            self.startWriting()
            return None
项目:python-group-proj    作者:Sharcee    | 项目源码 | 文件源码
def _syscall_wrapper(func, recalc_timeout, *args, **kwargs):
    """ Wrapper function for syscalls that could fail due to EINTR.
    All functions should be retried if there is time left in the timeout
    in accordance with PEP 475. """
    timeout = kwargs.get("timeout", None)
    if timeout is None:
        expires = None
        recalc_timeout = False
    else:
        timeout = float(timeout)
        if timeout < 0.0:  # Timeout less than 0 treated as no timeout.
            expires = None
        else:
            expires = monotonic() + timeout

    args = list(args)
    if recalc_timeout and "timeout" not in kwargs:
        raise ValueError(
            "Timeout must be in args or kwargs to be recalculated")

    result = _SYSCALL_SENTINEL
    while result is _SYSCALL_SENTINEL:
        try:
            result = func(*args, **kwargs)
        # OSError is thrown by select.select
        # IOError is thrown by select.epoll.poll
        # select.error is thrown by select.poll.poll
        # Aren't we thankful for Python 3.x rework for exceptions?
        except (OSError, IOError, select.error) as e:
            # select.error wasn't a subclass of OSError in the past.
            errcode = None
            if hasattr(e, "errno"):
                errcode = e.errno
            elif hasattr(e, "args"):
                errcode = e.args[0]

            # Also test for the Windows equivalent of EINTR.
            is_interrupt = (errcode == errno.EINTR or (hasattr(errno, "WSAEINTR") and
                                                       errcode == errno.WSAEINTR))

            if is_interrupt:
                if expires is not None:
                    current_time = monotonic()
                    if current_time > expires:
                        raise OSError(errno=errno.ETIMEDOUT)
                    if recalc_timeout:
                        if "timeout" in kwargs:
                            kwargs["timeout"] = expires - current_time
                continue
            if errcode:
                raise SelectorError(errcode)
            else:
                raise
    return result
项目:islam-buddy    作者:hamir    | 项目源码 | 文件源码
def _syscall_wrapper(func, recalc_timeout, *args, **kwargs):
    """ Wrapper function for syscalls that could fail due to EINTR.
    All functions should be retried if there is time left in the timeout
    in accordance with PEP 475. """
    timeout = kwargs.get("timeout", None)
    if timeout is None:
        expires = None
        recalc_timeout = False
    else:
        timeout = float(timeout)
        if timeout < 0.0:  # Timeout less than 0 treated as no timeout.
            expires = None
        else:
            expires = monotonic() + timeout

    args = list(args)
    if recalc_timeout and "timeout" not in kwargs:
        raise ValueError(
            "Timeout must be in args or kwargs to be recalculated")

    result = _SYSCALL_SENTINEL
    while result is _SYSCALL_SENTINEL:
        try:
            result = func(*args, **kwargs)
        # OSError is thrown by select.select
        # IOError is thrown by select.epoll.poll
        # select.error is thrown by select.poll.poll
        # Aren't we thankful for Python 3.x rework for exceptions?
        except (OSError, IOError, select.error) as e:
            # select.error wasn't a subclass of OSError in the past.
            errcode = None
            if hasattr(e, "errno"):
                errcode = e.errno
            elif hasattr(e, "args"):
                errcode = e.args[0]

            # Also test for the Windows equivalent of EINTR.
            is_interrupt = (errcode == errno.EINTR or (hasattr(errno, "WSAEINTR") and
                                                       errcode == errno.WSAEINTR))

            if is_interrupt:
                if expires is not None:
                    current_time = monotonic()
                    if current_time > expires:
                        raise OSError(errno=errno.ETIMEDOUT)
                    if recalc_timeout:
                        if "timeout" in kwargs:
                            kwargs["timeout"] = expires - current_time
                continue
            if errcode:
                raise SelectorError(errcode)
            else:
                raise
    return result
项目:start    作者:argeweb    | 项目源码 | 文件源码
def _syscall_wrapper(func, recalc_timeout, *args, **kwargs):
    """ Wrapper function for syscalls that could fail due to EINTR.
    All functions should be retried if there is time left in the timeout
    in accordance with PEP 475. """
    timeout = kwargs.get("timeout", None)
    if timeout is None:
        expires = None
        recalc_timeout = False
    else:
        timeout = float(timeout)
        if timeout < 0.0:  # Timeout less than 0 treated as no timeout.
            expires = None
        else:
            expires = monotonic() + timeout

    args = list(args)
    if recalc_timeout and "timeout" not in kwargs:
        raise ValueError(
            "Timeout must be in args or kwargs to be recalculated")

    result = _SYSCALL_SENTINEL
    while result is _SYSCALL_SENTINEL:
        try:
            result = func(*args, **kwargs)
        # OSError is thrown by select.select
        # IOError is thrown by select.epoll.poll
        # select.error is thrown by select.poll.poll
        # Aren't we thankful for Python 3.x rework for exceptions?
        except (OSError, IOError, select.error) as e:
            # select.error wasn't a subclass of OSError in the past.
            errcode = None
            if hasattr(e, "errno"):
                errcode = e.errno
            elif hasattr(e, "args"):
                errcode = e.args[0]

            # Also test for the Windows equivalent of EINTR.
            is_interrupt = (errcode == errno.EINTR or (hasattr(errno, "WSAEINTR") and
                                                       errcode == errno.WSAEINTR))

            if is_interrupt:
                if expires is not None:
                    current_time = monotonic()
                    if current_time > expires:
                        raise OSError(errno=errno.ETIMEDOUT)
                    if recalc_timeout:
                        if "timeout" in kwargs:
                            kwargs["timeout"] = expires - current_time
                continue
            if errcode:
                raise SelectorError(errcode)
            else:
                raise
    return result
项目:SensorData    作者:libracore    | 项目源码 | 文件源码
def _syscall_wrapper(func, recalc_timeout, *args, **kwargs):
    """ Wrapper function for syscalls that could fail due to EINTR.
    All functions should be retried if there is time left in the timeout
    in accordance with PEP 475. """
    timeout = kwargs.get("timeout", None)
    if timeout is None:
        expires = None
        recalc_timeout = False
    else:
        timeout = float(timeout)
        if timeout < 0.0:  # Timeout less than 0 treated as no timeout.
            expires = None
        else:
            expires = monotonic() + timeout

    args = list(args)
    if recalc_timeout and "timeout" not in kwargs:
        raise ValueError(
            "Timeout must be in args or kwargs to be recalculated")

    result = _SYSCALL_SENTINEL
    while result is _SYSCALL_SENTINEL:
        try:
            result = func(*args, **kwargs)
        # OSError is thrown by select.select
        # IOError is thrown by select.epoll.poll
        # select.error is thrown by select.poll.poll
        # Aren't we thankful for Python 3.x rework for exceptions?
        except (OSError, IOError, select.error) as e:
            # select.error wasn't a subclass of OSError in the past.
            errcode = None
            if hasattr(e, "errno"):
                errcode = e.errno
            elif hasattr(e, "args"):
                errcode = e.args[0]

            # Also test for the Windows equivalent of EINTR.
            is_interrupt = (errcode == errno.EINTR or (hasattr(errno, "WSAEINTR") and
                                                       errcode == errno.WSAEINTR))

            if is_interrupt:
                if expires is not None:
                    current_time = monotonic()
                    if current_time > expires:
                        raise OSError(errno=errno.ETIMEDOUT)
                    if recalc_timeout:
                        if "timeout" in kwargs:
                            kwargs["timeout"] = expires - current_time
                continue
            if errcode:
                raise SelectorError(errcode)
            else:
                raise
    return result
项目:ServerlessCrawler-VancouverRealState    作者:MarcelloLins    | 项目源码 | 文件源码
def _syscall_wrapper(func, recalc_timeout, *args, **kwargs):
        """ Wrapper function for syscalls that could fail due to EINTR.
        All functions should be retried if there is time left in the timeout
        in accordance with PEP 475. """
        timeout = kwargs.get("timeout", None)
        if timeout is None:
            expires = None
            recalc_timeout = False
        else:
            timeout = float(timeout)
            if timeout < 0.0:  # Timeout less than 0 treated as no timeout.
                expires = None
            else:
                expires = monotonic() + timeout

        args = list(args)
        if recalc_timeout and "timeout" not in kwargs:
            raise ValueError(
                "Timeout must be in args or kwargs to be recalculated")

        result = _SYSCALL_SENTINEL
        while result is _SYSCALL_SENTINEL:
            try:
                result = func(*args, **kwargs)
            # OSError is thrown by select.select
            # IOError is thrown by select.epoll.poll
            # select.error is thrown by select.poll.poll
            # Aren't we thankful for Python 3.x rework for exceptions?
            except (OSError, IOError, select.error) as e:
                # select.error wasn't a subclass of OSError in the past.
                errcode = None
                if hasattr(e, "errno"):
                    errcode = e.errno
                elif hasattr(e, "args"):
                    errcode = e.args[0]

                # Also test for the Windows equivalent of EINTR.
                is_interrupt = (errcode == errno.EINTR or (hasattr(errno, "WSAEINTR") and
                                                           errcode == errno.WSAEINTR))

                if is_interrupt:
                    if expires is not None:
                        current_time = monotonic()
                        if current_time > expires:
                            raise OSError(errno=errno.ETIMEDOUT)
                        if recalc_timeout:
                            if "timeout" in kwargs:
                                kwargs["timeout"] = expires - current_time
                    continue
                if errcode:
                    raise SelectorError(errcode)
                else:
                    raise
        return result
项目:ServerlessCrawler-VancouverRealState    作者:MarcelloLins    | 项目源码 | 文件源码
def _syscall_wrapper(func, recalc_timeout, *args, **kwargs):
        """ Wrapper function for syscalls that could fail due to EINTR.
        All functions should be retried if there is time left in the timeout
        in accordance with PEP 475. """
        timeout = kwargs.get("timeout", None)
        if timeout is None:
            expires = None
            recalc_timeout = False
        else:
            timeout = float(timeout)
            if timeout < 0.0:  # Timeout less than 0 treated as no timeout.
                expires = None
            else:
                expires = monotonic() + timeout

        args = list(args)
        if recalc_timeout and "timeout" not in kwargs:
            raise ValueError(
                "Timeout must be in args or kwargs to be recalculated")

        result = _SYSCALL_SENTINEL
        while result is _SYSCALL_SENTINEL:
            try:
                result = func(*args, **kwargs)
            # OSError is thrown by select.select
            # IOError is thrown by select.epoll.poll
            # select.error is thrown by select.poll.poll
            # Aren't we thankful for Python 3.x rework for exceptions?
            except (OSError, IOError, select.error) as e:
                # select.error wasn't a subclass of OSError in the past.
                errcode = None
                if hasattr(e, "errno"):
                    errcode = e.errno
                elif hasattr(e, "args"):
                    errcode = e.args[0]

                # Also test for the Windows equivalent of EINTR.
                is_interrupt = (errcode == errno.EINTR or (hasattr(errno, "WSAEINTR") and
                                                           errcode == errno.WSAEINTR))

                if is_interrupt:
                    if expires is not None:
                        current_time = monotonic()
                        if current_time > expires:
                            raise OSError(errno=errno.ETIMEDOUT)
                        if recalc_timeout:
                            if "timeout" in kwargs:
                                kwargs["timeout"] = expires - current_time
                    continue
                if errcode:
                    raise SelectorError(errcode)
                else:
                    raise
        return result
项目:ServerlessCrawler-VancouverRealState    作者:MarcelloLins    | 项目源码 | 文件源码
def _syscall_wrapper(func, recalc_timeout, *args, **kwargs):
        """ Wrapper function for syscalls that could fail due to EINTR.
        All functions should be retried if there is time left in the timeout
        in accordance with PEP 475. """
        timeout = kwargs.get("timeout", None)
        if timeout is None:
            expires = None
            recalc_timeout = False
        else:
            timeout = float(timeout)
            if timeout < 0.0:  # Timeout less than 0 treated as no timeout.
                expires = None
            else:
                expires = monotonic() + timeout

        args = list(args)
        if recalc_timeout and "timeout" not in kwargs:
            raise ValueError(
                "Timeout must be in args or kwargs to be recalculated")

        result = _SYSCALL_SENTINEL
        while result is _SYSCALL_SENTINEL:
            try:
                result = func(*args, **kwargs)
            # OSError is thrown by select.select
            # IOError is thrown by select.epoll.poll
            # select.error is thrown by select.poll.poll
            # Aren't we thankful for Python 3.x rework for exceptions?
            except (OSError, IOError, select.error) as e:
                # select.error wasn't a subclass of OSError in the past.
                errcode = None
                if hasattr(e, "errno"):
                    errcode = e.errno
                elif hasattr(e, "args"):
                    errcode = e.args[0]

                # Also test for the Windows equivalent of EINTR.
                is_interrupt = (errcode == errno.EINTR or (hasattr(errno, "WSAEINTR") and
                                                           errcode == errno.WSAEINTR))

                if is_interrupt:
                    if expires is not None:
                        current_time = monotonic()
                        if current_time > expires:
                            raise OSError(errno=errno.ETIMEDOUT)
                        if recalc_timeout:
                            if "timeout" in kwargs:
                                kwargs["timeout"] = expires - current_time
                    continue
                if errcode:
                    raise SelectorError(errcode)
                else:
                    raise
        return result
项目:plugin.video.unofficial9anime    作者:Prometheusx-git    | 项目源码 | 文件源码
def _syscall_wrapper(func, recalc_timeout, *args, **kwargs):
        """ Wrapper function for syscalls that could fail due to EINTR.
        All functions should be retried if there is time left in the timeout
        in accordance with PEP 475. """
        timeout = kwargs.get("timeout", None)
        if timeout is None:
            expires = None
            recalc_timeout = False
        else:
            timeout = float(timeout)
            if timeout < 0.0:  # Timeout less than 0 treated as no timeout.
                expires = None
            else:
                expires = monotonic() + timeout

        args = list(args)
        if recalc_timeout and "timeout" not in kwargs:
            raise ValueError(
                "Timeout must be in args or kwargs to be recalculated")

        result = _SYSCALL_SENTINEL
        while result is _SYSCALL_SENTINEL:
            try:
                result = func(*args, **kwargs)
            # OSError is thrown by select.select
            # IOError is thrown by select.epoll.poll
            # select.error is thrown by select.poll.poll
            # Aren't we thankful for Python 3.x rework for exceptions?
            except (OSError, IOError, select.error) as e:
                # select.error wasn't a subclass of OSError in the past.
                errcode = None
                if hasattr(e, "errno"):
                    errcode = e.errno
                elif hasattr(e, "args"):
                    errcode = e.args[0]

                # Also test for the Windows equivalent of EINTR.
                is_interrupt = (errcode == errno.EINTR or (hasattr(errno, "WSAEINTR") and
                                                           errcode == errno.WSAEINTR))

                if is_interrupt:
                    if expires is not None:
                        current_time = monotonic()
                        if current_time > expires:
                            raise OSError(errno=errno.ETIMEDOUT)
                        if recalc_timeout:
                            if "timeout" in kwargs:
                                kwargs["timeout"] = expires - current_time
                    continue
                if errcode:
                    raise SelectorError(errcode)
                else:
                    raise
        return result
项目:Repobot    作者:Desgard    | 项目源码 | 文件源码
def _syscall_wrapper(func, recalc_timeout, *args, **kwargs):
    """ Wrapper function for syscalls that could fail due to EINTR.
    All functions should be retried if there is time left in the timeout
    in accordance with PEP 475. """
    timeout = kwargs.get("timeout", None)
    if timeout is None:
        expires = None
        recalc_timeout = False
    else:
        timeout = float(timeout)
        if timeout < 0.0:  # Timeout less than 0 treated as no timeout.
            expires = None
        else:
            expires = monotonic() + timeout

    args = list(args)
    if recalc_timeout and "timeout" not in kwargs:
        raise ValueError(
            "Timeout must be in args or kwargs to be recalculated")

    result = _SYSCALL_SENTINEL
    while result is _SYSCALL_SENTINEL:
        try:
            result = func(*args, **kwargs)
        # OSError is thrown by select.select
        # IOError is thrown by select.epoll.poll
        # select.error is thrown by select.poll.poll
        # Aren't we thankful for Python 3.x rework for exceptions?
        except (OSError, IOError, select.error) as e:
            # select.error wasn't a subclass of OSError in the past.
            errcode = None
            if hasattr(e, "errno"):
                errcode = e.errno
            elif hasattr(e, "args"):
                errcode = e.args[0]

            # Also test for the Windows equivalent of EINTR.
            is_interrupt = (errcode == errno.EINTR or (hasattr(errno, "WSAEINTR") and
                                                       errcode == errno.WSAEINTR))

            if is_interrupt:
                if expires is not None:
                    current_time = monotonic()
                    if current_time > expires:
                        raise OSError(errno=errno.ETIMEDOUT)
                    if recalc_timeout:
                        if "timeout" in kwargs:
                            kwargs["timeout"] = expires - current_time
                continue
            if errcode:
                raise SelectorError(errcode)
            else:
                raise
    return result
项目:s3-misuse-shoutings    作者:davidporter-id-au    | 项目源码 | 文件源码
def _syscall_wrapper(func, recalc_timeout, *args, **kwargs):
        """ Wrapper function for syscalls that could fail due to EINTR.
        All functions should be retried if there is time left in the timeout
        in accordance with PEP 475. """
        timeout = kwargs.get("timeout", None)
        if timeout is None:
            expires = None
            recalc_timeout = False
        else:
            timeout = float(timeout)
            if timeout < 0.0:  # Timeout less than 0 treated as no timeout.
                expires = None
            else:
                expires = monotonic() + timeout

        args = list(args)
        if recalc_timeout and "timeout" not in kwargs:
            raise ValueError(
                "Timeout must be in args or kwargs to be recalculated")

        result = _SYSCALL_SENTINEL
        while result is _SYSCALL_SENTINEL:
            try:
                result = func(*args, **kwargs)
            # OSError is thrown by select.select
            # IOError is thrown by select.epoll.poll
            # select.error is thrown by select.poll.poll
            # Aren't we thankful for Python 3.x rework for exceptions?
            except (OSError, IOError, select.error) as e:
                # select.error wasn't a subclass of OSError in the past.
                errcode = None
                if hasattr(e, "errno"):
                    errcode = e.errno
                elif hasattr(e, "args"):
                    errcode = e.args[0]

                # Also test for the Windows equivalent of EINTR.
                is_interrupt = (errcode == errno.EINTR or (hasattr(errno, "WSAEINTR") and
                                                           errcode == errno.WSAEINTR))

                if is_interrupt:
                    if expires is not None:
                        current_time = monotonic()
                        if current_time > expires:
                            raise OSError(errno=errno.ETIMEDOUT)
                        if recalc_timeout:
                            if "timeout" in kwargs:
                                kwargs["timeout"] = expires - current_time
                    continue
                if errcode:
                    raise SelectorError(errcode)
                else:
                    raise
        return result
项目:core    作者:getavalon    | 项目源码 | 文件源码
def _syscall_wrapper(func, recalc_timeout, *args, **kwargs):
        """ Wrapper function for syscalls that could fail due to EINTR.
        All functions should be retried if there is time left in the timeout
        in accordance with PEP 475. """
        timeout = kwargs.get("timeout", None)
        if timeout is None:
            expires = None
            recalc_timeout = False
        else:
            timeout = float(timeout)
            if timeout < 0.0:  # Timeout less than 0 treated as no timeout.
                expires = None
            else:
                expires = monotonic() + timeout

        args = list(args)
        if recalc_timeout and "timeout" not in kwargs:
            raise ValueError(
                "Timeout must be in args or kwargs to be recalculated")

        result = _SYSCALL_SENTINEL
        while result is _SYSCALL_SENTINEL:
            try:
                result = func(*args, **kwargs)
            # OSError is thrown by select.select
            # IOError is thrown by select.epoll.poll
            # select.error is thrown by select.poll.poll
            # Aren't we thankful for Python 3.x rework for exceptions?
            except (OSError, IOError, select.error) as e:
                # select.error wasn't a subclass of OSError in the past.
                errcode = None
                if hasattr(e, "errno"):
                    errcode = e.errno
                elif hasattr(e, "args"):
                    errcode = e.args[0]

                # Also test for the Windows equivalent of EINTR.
                is_interrupt = (errcode == errno.EINTR or (hasattr(errno, "WSAEINTR") and
                                                           errcode == errno.WSAEINTR))

                if is_interrupt:
                    if expires is not None:
                        current_time = monotonic()
                        if current_time > expires:
                            raise OSError(errno=errno.ETIMEDOUT)
                        if recalc_timeout:
                            if "timeout" in kwargs:
                                kwargs["timeout"] = expires - current_time
                    continue
                if errcode:
                    raise SelectorError(errcode)
                else:
                    raise
        return result
项目:plugin.program.indigo    作者:tvaddonsco    | 项目源码 | 文件源码
def _syscall_wrapper(func, recalc_timeout, *args, **kwargs):
    """ Wrapper function for syscalls that could fail due to EINTR.
    All functions should be retried if there is time left in the timeout
    in accordance with PEP 475. """
    timeout = kwargs.get("timeout", None)
    if timeout is None:
        expires = None
        recalc_timeout = False
    else:
        timeout = float(timeout)
        if timeout < 0.0:  # Timeout less than 0 treated as no timeout.
            expires = None
        else:
            expires = monotonic() + timeout

    args = list(args)
    if recalc_timeout and "timeout" not in kwargs:
        raise ValueError(
            "Timeout must be in args or kwargs to be recalculated")

    result = _SYSCALL_SENTINEL
    while result is _SYSCALL_SENTINEL:
        try:
            result = func(*args, **kwargs)
        # OSError is thrown by select.select
        # IOError is thrown by select.epoll.poll
        # select.error is thrown by select.poll.poll
        # Aren't we thankful for Python 3.x rework for exceptions?
        except (OSError, IOError, select.error) as e:
            # select.error wasn't a subclass of OSError in the past.
            errcode = None
            if hasattr(e, "errno"):
                errcode = e.errno
            elif hasattr(e, "args"):
                errcode = e.args[0]

            # Also test for the Windows equivalent of EINTR.
            is_interrupt = (errcode == errno.EINTR or (hasattr(errno, "WSAEINTR") and
                                                       errcode == errno.WSAEINTR))

            if is_interrupt:
                if expires is not None:
                    current_time = monotonic()
                    if current_time > expires:
                        raise OSError(errno=errno.ETIMEDOUT)
                    if recalc_timeout:
                        if "timeout" in kwargs:
                            kwargs["timeout"] = expires - current_time
                continue
            if errcode:
                raise SelectorError(errcode)
            else:
                raise
    return result