68 obj = _PySrv.plcobj |
68 obj = _PySrv.plcobj |
69 while names: |
69 while names: |
70 obj = getattr(obj, names.pop(0)) |
70 obj = getattr(obj, names.pop(0)) |
71 return obj |
71 return obj |
72 |
72 |
|
73 def getValidOptins(options, arguments): |
|
74 validOptions = {} |
|
75 for key in options: |
|
76 if key in arguments: |
|
77 validOptions[key] = options[key] |
|
78 if len(validOptions) > 0: |
|
79 return validOptions |
|
80 else: |
|
81 return None |
73 |
82 |
74 class WampSession(wamp.ApplicationSession): |
83 class WampSession(wamp.ApplicationSession): |
75 def onConnect(self): |
84 def onConnect(self): |
76 if "secret" in self.config.extra: |
85 if "secret" in self.config.extra: |
77 user = self.config.extra["ID"] |
86 user = self.config.extra["ID"] |
90 @inlineCallbacks |
99 @inlineCallbacks |
91 def onJoin(self, details): |
100 def onJoin(self, details): |
92 global _WampSession |
101 global _WampSession |
93 _WampSession = self |
102 _WampSession = self |
94 ID = self.config.extra["ID"] |
103 ID = self.config.extra["ID"] |
|
104 regoption = None |
|
105 |
|
106 registerOptions = self.config.extra.get('registerOptions', None) |
|
107 arguments = inspect.getargspec(types.RegisterOptions.__init__).args |
|
108 validRegisterOptions = getValidOptins(registerOptions, arguments) |
|
109 if validRegisterOptions: |
|
110 regoption = types.RegisterOptions(**validRegisterOptions) |
|
111 #print(_("Added custom register options")) |
|
112 |
95 for name in ExposedCalls: |
113 for name in ExposedCalls: |
96 regoption = types.RegisterOptions(u'exact', u'last') |
|
97 yield self.register(GetCallee(name), u'.'.join((ID, name)), regoption) |
114 yield self.register(GetCallee(name), u'.'.join((ID, name)), regoption) |
98 |
115 |
99 for name in SubscribedEvents: |
116 for name in SubscribedEvents: |
100 yield self.subscribe(GetCallee(name), unicode(name)) |
117 yield self.subscribe(GetCallee(name), unicode(name)) |
101 |
118 |
112 |
129 |
113 class ReconnectingWampWebSocketClientFactory(WampWebSocketClientFactory, ReconnectingClientFactory): |
130 class ReconnectingWampWebSocketClientFactory(WampWebSocketClientFactory, ReconnectingClientFactory): |
114 def __init__(self, config, *args, **kwargs): |
131 def __init__(self, config, *args, **kwargs): |
115 WampWebSocketClientFactory.__init__(self, *args, **kwargs) |
132 WampWebSocketClientFactory.__init__(self, *args, **kwargs) |
116 |
133 |
|
134 protocolOptions = config.extra.get('protocolOptions', None) |
117 arguments = inspect.getargspec(self.setProtocolOptions).args |
135 arguments = inspect.getargspec(self.setProtocolOptions).args |
118 protocolOptions = config.extra.get('protocolOptions', None) |
136 validProtocolOptions = getValidOptins(protocolOptions, arguments) |
119 |
137 if validProtocolOptions: |
120 validProtocolOptions = {} |
|
121 |
|
122 for key in protocolOptions: |
|
123 if key in arguments: |
|
124 validProtocolOptions[key] = protocolOptions[key] |
|
125 |
|
126 if len(validProtocolOptions) > 0: |
|
127 self.setProtocolOptions(**validProtocolOptions) |
138 self.setProtocolOptions(**validProtocolOptions) |
128 print(_("Added custom protocol options")) |
139 #print(_("Added custom protocol options")) |
129 |
|
130 del validProtocolOptions |
|
131 del protocolOptions |
|
132 |
140 |
133 def buildProtocol(self, addr): |
141 def buildProtocol(self, addr): |
134 self.resetDelay() |
142 self.resetDelay() |
135 return ReconnectingClientFactory.buildProtocol(self, addr) |
143 return ReconnectingClientFactory.buildProtocol(self, addr) |
136 |
144 |