本文整理汇总了Python中autobahn.twisted.websocket.WebSocketClientFactory.origin方法的典型用法代码示例。如果您正苦于以下问题:Python WebSocketClientFactory.origin方法的具体用法?Python WebSocketClientFactory.origin怎么用?Python WebSocketClientFactory.origin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类autobahn.twisted.websocket.WebSocketClientFactory
的用法示例。
在下文中一共展示了WebSocketClientFactory.origin方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUpClientServer
# 需要导入模块: from autobahn.twisted.websocket import WebSocketClientFactory [as 别名]
# 或者: from autobahn.twisted.websocket.WebSocketClientFactory import origin [as 别名]
def setUpClientServer(
self,
use_encryption=False,
origin="https://site.shotgunstudio.com",
host_aliases=None
):
if not host_aliases:
host_aliases = ["site.shotgunstudio.com"]
self._use_encryption = use_encryption
# Create a mockgun instance and add support for the _call_rpc method which is used to get
# the secret.
sg_host = "https://127.0.0.1"
Shotgun.set_schema_paths(
os.path.join(fixtures_root, "mockgun", "schema.pickle"),
os.path.join(fixtures_root, "mockgun", "schema_entity.pickle")
)
self._mockgun = Shotgun(sg_host)
self._mockgun._call_rpc = self._call_rpc
self._mockgun.server_info = {
"shotgunlocalhost_browser_integration_enabled": True
}
# Set up an encryption key.
self._ws_server_secret = base64.urlsafe_b64encode(os.urandom(32))
self._fernet = Fernet(self._ws_server_secret)
# Create the user who will be making all the requests.
self._user = self._mockgun.create("HumanUser", {"name": "Gilles Pomerleau"})
# Pretend there is a current bundle loaded.
patched = patch("sgtk.platform.current_bundle", return_value=Mock(shotgun=self._mockgun))
patched.start()
self.addCleanup(patched.stop)
from tk_framework_desktopserver import Server, shotgun
patched = patch.object(Server, "Notifier", new=Mock())
patched.start()
self.addCleanup(patched.stop)
port = find_free_port()
# Initialize the websocket server.
self.server = Server(
keys_path=os.path.join(fixtures_root, "certificates"),
encrypt=use_encryption,
host="https://site.shotgunstudio.com",
user_id=self._user["id"],
host_aliases=host_aliases,
port=port
)
patched = patch.object(
shotgun, "get_shotgun_api",
new=lambda _, host, process_manager, wss_key: MockShotgunApi(host, process_manager, wss_key)
)
patched.start()
self.addCleanup(patched.stop)
# Do not call server.start() as this will also launch the reactor, which was already
# launched by twisted.trial
self.server._start_server()
# Create the client connection to the websocket server.
context_factory = ssl.DefaultOpenSSLContextFactory(
os.path.join(fixtures_root, "certificates", "server.key"),
os.path.join(fixtures_root, "certificates", "server.crt")
)
# This will be returned by the setUp method to signify that we're done setuping the test.
connection_ready_deferred = Deferred()
test_case = self
class ClientProtocol(WebSocketClientProtocol):
"""
This class will use Deferred instances to notify that the test is ready to start
and to notify the test that a payload has arrived.
"""
def __init__(self):
super(ClientProtocol, self).__init__()
self._on_message_deferred = None
def onConnect(self, response):
"""
Informs the unit test framework that we're connected to the server.
"""
test_case.client_protocol = self
connection_ready_deferred.callback(None)
def sendMessage(self, payload, is_binary):
"""
Sends a message to the websocket server.
:returns: A deferred that will be called when the associated response comes back.
.. note::
#.........这里部分代码省略.........