当前位置: 首页>>代码示例>>Python>>正文


Python _socket.timeout方法代码示例

本文整理汇总了Python中_socket.timeout方法的典型用法代码示例。如果您正苦于以下问题:Python _socket.timeout方法的具体用法?Python _socket.timeout怎么用?Python _socket.timeout使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在_socket的用法示例。


在下文中一共展示了_socket.timeout方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_pod_relay_preferences

# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import timeout [as 别名]
def get_pod_relay_preferences(self, host):
        """Query remote pods on https first, fall back to http."""
        logging.info("Querying %s" % host)
        try:
            try:
                response = requests.get("https://%s/.well-known/x-social-relay" % host,
                                timeout=5,
                                headers={"User-Agent": config.USER_AGENT})
            except timeout:
                response = None
            if not response or response.status_code != 200:
                response = requests.get("http://%s/.well-known/x-social-relay" % host,
                                timeout=5,
                                headers={"User-Agent": config.USER_AGENT})
                if response.status_code != 200:
                    return None
        except (ConnectionError, Timeout, timeout):
            return None
        try:
            # Make sure we have a valid x-social-relay doc
            validate(response.json(), self.schema)
            return response.text
        except (ValueError, ValidationError):
            return None 
开发者ID:jaywink,项目名称:social-relay,代码行数:26,代码来源:poll_pods.py

示例2: accept

# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import timeout [as 别名]
def accept(self):
        """accept() -> (socket object, address info)

        Wait for an incoming connection.  Return a new socket
        representing the connection, and the address of the client.
        For IP sockets, the address info is a pair (hostaddr, port).
        """
        fd, addr = self._accept()
        # If our type has the SOCK_NONBLOCK flag, we shouldn't pass it onto the
        # new socket. We do not currently allow passing SOCK_NONBLOCK to
        # accept4, so the returned socket is always blocking.
        type = self.type & ~globals().get("SOCK_NONBLOCK", 0)
        sock = socket(self.family, type, self.proto, fileno=fd)
        # Issue #7995: if no default timeout is set and the listening
        # socket had a (non-zero) timeout, force the new socket in blocking
        # mode to override platform-specific socket flags inheritance.
        if getdefaulttimeout() is None and self.gettimeout():
            sock.setblocking(True)
        return sock, addr 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:21,代码来源:socket.py

示例3: readinto

# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import timeout [as 别名]
def readinto(self, b):
        """Read up to len(b) bytes into the writable buffer *b* and return
        the number of bytes read.  If the socket is non-blocking and no bytes
        are available, None is returned.

        If *b* is non-empty, a 0 return value indicates that the connection
        was shutdown at the other end.
        """
        self._checkClosed()
        self._checkReadable()
        if self._timeout_occurred:
            raise OSError("cannot read from timed out object")
        while True:
            try:
                return self._sock.recv_into(b)
            except timeout:
                self._timeout_occurred = True
                raise
            except error as e:
                if e.args[0] in _blocking_errnos:
                    return None
                raise 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:24,代码来源:socket.py

示例4: _open_channel

# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import timeout [as 别名]
def _open_channel(self, host, port, username, password, connect_timeout):
        self.client = paramiko.SSHClient()
        self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        try:
            self.client.connect(host,
                                port=port,
                                username=username,
                                password=password,
                                timeout=connect_timeout,
                                allow_agent=False,
                                look_for_keys=False)
        except timeout:
            raise ConnectTimeout(host, port)
        except gaierror:
            raise CouldNotConnect(host, port)

        self.channel = self.client.invoke_shell()

        self._wait_for(self.prompt) 
开发者ID:internap,项目名称:netman,代码行数:21,代码来源:ssh.py

示例5: create_connection

# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import timeout [as 别名]
def create_connection(address, timeout=_GLOBAL_DEFAULT_TIMEOUT,
                      source_address=None):
    """Connect to *address* and return the socket object.

    Convenience function.  Connect to *address* (a 2-tuple ``(host,
    port)``) and return the socket object.  Passing the optional
    *timeout* parameter will set the timeout on the socket instance
    before attempting to connect.  If no *timeout* is supplied, the
    global default timeout setting returned by :func:`getdefaulttimeout`
    is used.  If *source_address* is set it must be a tuple of (host, port)
    for the socket to bind as a source address before making the connection.
    An host of '' or port 0 tells the OS to use the default.
    """

    host, port = address
    err = None
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
        af, socktype, proto, canonname, sa = res
        sock = None
        try:
            sock = socket(af, socktype, proto)
            if timeout is not _GLOBAL_DEFAULT_TIMEOUT:
                sock.settimeout(timeout)
            if source_address:
                sock.bind(source_address)
            sock.connect(sa)
            return sock

        except error as _:
            err = _
            if sock is not None:
                sock.close()

    if err is not None:
        raise err
    else:
        raise error("getaddrinfo returns an empty list") 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:39,代码来源:socket.py

