本文整理汇总了Python中geventwebsocket.WebSocketError方法的典型用法代码示例。如果您正苦于以下问题:Python geventwebsocket.WebSocketError方法的具体用法?Python geventwebsocket.WebSocketError怎么用?Python geventwebsocket.WebSocketError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类geventwebsocket
的用法示例。
在下文中一共展示了geventwebsocket.WebSocketError方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_events
# 需要导入模块: import geventwebsocket [as 别名]
# 或者: from geventwebsocket import WebSocketError [as 别名]
def get_events(self, ws):
"""
Yields valid messages from the websocket. Only yields well formed
messages. In the case of an illformed message, an error event is sent
to the client.
"""
while True:
try:
raw = ws.receive()
except WebSocketError:
return
try:
event = json.loads(raw)
event['e']
except (ValueError, TypeError) as v:
self.send_error(ws, 'event', str(v))
return
except KeyError:
self.send_error(ws, 'event', "No 'e' field sent")
return
yield event
示例2: do_install
# 需要导入模块: import geventwebsocket [as 别名]
# 或者: from geventwebsocket import WebSocketError [as 别名]
def do_install(self, ws, message):
def go_do_install():
with tempfile.NamedTemporaryFile() as f:
f.write(message)
f.flush()
try:
self.load_pbws([f.name], cache=True)
AppInstaller(self.pebble.pebble, f.name, blobdb_client=self.pebble.blobdb).install()
except:
try:
ws.send(bytearray([0x05, 0x00, 0x00, 0x00, 0x01]))
except WebSocketError:
pass
raise
else:
try:
ws.send(bytearray([0x05, 0x00, 0x00, 0x00, 0x00]))
except WebSocketError:
pass
gevent.spawn(go_do_install)
示例3: progress_sender
# 需要导入模块: import geventwebsocket [as 别名]
# 或者: from geventwebsocket import WebSocketError [as 别名]
def progress_sender(job, channel, interval=5, stat=None):
stat = stat or (lambda data: data)
data = job.data
i = 10
try:
while True:
# if thread died due to some reason, still send 10 stats
if not job.thread.is_alive():
logger.info('job %s died: %s' % (job.ident, repr(job.err)))
if i == 0:
channel.ws.close()
break
i -= 1
logger.info('jod %s on channel %s send progress: %s' %
(job.ident, repr(channel), repr(stat(data))))
to_send = stat(data)
if channel.report_system_load and type(to_send) == type({}):
to_send['system_load'] = channel.get_system_load()
channel.ws.send(utfjson.dump(to_send))
if job.progress_available.wait(interval):
job.progress_available.clear()
except WebSocketError as e:
if channel.ws.closed == True:
logger.info('the client has closed the connection')
else:
logger.exception(('got websocket error when sending progress on' +
' channel %s: %s') % (repr(channel), repr(e)))
except Exception as e:
logger.exception('got exception when sending progress on channel %s: %s'
% (repr(channel), repr(e)))
channel.ws.close()
示例4: send_error
# 需要导入模块: import geventwebsocket [as 别名]
# 或者: from geventwebsocket import WebSocketError [as 别名]
def send_error(self, ws, error_type, error_data):
"""
Sends an error event back to the client.
"""
try:
ws.send(fmt_err_msg(error_type, error_data, serial=json.dumps))
except WebSocketError:
return
示例5: slaughter
# 需要导入模块: import geventwebsocket [as 别名]
# 或者: from geventwebsocket import WebSocketError [as 别名]
def slaughter(self, uuid, mode='soft'):
"""
Slaughters a session, closing all clients and the tracer.
This also removes the session from the list of sessions.
If mode is 'soft', the tracer clears all breakpoints and continues
execution. If it is 'hard', it raises a QdbQuit in the tracer process.
"""
session = self._sessions.get(uuid)
if not session:
return # Slaughtering a session that does not exits.
# Close all the clients.
disable_event = fmt_msg('disable')
self.send_to_clients(uuid, event=disable_event)
for client in session.clients:
try:
client.close()
except WebSocketError as e:
if str(e) != 'Socket is dead' or e.errno not in safe_errnos:
log.exception(
'Exception caught while killing client for '
'session %s:' % uuid
)
# Close the tracer if we had one.
if session.tracer:
try:
disable_event['p'] = mode
self.send_to_tracer(uuid, event=disable_event)
session.tracer.close()
except socket.error as e:
if e.errno not in safe_errnos:
log.exception(
'Exception caught while killing tracer for session %s:'
% uuid
)
del self._sessions[uuid]
log.info('Debugging session %s has been terminated' % uuid)
示例6: data_socket
# 需要导入模块: import geventwebsocket [as 别名]
# 或者: from geventwebsocket import WebSocketError [as 别名]
def data_socket(ws):
data = 0
while True:
try:
ws.send('Some Data: %d' % data)
except WebSocketError as e:
print('Caught WebSocketError: %s' % e)
break
sleep(2)
data += 1
示例7: handle_ws
# 需要导入模块: import geventwebsocket [as 别名]
# 或者: from geventwebsocket import WebSocketError [as 别名]
def handle_ws(self, environ, start_response):
if environ['PATH_INFO'] == '/':
ws = Websocket(environ['wsgi.websocket'])
self.websockets.append(ws)
self.on_open(ws)
while True:
try:
self.on_message(ws, ws.receive())
except WebSocketError:
break
self.on_close(ws)
示例8: broadcast
# 需要导入模块: import geventwebsocket [as 别名]
# 或者: from geventwebsocket import WebSocketError [as 别名]
def broadcast(self, message):
to_remove = []
for i, ws in enumerate(self.websockets):
if ws.authed:
try:
ws.send(message)
except (WebSocketError, ssl.SSLError):
to_remove.append(i)
for i in reversed(to_remove):
del self.websockets[i]
# https://pebbletechnology.atlassian.net/wiki/pages/viewpage.action?pageId=491742
示例9: do_phone_info
# 需要导入模块: import geventwebsocket [as 别名]
# 或者: from geventwebsocket import WebSocketError [as 别名]
def do_phone_info(self, ws, message):
try:
ws.send(bytearray("\x06pypkjs,0.0.0,qemu"))
except WebSocketError:
pass
示例10: get_realtime_tlm
# 需要导入模块: import geventwebsocket [as 别名]
# 或者: from geventwebsocket import WebSocketError [as 别名]
def get_realtime_tlm(self):
"""Handles realtime packet dispatch via websocket layers"""
pad = bytearray(1)
websocket = bottle.request.environ.get('wsgi.websocket')
if not websocket:
bottle.abort(400, 'Expected WebSocket request.')
empty_map = dict() # default empty object for probing websocket connection
req_env = bottle.request.environ
client_ip = req_env.get('HTTP_X_FORWARDED_FOR') or req_env.get('REMOTE_ADDR') or "(unknown)"
self.dbg_message('Creating a new web-socket session with client IP '+client_ip)
try:
while not websocket.closed:
try:
self.dbg_message("Polling Telemtry queue...")
uid, data = self._tlmQueue.popleft(timeout=30)
pkt_defn = self._get_tlm_packet_def(uid)
if not pkt_defn:
continue
pkt_name = pkt_defn.name
ait_pkt = ait.core.tlm.Packet(pkt_defn, data=data)
openmct_pkt = self.format_tlmpkt_for_openmct(ait_pkt)
openmct_pkt_jsonstr = json.dumps(openmct_pkt, default=self.datetime_jsonifier)
self.dbg_message("Sending realtime telemtry websocket msg: "+openmct_pkt_jsonstr)
websocket.send(openmct_pkt_jsonstr)
except IndexError:
# If no telemetry has been received by the GUI
# server after timeout seconds, "probe" the client
# websocket connection to make sure it's still
# active and if so, keep it alive. This is
# accomplished by sending an empty JSON object.
self.dbg_message("Telemtry queue is empty.")
if not websocket.closed:
websocket.send(json.dumps(empty_map))
self.dbg_message('Web-socket session closed with client IP '+client_ip)
except geventwebsocket.WebSocketError as wser:
log.warn('Web-socket session had an error with client IP '+client_ip+': '+str(wser))
示例11: handle_client
# 需要导入模块: import geventwebsocket [as 别名]
# 或者: from geventwebsocket import WebSocketError [as 别名]
def handle_client(self, environ, start_response):
path = environ['PATH_INFO']
ws = environ['wsgi.websocket']
addr = environ['REMOTE_ADDR']
try:
match = self.route.match(path)
if not match:
# This did not match our route.
return
log.info('Client request from %s' % addr)
uuid = match.group(1)
start_event = None
with Timeout(self.auth_timeout, False):
start_event = self.get_event(ws)
failed = False
message = ''
# Fall through the various ways to fail to generate a more helpful
# error message.
if not start_event:
message = 'No start event received'
failed = True
elif start_event['e'] != 'start':
message = "First event must be of type: 'start'"
failed = True
elif not self.auth_fn(start_event.get('p', '')):
log.warn('Client %s failed to authenticate' % addr)
message = 'Authentication failed'
failed = True
if failed:
try:
self.send_error(ws, 'auth', message)
ws.send(fmt_msg('disable', serial=json.dumps))
except WebSocketError:
# We are unable to send the disable message for some
# reason; however, they already failed auth so suppress
# it and close.
pass
return
if not self.session_store.attach_client(uuid, ws):
# We are attaching to a client that does not exist.
return
self.session_store.send_to_tracer(uuid, event=start_event)
for event in self.get_events(ws):
self.session_store.send_to_tracer(uuid, event=event)
finally:
log.info('Closing websocket to client %s' % addr)
ws.close()