本文整理汇总了Python中test.support.bind_port函数的典型用法代码示例。如果您正苦于以下问题:Python bind_port函数的具体用法?Python bind_port怎么用?Python bind_port使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了bind_port函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: testSendall
def testSendall(self):
# Test sendall() timeout
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as serv:
support.bind_port(serv, self.localhost)
serv.listen(5)
self.sock.connect(serv.getsockname())
# Send a lot of data in order to bypass buffering in the TCP stack.
self._sock_operation(100, 1.5, 'sendall', b"X" * 200000)
开发者ID:5outh,项目名称:Databases-Fall2014,代码行数:8,代码来源:test_timeout.py
示例2: testSendto
def testSendto(self):
# Test sendto() timeout
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as serv:
support.bind_port(serv, self.localhost)
serv.listen(5)
self.sock.connect(serv.getsockname())
# The address argument is ignored since we already connected.
self._sock_operation(100, 1.5, "sendto", b"X" * 200000, serv.getsockname())
开发者ID:RockySteveJobs,项目名称:python-for-android,代码行数:8,代码来源:test_timeout.py
示例3: testAcceptTimeout
def testAcceptTimeout(self):
# Test accept() timeout
_timeout = 2
self.sock.settimeout(_timeout)
# Prevent "Address already in use" socket exceptions
support.bind_port(self.sock, self.localhost)
self.sock.listen(5)
_t1 = time.time()
self.assertRaises(socket.error, self.sock.accept)
_t2 = time.time()
_delta = abs(_t1 - _t2)
self.assertTrue(_delta < _timeout + self.fuzz,
"timeout (%g) is %g seconds more than expected (%g)"
%(_delta, self.fuzz, _timeout))
开发者ID:henrywoo,项目名称:Python3.1.3-Linux,代码行数:16,代码来源:test_timeout.py
示例4: testRecvfromTimeout
def testRecvfromTimeout(self):
# Test recvfrom() timeout
_timeout = 2
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.sock.settimeout(_timeout)
# Prevent "Address already in use" socket exceptions
support.bind_port(self.sock, self.localhost)
_t1 = time.time()
self.assertRaises(socket.error, self.sock.recvfrom, 8192)
_t2 = time.time()
_delta = abs(_t1 - _t2)
self.assertTrue(_delta < _timeout + self.fuzz,
"timeout (%g) is %g seconds more than expected (%g)"
%(_delta, self.fuzz, _timeout))
开发者ID:henrywoo,项目名称:Python3.1.3-Linux,代码行数:16,代码来源:test_timeout.py
示例5: __init__
def __init__(self, process_id, storage_handler, _config=None):
"""
Args:
process_id: an index in the config file
_config: custom config values passed in for unit testing
"""
self.process_id = process_id
self.storage_handler = storage_handler
self.MESSAGE_MAX_SIZE = 1024
self.request_counter = 0 # This is used to generate request IDs
if _config == None:
# Initialize the UDP socket.
self.config = config
ip, port, _ = config['hosts'][process_id]
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
self.sock.bind((ip, port))
self.input = sys.stdin
self.output = sys.stdout
self.is_testing = False
else:
# Unit testing mode
from test import support
self.config = _config
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
port = support.bind_port(self.sock)
self.port = port
self.config['hosts'][process_id][1] = port
self.input = self.config['input'][process_id]
self.output = self.config['output'][process_id]
self.is_testing = True
开发者ID:daeyun,项目名称:distributed-key-value-store,代码行数:32,代码来源:input_handler.py
示例6: test_send
def test_send(self):
self.evt = threading.Event()
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock.settimeout(3)
self.port = support.bind_port(self.sock)
cap = BytesIO()
args = (self.evt, cap, self.sock)
threading.Thread(target=capture_server, args=args).start()
# wait a little longer for the server to initialize (it sometimes
# refuses connections on slow machines without this wait)
time.sleep(0.2)
data = b"Suppose there isn't a 16-ton weight?"
d = dispatcherwithsend_noread()
d.create_socket(socket.AF_INET, socket.SOCK_STREAM)
d.connect((HOST, self.port))
# give time for socket to connect
time.sleep(0.1)
d.send(data)
d.send(data)
d.send(b'\n')
n = 1000
while d.out_buffer and n > 0:
asyncore.poll()
n -= 1
self.evt.wait()
self.assertEqual(cap.getvalue(), data*2)
开发者ID:henrywoo,项目名称:Python3.1.3-Linux,代码行数:34,代码来源:test_asyncore.py
示例7: setUp
def setUp(self):
self.evt = threading.Event()
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock.settimeout(3)
self.port = test_support.bind_port(self.sock)
threading.Thread(target=self.server, args=(self.evt,self.sock)).start()
time.sleep(.1)
开发者ID:henrywoo,项目名称:Python3.1.3-Linux,代码行数:7,代码来源:test_poplib.py
示例8: __init__
def __init__(self, event):
threading.Thread.__init__(self)
self.event = event
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.port = support.bind_port(self.sock)
# This will be set if the client wants us to wait before echoing data
# back.
self.start_resend_event = None
开发者ID:vemulasravan6,项目名称:cpython,代码行数:8,代码来源:test_asynchat.py
示例9: setUp
def setUp(self):
self.evt = threading.Event()
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock.settimeout(15)
self.port = support.bind_port(self.sock)
servargs = (self.evt, b"220 Hola mundo\n", self.sock)
threading.Thread(target=server, args=servargs).start()
self.evt.wait()
self.evt.clear()
开发者ID:henrywoo,项目名称:Python3.1.3-Linux,代码行数:9,代码来源:test_smtplib.py
示例10: setUp
def setUp(self):
self.evt = threading.Event()
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock.settimeout(60) # Safety net. Look issue 11812
self.port = support.bind_port(self.sock)
self.thread = threading.Thread(target=server, args=(self.evt,self.sock))
self.thread.setDaemon(True)
self.thread.start()
self.evt.wait()
开发者ID:Logotrop,项目名称:trida,代码行数:9,代码来源:test_telnetlib.py
示例11: setUp
def setUp(self):
self.evt = threading.Event()
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock.settimeout(3)
self.port = support.bind_port(self.sock)
threading.Thread(target=self.server, args=(self.evt,self.sock)).start()
# Wait for the server to be ready.
self.evt.wait()
self.evt.clear()
ftplib.FTP.port = self.port
开发者ID:pombredanne,项目名称:cpython,代码行数:10,代码来源:test_ftplib.py
示例12: setUp
def setUp(self):
self.old_stdout = sys.stdout
self.output = io.StringIO()
sys.stdout = self.output
self.evt = threading.Event()
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock.settimeout(15)
self.port = support.bind_port(self.sock)
servargs = (self.evt, self.respdata, self.sock)
threading.Thread(target=server, args=servargs).start()
self.evt.wait()
self.evt.clear()
开发者ID:pykomke,项目名称:Kurz_Python_KE,代码行数:13,代码来源:test_smtplib.py
示例13: setUp
def setUp(self):
self.evt = threading.Event()
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock.settimeout(20)
self.port = support.bind_port(self.sock)
self.server_thread = threading.Thread(target=self.server)
self.server_thread.daemon = True
self.server_thread.start()
# Wait for the server to be ready.
self.evt.wait()
self.evt.clear()
self.old_port = ftplib.FTP.port
ftplib.FTP.port = self.port
开发者ID:Apoorvadabhere,项目名称:cpython,代码行数:13,代码来源:test_ftplib.py
示例14: __init__
def __init__(self, certificate, ssl_version=None,
certreqs=None, cacerts=None, expect_bad_connects=False,
chatty=True, connectionchatty=False, starttls_server=False):
if ssl_version is None:
ssl_version = ssl.PROTOCOL_TLSv1
if certreqs is None:
certreqs = ssl.CERT_NONE
self.certificate = certificate
self.protocol = ssl_version
self.certreqs = certreqs
self.cacerts = cacerts
self.expect_bad_connects = expect_bad_connects
self.chatty = chatty
self.connectionchatty = connectionchatty
self.starttls_server = starttls_server
self.sock = socket.socket()
self.port = support.bind_port(self.sock)
self.flag = None
self.active = False
threading.Thread.__init__(self)
self.daemon = True
开发者ID:Kanma,项目名称:Athena-Dependencies-Python,代码行数:21,代码来源:test_ssl.py
示例15: test_send
def test_send(self):
evt = threading.Event()
sock = socket.socket()
sock.settimeout(3)
port = support.bind_port(sock)
cap = BytesIO()
args = (evt, cap, sock)
t = threading.Thread(target=capture_server, args=args)
t.start()
try:
# wait a little longer for the server to initialize (it sometimes
# refuses connections on slow machines without this wait)
time.sleep(0.2)
data = b"Suppose there isn't a 16-ton weight?"
d = dispatcherwithsend_noread()
d.create_socket()
d.connect((support.HOST, port))
# give time for socket to connect
time.sleep(0.1)
d.send(data)
d.send(data)
d.send(b'\n')
n = 1000
while d.out_buffer and n > 0:
asyncore.poll()
n -= 1
evt.wait()
self.assertEqual(cap.getvalue(), data*2)
finally:
t.join(timeout=TIMEOUT)
if t.is_alive():
self.fail("join() timed out")
开发者ID:5outh,项目名称:Databases-Fall2014,代码行数:39,代码来源:test_asyncore.py
示例16: __init__
def __init__(self, process_id, delay_times, _config=None):
"""
Args:
process_id: an index in the config file
delay_times: process_id of this node
_config: custom config values passed in for unit testing
"""
self.MESSAGE_MAX_SIZE = 1024
self.NUM_REPLICAS = 3
self.local_storage = {}
self.required_num_responses = {}
self.version_num = {}
self.replica_response_values = {}
self.search_replica_values = {}
if _config == None:
self.config = config
# Initialize the UDP socket.
ip, _, port = self.config['hosts'][process_id]
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
self.sock.bind((ip, port))
self.is_testing = False
else:
# Unit testing mode
from test import support
self.config = _config
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
port = support.bind_port(self.sock)
self.config['hosts'][process_id][2] = port
self.input = self.config['input'][process_id]
self.output = self.config['output'][process_id]
self.is_testing = True
self.process_id = process_id
self.set_delay_times(delay_times)
开发者ID:daeyun,项目名称:distributed-key-value-store,代码行数:36,代码来源:storage_handler.py
示例17: setUp
def setUp(self):
self.serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.port = support.bind_port(self.serv)
self.serv.listen(1)
开发者ID:LinkedModernismProject,项目名称:web_code,代码行数:4,代码来源:test_socket.py
示例18: setUp
def setUp(self):
self.serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
TimeoutTest.PORT = support.bind_port(self.serv)
self.serv.listen(5)
开发者ID:chidea,项目名称:GoPythonDLLWrapper,代码行数:4,代码来源:test_httplib.py
示例19: test_bind_port
def test_bind_port(self):
s = socket.socket()
support.bind_port(s)
s.listen()
s.close()
开发者ID:MYSHLIFE,项目名称:cpython-1,代码行数:5,代码来源:test_support.py
示例20: testAcceptTimeout
def testAcceptTimeout(self):
# Test accept() timeout
support.bind_port(self.sock, self.localhost)
self.sock.listen(5)
self._sock_operation(1, 1.5, 'accept')
开发者ID:5outh,项目名称:Databases-Fall2014,代码行数:5,代码来源:test_timeout.py
注:本文中的test.support.bind_port函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论