本文整理匯總了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
示例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
示例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
示例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)
示例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")
示例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
示例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")
示例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]
示例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]
示例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
示例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")