本文整理汇总了Python中socket.getdefaulttimeout方法的典型用法代码示例。如果您正苦于以下问题:Python socket.getdefaulttimeout方法的具体用法?Python socket.getdefaulttimeout怎么用?Python socket.getdefaulttimeout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类socket
的用法示例。
在下文中一共展示了socket.getdefaulttimeout方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: downloadAndShow
# 需要导入模块: import socket [as 别名]
# 或者: from socket import getdefaulttimeout [as 别名]
def downloadAndShow(self):
"""Triggered when the user wants to download and see the file"""
url = self.selectedText.strip()
if url.lower().startswith("www."):
url = "http://" + url
oldTimeout = socket.getdefaulttimeout()
newTimeout = 5 # Otherwise the pause is too long
socket.setdefaulttimeout(newTimeout)
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
try:
response = urllib.request.urlopen(url)
content = decodeURLContent(response.read())
# The content has been read sucessfully
mainWindow = GlobalData().mainWindow
mainWindow.editorsManager().newTabClicked(content,
os.path.basename(url))
except Exception as exc:
logging.error("Error downloading '" + url + "'\n" + str(exc))
QApplication.restoreOverrideCursor()
socket.setdefaulttimeout(oldTimeout)
示例2: test_timeout
# 需要导入模块: import socket [as 别名]
# 或者: from socket import getdefaulttimeout [as 别名]
def test_timeout(self):
old_timeout = socket.getdefaulttimeout()
try:
socket.setdefaulttimeout(0.1)
parent, child = multiprocessing.Pipe(duplex=True)
l = multiprocessing.connection.Listener(family='AF_INET')
p = multiprocessing.Process(target=self._test_timeout,
args=(child, l.address))
p.start()
child.close()
self.assertEqual(parent.recv(), 123)
parent.close()
conn = l.accept()
self.assertEqual(conn.recv(), 456)
conn.close()
l.close()
p.join(10)
finally:
socket.setdefaulttimeout(old_timeout)
#
# Test what happens with no "if __name__ == '__main__'"
#
示例3: test_tls_error_ftp
# 需要导入模块: import socket [as 别名]
# 或者: from socket import getdefaulttimeout [as 别名]
def test_tls_error_ftp(self):
s = None
try:
def_timeout = socket.getdefaulttimeout()
socket.setdefaulttimeout(5)
s = make_socket_server(8021, lambda s, d: s.send(b'220 Welcome to FooFTP\n'))
with assert_exception(self, errors.TLSError, 'remote end closed the connection|server responded using FTP'):
tls.TLSSocket('localhost', 8021)
finally:
if s:
s.close()
socket.setdefaulttimeout(def_timeout)
示例4: socket_timeout
# 需要导入模块: import socket [as 别名]
# 或者: from socket import getdefaulttimeout [as 别名]
def socket_timeout(seconds=15):
cto = socket.getdefaulttimeout()
try:
socket.setdefaulttimeout(seconds)
yield
finally:
socket.setdefaulttimeout(cto)
示例5: socket_timeout
# 需要导入模块: import socket [as 别名]
# 或者: from socket import getdefaulttimeout [as 别名]
def socket_timeout(timeout=15):
def _socket_timeout(func):
def _socket_timeout(*args, **kwargs):
old_timeout = socket.getdefaulttimeout()
socket.setdefaulttimeout(timeout)
try:
return func(*args, **kwargs)
finally:
socket.setdefaulttimeout(old_timeout)
return _socket_timeout
return _socket_timeout
示例6: _new_fixed_fetch
# 需要导入模块: import socket [as 别名]
# 或者: from socket import getdefaulttimeout [as 别名]
def _new_fixed_fetch(validate_certificate):
def fixed_fetch(url, payload=None, method="GET", headers={},
allow_truncated=False, follow_redirects=True,
deadline=None):
if deadline is None:
deadline = socket.getdefaulttimeout() or 5
return fetch(url, payload=payload, method=method, headers=headers,
allow_truncated=allow_truncated,
follow_redirects=follow_redirects, deadline=deadline,
validate_certificate=validate_certificate)
return fixed_fetch
示例7: socket_timeout
# 需要导入模块: import socket [as 别名]
# 或者: from socket import getdefaulttimeout [as 别名]
def socket_timeout(timeout=15):
def _socket_timeout(func):
def _socket_timeout(*args, **kwargs):
old_timeout = socket.getdefaulttimeout()
socket.setdefaulttimeout(timeout)
try:
return func(*args, **kwargs)
finally:
socket.setdefaulttimeout(old_timeout)
return _socket_timeout
return _socket_timeout
示例8: testDefaultTimeout
# 需要导入模块: import socket [as 别名]
# 或者: from socket import getdefaulttimeout [as 别名]
def testDefaultTimeout(self):
# Testing default timeout
# The default timeout should initially be None
self.assertEqual(socket.getdefaulttimeout(), None)
s = socket.socket()
self.assertEqual(s.gettimeout(), None)
s.close()
# Set the default timeout to 10, and see if it propagates
socket.setdefaulttimeout(10)
self.assertEqual(socket.getdefaulttimeout(), 10)
s = socket.socket()
self.assertEqual(s.gettimeout(), 10)
s.close()
# Reset the default timeout to None, and see if it propagates
socket.setdefaulttimeout(None)
self.assertEqual(socket.getdefaulttimeout(), None)
s = socket.socket()
self.assertEqual(s.gettimeout(), None)
s.close()
# Check that setting it to an invalid value raises ValueError
self.assertRaises(ValueError, socket.setdefaulttimeout, -1)
# Check that setting it to an invalid type raises TypeError
self.assertRaises(TypeError, socket.setdefaulttimeout, "spam")
示例9: _testTimeoutDefault
# 需要导入模块: import socket [as 别名]
# 或者: from socket import getdefaulttimeout [as 别名]
def _testTimeoutDefault(self):
# passing no explicit timeout uses socket's global default
self.assertTrue(socket.getdefaulttimeout() is None)
socket.setdefaulttimeout(42)
try:
self.cli = socket.create_connection((HOST, self.port))
self.addCleanup(self.cli.close)
finally:
socket.setdefaulttimeout(None)
self.assertEqual(self.cli.gettimeout(), 42)
示例10: _testTimeoutNone
# 需要导入模块: import socket [as 别名]
# 或者: from socket import getdefaulttimeout [as 别名]
def _testTimeoutNone(self):
# None timeout means the same as sock.settimeout(None)
self.assertTrue(socket.getdefaulttimeout() is None)
socket.setdefaulttimeout(30)
try:
self.cli = socket.create_connection((HOST, self.port), timeout=None)
self.addCleanup(self.cli.close)
finally:
socket.setdefaulttimeout(None)
self.assertEqual(self.cli.gettimeout(), None)
示例11: testTimeoutDefault
# 需要导入模块: import socket [as 别名]
# 或者: from socket import getdefaulttimeout [as 别名]
def testTimeoutDefault(self):
# default -- use global socket timeout
self.assertIsNone(socket.getdefaulttimeout())
socket.setdefaulttimeout(30)
try:
ftp = ftplib.FTP(HOST)
finally:
socket.setdefaulttimeout(None)
self.assertEqual(ftp.sock.gettimeout(), 30)
self.evt.wait()
ftp.close()
示例12: testTimeoutNone
# 需要导入模块: import socket [as 别名]
# 或者: from socket import getdefaulttimeout [as 别名]
def testTimeoutNone(self):
# no timeout -- do not use global socket timeout
self.assertIsNone(socket.getdefaulttimeout())
socket.setdefaulttimeout(30)
try:
ftp = ftplib.FTP(HOST, timeout=None)
finally:
socket.setdefaulttimeout(None)
self.assertIsNone(ftp.sock.gettimeout())
self.evt.wait()
ftp.close()
示例13: testTimeoutNone
# 需要导入模块: import socket [as 别名]
# 或者: from socket import getdefaulttimeout [as 别名]
def testTimeoutNone(self):
self.assertIsNone(socket.getdefaulttimeout())
socket.setdefaulttimeout(30)
try:
smtp = smtplib.SMTP(HOST, self.port, timeout=None)
finally:
socket.setdefaulttimeout(None)
self.assertIsNone(smtp.sock.gettimeout())
smtp.close()
示例14: test_http_basic
# 需要导入模块: import socket [as 别名]
# 或者: from socket import getdefaulttimeout [as 别名]
def test_http_basic(self):
self.assertIsNone(socket.getdefaulttimeout())
url = test_support.TEST_HTTP_URL
with test_support.transient_internet(url, timeout=None):
u = _urlopen_with_retry(url)
self.assertIsNone(u.fp._sock.fp._sock.gettimeout())
示例15: test_http_default_timeout
# 需要导入模块: import socket [as 别名]
# 或者: from socket import getdefaulttimeout [as 别名]
def test_http_default_timeout(self):
self.assertIsNone(socket.getdefaulttimeout())
url = test_support.TEST_HTTP_URL
with test_support.transient_internet(url):
socket.setdefaulttimeout(60)
try:
u = _urlopen_with_retry(url)
finally:
socket.setdefaulttimeout(None)
self.assertEqual(u.fp._sock.fp._sock.gettimeout(), 60)