本文整理汇总了Python中tornado.websocket.websocket_connect方法的典型用法代码示例。如果您正苦于以下问题:Python websocket.websocket_connect方法的具体用法?Python websocket.websocket_connect怎么用?Python websocket.websocket_connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tornado.websocket
的用法示例。
在下文中一共展示了websocket.websocket_connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _connect
# 需要导入模块: from tornado import websocket [as 别名]
# 或者: from tornado.websocket import websocket_connect [as 别名]
def _connect(self):
ws = await websocket.websocket_connect(self._server_ws_url)
ws.__class__ = SafeWebSocket
await ws.write_message({
"command": "handshake",
"name": self._name,
"owner": self._owner,
"secret": self._secret,
"url": self._provider_url,
"priority": self._priority, # the large the importanter
})
msg = await ws.read_message()
logger.info("WS receive: %s", msg)
return ws
示例2: run_tests
# 需要导入模块: from tornado import websocket [as 别名]
# 或者: from tornado.websocket import websocket_connect [as 别名]
def run_tests():
url = options.url + '/getCaseCount'
control_ws = yield websocket_connect(url, None)
num_tests = int((yield control_ws.read_message()))
logging.info('running %d cases', num_tests)
msg = yield control_ws.read_message()
assert msg is None
for i in range(1, num_tests + 1):
logging.info('running test case %d', i)
url = options.url + '/runCase?case=%d&agent=%s' % (i, options.name)
test_ws = yield websocket_connect(url, None, compression_options={})
while True:
message = yield test_ws.read_message()
if message is None:
break
test_ws.write_message(message, binary=isinstance(message, bytes))
url = options.url + '/updateReports?agent=%s' % options.name
update_ws = yield websocket_connect(url, None)
msg = yield update_ws.read_message()
assert msg is None
IOLoop.instance().stop()
示例3: _connect
# 需要导入模块: from tornado import websocket [as 别名]
# 或者: from tornado.websocket import websocket_connect [as 别名]
def _connect(self):
ws = await websocket.websocket_connect(self._ws_url, ping_interval=3)
ws.__class__ = SafeWebSocket
await ws.write_message({
"command": "handshake",
"name": self._name,
"owner": self._owner,
"secret": self._secret,
"url": self._provider_url,
"priority": self._priority, # the large the importanter
})
msg = await ws.read_message()
logger.info("WS receive: %s", msg)
return ws
示例4: wsquery
# 需要导入模块: from tornado import websocket [as 别名]
# 或者: from tornado.websocket import websocket_connect [as 别名]
def wsquery(wsurl,msg): # Synchrone call, with tornado
""" In a simple world, could be (with websocket_client pypi):
ws = websocket.create_connection(wsurl)
ws.send(msg)
resp=ws.recv()
ws.close()
return resp
"""
@gen.coroutine
def fct(ioloop,u,content):
cnx=yield websocket_connect(u)
cnx.write_message(msg)
resp=yield cnx.read_message()
cnx.close()
ioloop.stop()
ioloop.response=resp
ioloop = IOLoop.instance()
fct(ioloop,wsurl,msg)
ioloop.start()
return ioloop.response
示例5: _on_open
# 需要导入模块: from tornado import websocket [as 别名]
# 或者: from tornado.websocket import websocket_connect [as 别名]
def _on_open(self):
# Only proxy local connections.
proxy_path = self.request.uri.replace(self._PATH_PREFIX, '/')
proxy_url = '{}://{}{}'.format(_PROTOCOL_MAP[self.request.protocol],
self.request.host, proxy_path)
yield self._attach_auth_cookies()
self.log.info('proxying WebSocket connection to: {}'.format(proxy_url))
proxy_request = httpclient.HTTPRequest(
url=proxy_url,
method='GET',
headers=self.request.headers,
body=None,
ca_certs=self.ca_certs)
_modify_proxy_request_test_only(proxy_request)
client = yield websocket.websocket_connect(
proxy_request, on_message_callback=self._on_proxied_message)
raise gen.Return(client)
示例6: test_proxied_post_base64_body
# 需要导入模块: from tornado import websocket [as 别名]
# 或者: from tornado.websocket import websocket_connect [as 别名]
def test_proxied_post_base64_body(self):
client = yield websocket.websocket_connect(
self.get_ws_connection_request('http_over_websocket'))
client.write_message(
self.get_request_json(
'/api/sessions',
'1234',
method='POST',
body_base64=base64.b64encode(
'the_data'.encode('utf-8')).decode('utf-8')))
response_body = yield client.read_message()
response = json.loads(response_body)
self.assertEqual(200, response['status'])
self.assertEqual('the_data',
base64.b64decode(response['data']).decode('utf-8'))
self.assertEqual('1234', response['message_id'])
self.assertTrue(response['done'])
示例7: test_auth_url_provided_forwards_cookies_and_propagates_xsrf
# 需要导入模块: from tornado import websocket [as 别名]
# 或者: from tornado.websocket import websocket_connect [as 别名]
def test_auth_url_provided_forwards_cookies_and_propagates_xsrf(self):
auth_url = self.get_server_base_url() + '/fake-auth'
encoded_query_args = urlparse.urlencode(
{'jupyter_http_over_ws_auth_url': auth_url})
request = self.get_ws_connection_request('http_over_websocket?' +
encoded_query_args)
client = yield websocket.websocket_connect(request)
client.write_message(
self.get_request_json(
'/api/sessions', '1234', method='POST', body='somedata'))
response_body = yield client.read_message()
response = json.loads(response_body)
self.assertEqual(200, response['status'])
self.assertEqual('somedata',
base64.b64decode(response['data']).decode('utf-8'))
self.assertEqual('1234', response['message_id'])
self.assertIn(TEST_XSRF_HEADER, response['headers'])
self.assertEqual(FAKE_XSRF_VALUE, response['headers'][TEST_XSRF_HEADER])
self.assertTrue(response['done'])
示例8: test_auth_url_provided_forwards_cookies
# 需要导入模块: from tornado import websocket [as 别名]
# 或者: from tornado.websocket import websocket_connect [as 别名]
def test_auth_url_provided_forwards_cookies(self):
auth_url = self.get_server_base_url() + '/fake-auth'
encoded_query_args = urlparse.urlencode(
{'jupyter_http_over_ws_auth_url': auth_url})
request = self.get_ws_connection_request('http_over_websocket?' +
encoded_query_args)
client = yield websocket.websocket_connect(request)
client.write_message(
self.get_request_json('/requires-cookies-from-fake-auth', '1234'))
response_body = yield client.read_message()
response = json.loads(response_body)
self.assertEqual(200, response['status'])
# RequiresCookieFromFakeAuthHandler writes cookies that should have
# been received by performing a request to the auth url.
self.assertEqual('X-Test-Cookie: "1" X-Other-Test-Cookie: "2"',
base64.b64decode(response['data']).decode('utf-8'))
self.assertEqual('1234', response['message_id'])
self.assertTrue(response['done'])
示例9: test_auth_url_provided_fails
# 需要导入模块: from tornado import websocket [as 别名]
# 或者: from tornado.websocket import websocket_connect [as 别名]
def test_auth_url_provided_fails(self):
auth_url = self.get_server_base_url() + '/fake-auth?always_fail=1'
encoded_query_args = urlparse.urlencode(
{'jupyter_http_over_ws_auth_url': auth_url})
request = self.get_ws_connection_request('http_over_websocket?' +
encoded_query_args)
client = yield websocket.websocket_connect(request)
client.write_message(
self.get_request_json('/requires-cookies-from-fake-auth', '1234'))
response_body = yield client.read_message()
response = json.loads(response_body)
self.assertEqual('1234', response['message_id'])
self.assertEqual(500, response['status'])
self.assertEqual(
'Uncaught server-side exception. Check logs for additional details.',
response['statusText'])
self.assertTrue(response['done'])
示例10: _assertCrossDomainRequestFails
# 需要导入模块: from tornado import websocket [as 别名]
# 或者: from tornado.websocket import websocket_connect [as 别名]
def _assertCrossDomainRequestFails(self, auth_url):
encoded_query_args = urlparse.urlencode(
{'jupyter_http_over_ws_auth_url': auth_url})
request = self.get_ws_connection_request('http_over_websocket?' +
encoded_query_args)
with testing.ExpectLog(
'tornado.application',
'Uncaught error when proxying request',
required=True) as expect_log:
client = yield websocket.websocket_connect(request)
client.write_message(
self.get_request_json('/requires-cookies-from-fake-auth-ws', '1234'))
response_body = yield client.read_message()
response = json.loads(response_body)
self.assertEqual('1234', response['message_id'])
self.assertEqual(500, response['status'])
self.assertEqual(
'Uncaught server-side exception. Check logs for additional details.',
response['statusText'])
self.assertTrue(response['done'])
self.assertTrue(expect_log.logged_stack)
示例11: test_diagnostic_handler_no_problems_request
# 需要导入模块: from tornado import websocket [as 别名]
# 或者: from tornado.websocket import websocket_connect [as 别名]
def test_diagnostic_handler_no_problems_request(self):
request = self.get_ws_connection_request('http_over_websocket/diagnose')
request.url += '?min_version=0.0.7'
request.headers.add('Origin', ALLOWED_ORIGIN)
request.headers.add('Cookie', '_xsrf=' + FAKE_XSRF_VALUE)
client = yield websocket.websocket_connect(request)
self.assertIsNotNone(client)
client.write_message('1')
response_body = yield client.read_message()
response = json.loads(response_body)
self.assertEqual(
{
'message_id': '1',
'extension_version': '0.0.7',
'has_authentication_cookie': True,
'is_outdated_extension': False
}, response)
示例12: test_diagnostic_handler_missing_xsrf_cookie
# 需要导入模块: from tornado import websocket [as 别名]
# 或者: from tornado.websocket import websocket_connect [as 别名]
def test_diagnostic_handler_missing_xsrf_cookie(self):
request = self.get_ws_connection_request('http_over_websocket/diagnose')
request.headers.add('Origin', ALLOWED_ORIGIN)
client = yield websocket.websocket_connect(request)
client.write_message('1')
response_body = yield client.read_message()
response = json.loads(response_body)
self.assertEqual(
{
'message_id': '1',
'extension_version': '0.0.7',
'has_authentication_cookie': False,
'is_outdated_extension': False
}, response)
示例13: test_diagnostic_handler_newer_protocol_version_requested
# 需要导入模块: from tornado import websocket [as 别名]
# 或者: from tornado.websocket import websocket_connect [as 别名]
def test_diagnostic_handler_newer_protocol_version_requested(self):
request = self.get_ws_connection_request('http_over_websocket/diagnose')
request.url += '?min_version=0.0.8'
request.headers.add('Origin', ALLOWED_ORIGIN)
request.headers.add('Cookie', '_xsrf=' + FAKE_XSRF_VALUE)
client = yield websocket.websocket_connect(request)
client.write_message('1')
response_body = yield client.read_message()
response = json.loads(response_body)
self.assertEqual(
{
'message_id': '1',
'extension_version': '0.0.7',
'has_authentication_cookie': True,
'is_outdated_extension': True
}, response)
示例14: test_proxied_connection_io
# 需要导入模块: from tornado import websocket [as 别名]
# 或者: from tornado.websocket import websocket_connect [as 别名]
def test_proxied_connection_io(self):
request = self.get_ws_connection_request(
'http_over_websocket/proxied_ws/echoing-ws?someparam=1')
request.headers.add('Origin', ALLOWED_ORIGIN)
request.headers.add('X-Echo-Header', 'example')
client = yield websocket.websocket_connect(request)
self.assertIsNotNone(client)
# EchoingWebSocketHandler writes a message on connection with request
# details.
initial_message = yield client.read_message()
self.assertEqual(
'<ECHO INIT> GET /echoing-ws?someparam=1 X-Echo-Header: example',
initial_message)
client.write_message('1')
echo_message = yield client.read_message()
self.assertEqual('<ECHO RESPONSE> 1', echo_message)
client.write_message('something else!')
echo_message = yield client.read_message()
self.assertEqual('<ECHO RESPONSE> something else!', echo_message)
示例15: connect_kernel
# 需要导入模块: from tornado import websocket [as 别名]
# 或者: from tornado.websocket import websocket_connect [as 别名]
def connect_kernel():
# TODO check status busy/idle
run_sync(manager.list_kernels())
kernels = {
kernel_id: dateparser.parse(kernel["last_activity"])
for kernel_id, kernel in manager._kernels.items()
}
kernel_id = url_escape(sorted(kernels, key=kernels.get)[0])
client = GatewayClient.instance()
url = url_path_join(client.ws_url, client.kernels_endpoint, kernel_id, "channels")
ws_req = HTTPRequest(url=url)
return run_sync(websocket_connect(ws_req))