Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def startClient(wsuri, debug = False):
factory = BroadcastClientFactory(wsuri, debug)
connectWS(factory)
return True
def run():
"""
Run the helga process
"""
backend = _get_backend(settings.SERVER.get('TYPE', 'irc'))
smokesignal.emit('started')
factory = backend.Factory()
if settings.SERVER.get('TYPE', False) == 'slack':
connectWS(factory=factory)
elif settings.SERVER.get('SSL', False):
reactor.connectSSL(settings.SERVER['HOST'],
settings.SERVER['PORT'],
factory,
ssl.ClientContextFactory())
else:
reactor.connectTCP(settings.SERVER['HOST'],
settings.SERVER['PORT'],
factory)
reactor.run()
# create a WS server factory with our protocol
url = "wss://" + hostname + "/speech-to-text/api/v1/recognize?model=" + args.model
summary = {}
factory = WSInterfaceFactory(q, summary, args.dirOutput, args.contentType, args.model, url, headers, debug=False)
factory.protocol = WSInterfaceProtocol
for i in range(min(int(args.threads),q.qsize())):
factory.prepareUtterance()
# SSL client context: default
if factory.isSecure:
contextFactory = ssl.ClientContextFactory()
else:
contextFactory = None
connectWS(factory, contextFactory)
reactor.run()
# dump the hypotheses to the output file
fileHypotheses = args.dirOutput + "/hypotheses2.txt"
f = open(fileHypotheses,"w")
counter = 1
successful = 0
emptyHypotheses = 0
for key, value in (sorted(summary.items())):
if value['status']['code'] == 1000:
print key, ": ", value['status']['code'], " ", value['hypothesis'].encode('utf-8')
successful += 1
if value['hypothesis'][0] == "":
emptyHypotheses += 1
else:
def connect(self):
log.info('Connecting to {}'.format(self.url))
connectWS(self)
print("WebSocket connection closed: {0}".format(reason), "code: ", code, "clean: ", wasClean, "reason: ", reason)
self.summary[self.uttNumber]['status']['code'] = code
self.summary[self.uttNumber]['status']['reason'] = reason
# create a new WebSocket connection if there are still utterances in the queue that need to be processed
self.queue.task_done()
if self.factory.prepareUtterance() == False:
return
# SSL client context: default
if self.factory.isSecure:
contextFactory = ssl.ClientContextFactory()
else:
contextFactory = None
connectWS(self.factory, contextFactory)
def _start_socket(self, path, callback, prefix='ws/'):
if path in self._conns:
return False
factory_url = self.STREAM_URL + prefix + path
factory = BinanceClientFactory(factory_url)
factory.protocol = BinanceClientProtocol
factory.callback = callback
factory.reconnect = True
context_factory = ssl.ClientContextFactory()
self._conns[path] = connectWS(factory, context_factory)
return path
def _stream(self): # pragma: no cover
"""Runs in a sub-process to perform stream consumption"""
self.factory.protocol = LiveStream
self.factory.datasift = {
'on_open': self._on_open,
'on_close': self._on_close,
'on_message': self._on_message,
'send_message': None
}
if self.config.ssl:
from twisted.internet import ssl
options = ssl.optionsForClientTLS(hostname=WEBSOCKET_HOST)
connectWS(self.factory, options)
else:
connectWS(self.factory)
reactor.run()
def _start_socket(self, path, callback, prefix='ws/'):
if path in self._conns:
return False
factory_url = self.STREAM_URL + prefix + path
factory = BinanceClientFactory(factory_url)
factory.protocol = BinanceClientProtocol
factory.callback = callback
factory.reconnect = True
context_factory = ssl.ClientContextFactory()
self._conns[path] = connectWS(factory, context_factory)
return path
def hello(host, port, target):
from twisted.internet import reactor
if KEY is not None:
key = {'X-Trueseeing2-Key':KEY}
else:
key = None
with open(target, 'rb') as f:
factory = WebSocketClientFactory(u"wss://%s:%d/analyze" % (host, port), headers=key)
factory.isSecure = True
factory.protocol = TrueseeingClientProtocol.withFile(f)
connectWS(factory)
reactor.run()
# ui
controller = Controller()
stdio.StandardIO(controller)
factory = CoinigyWSClientFactory(_END_POINT, controller, config_dict)
factory.protocol = CoinigyWSClient
if factory.isSecure:
contextFactory = ssl.ClientContextFactory()
else:
contextFactory = None
print("Has SSL context factory: {}".format(contextFactory))
connectWS(factory, contextFactory)
reactor.run()