示例6: accept

# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import timeout [as 别名]
def accept(self):
        """accept() -> (socket object, address info)

        Wait for an incoming connection.  Return a new socket
        representing the connection, and the address of the client.
        For IP sockets, the address info is a pair (hostaddr, port).
        """
        fd, addr = self._accept()
        sock = socket(self.family, self.type, self.proto, fileno=fd)
        # Issue #7995: if no default timeout is set and the listening
        # socket had a (non-zero) timeout, force the new socket in blocking
        # mode to override platform-specific socket flags inheritance.
        if getdefaulttimeout() is None and self.gettimeout():
            sock.setblocking(True)
        return sock, addr 
开发者ID:CedricGuillemet,项目名称:Imogen,代码行数:17,代码来源:socket.py

示例7: create_connection

# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import timeout [as 别名]
def create_connection(address, timeout=_GLOBAL_DEFAULT_TIMEOUT,
                      source_address=None):
    """Connect to *address* and return the socket object.

    Convenience function.  Connect to *address* (a 2-tuple ``(host,
    port)``) and return the socket object.  Passing the optional
    *timeout* parameter will set the timeout on the socket instance
    before attempting to connect.  If no *timeout* is supplied, the
    global default timeout setting returned by :func:`getdefaulttimeout`
    is used.  If *source_address* is set it must be a tuple of (host, port)
    for the socket to bind as a source address before making the connection.
    A host of '' or port 0 tells the OS to use the default.
    """

    host, port = address
    err = None
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
        af, socktype, proto, canonname, sa = res
        sock = None
        try:
            sock = socket(af, socktype, proto)
            if timeout is not _GLOBAL_DEFAULT_TIMEOUT:
                sock.settimeout(timeout)
            if source_address:
                sock.bind(source_address)
            sock.connect(sa)
            # Break explicitly a reference cycle
            err = None
            return sock

        except error as _:
            err = _
            if sock is not None:
                sock.close()

    if err is not None:
        raise err
    else:
        raise error("getaddrinfo returns an empty list") 
开发者ID:CedricGuillemet,项目名称:Imogen,代码行数:41,代码来源:socket.py

示例8: _wait_for

# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import timeout [as 别名]
def _wait_for(self, expect):
        result = self.telnet.expect(expect, timeout=self.command_timeout)
        if result[0] == -1:
            raise CommandTimeout(expect)
        return result[2] 
开发者ID:internap,项目名称:netman,代码行数:7,代码来源:telnet.py

示例9: _wait_for_successful_login

# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import timeout [as 别名]
def _wait_for_successful_login(self):
        result = self.telnet.expect(list(self.prompt), timeout=self.connect_timeout)
        if result[0] == -1:
            raise ConnectTimeout(self.host, self.port)
        return result[2] 
开发者ID:internap,项目名称:netman,代码行数:7,代码来源:telnet.py

示例10: _connect

# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import timeout [as 别名]
def _connect(self):
        try:
            telnet = telnetlib.Telnet(self.host, self.port, self.connect_timeout)
        except timeout:
            raise ConnectTimeout(self.host, self.port)
        except gaierror:
            raise CouldNotConnect(self.host, self.port)

        telnet.set_option_negotiation_callback(_accept_all)
        return telnet 
开发者ID:internap,项目名称:netman,代码行数:12,代码来源:telnet.py

示例11: create_connection

# 需要导入模块: import _socket [as 别名]
# 或者: from _socket import timeout [as 别名]
def create_connection(address, timeout=_GLOBAL_DEFAULT_TIMEOUT,
                      source_address=None):
    """Connect to *address* and return the socket object.

    Convenience function.  Connect to *address* (a 2-tuple ``(host,
    port)``) and return the socket object.  Passing the optional
    *timeout* parameter will set the timeout on the socket instance
    before attempting to connect.  If no *timeout* is supplied, the
    global default timeout setting returned by :func:`getdefaulttimeout`
    is used.  If *source_address* is set it must be a tuple of (host, port)
    for the socket to bind as a source address before making the connection.
    A host of '' or port 0 tells the OS to use the default.
    """

    host, port = address
    err = None
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
        af, socktype, proto, canonname, sa = res
        sock = None
        try:
            sock = socket(af, socktype, proto)
            if timeout is not _GLOBAL_DEFAULT_TIMEOUT:
                sock.settimeout(timeout)
            if source_address:
                sock.bind(source_address)
            sock.connect(sa)
            return sock

        except error as _:
            err = _
            if sock is not None:
                sock.close()

    if err is not None:
        raise err
    else:
        raise error("getaddrinfo returns an empty list") 
开发者ID:ShikyoKira,项目名称:Project-New-Reign---Nemesis-Main,代码行数:39,代码来源:socket.py


注:本文中的_socket.timeout方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。