當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。