Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathbridge_hooks.py
More file actions
Latest commit
50 lines (43 loc) · 1.54 KB
/
Copy pathbridge_hooks.py
File metadata and controls
50 lines (43 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
fromflaskimportFlask, request
importhttp.client
importargparse
importsys
importtraceback
fromPythonBridgeimportbridge_globals
defserialize(obj):
returnbridge_globals.msg_service.serializer.serialize(obj)
defdeserialize(text):
returnbridge_globals.msg_service.serializer.deserialize(text)
defobserver(commandId, observerId):
returnlambdaobj: notify_observer(obj, commandId, observerId)
#### NOTIFICATION FUNCTIONS
defnotify(obj, notificationId):
bridge_globals.logger.log("PYTHON: Notify "+str(notificationId))
data= {}
data["type"] ="EVAL"
data["id"] =notificationId
data["value"] =serialize(obj)
bridge_globals.msg_service.send_async_message(data)
defnotify_observer(obj, commandId, observerId):
bridge_globals.logger.log("PYTHON: Notify observer "+str(commandId) +" "+str(observerId))
data= {}
data["type"] ="CALLBACK"
data["commandId"] =commandId
data["observerId"] =observerId
data["value"] =serialize(obj)
rawValue=bridge_globals.msg_service.send_sync_message(data)['value']
returndeserialize(rawValue)
defnotify_error(ex, command):
bridge_globals.logger.log("Error on command: "+str(command.command_id()))
bridge_globals.logger.log("Exception: "+str(ex))
data= {}
data["type"] ="ERR"
data["errMsg"] =str(ex)
data["trace"] =traceback.format_exc(100)
data["commandId"] =command.command_id()
returnbridge_globals.msg_service.send_sync_message(data)
defbridge_inspect(obj):
ifhasattr(obj,'__dict__'):
returnobj.__dict__
else:
return {}