160 def __init__(self, config, *args, **kwargs): |
160 def __init__(self, config, *args, **kwargs): |
161 global _transportFactory |
161 global _transportFactory |
162 WampWebSocketClientFactory.__init__(self, *args, **kwargs) |
162 WampWebSocketClientFactory.__init__(self, *args, **kwargs) |
163 |
163 |
164 try: |
164 try: |
|
165 clientFactoryOptions = config.extra.get("clientFactoryOptions") |
|
166 if clientFactoryOptions: |
|
167 self.setClientFactoryOptions(clientFactoryOptions) |
|
168 except Exception as e: |
|
169 print(_("Custom client factory options failed : "), e) |
|
170 _transportFactory = None |
|
171 |
|
172 try: |
165 protocolOptions = config.extra.get('protocolOptions', None) |
173 protocolOptions = config.extra.get('protocolOptions', None) |
166 if protocolOptions: |
174 if protocolOptions: |
167 self.setProtocolOptions(**protocolOptions) |
175 self.setProtocolOptions(**protocolOptions) |
168 _transportFactory = self |
176 _transportFactory = self |
169 except Exception as e: |
177 except Exception as e: |
170 print(_("Custom protocol options failed :"), e) |
178 print(_("Custom protocol options failed :"), e) |
171 _transportFactory = None |
179 _transportFactory = None |
172 |
180 |
|
181 def setClientFactoryOptions(self, options): |
|
182 for key, value in options.items(): |
|
183 setattr(self, key, value) |
|
184 |
173 def buildProtocol(self, addr): |
185 def buildProtocol(self, addr): |
174 self.resetDelay() |
186 self.resetDelay() |
175 return ReconnectingClientFactory.buildProtocol(self, addr) |
187 return ReconnectingClientFactory.buildProtocol(self, addr) |
176 |
188 |
177 def clientConnectionFailed(self, connector, reason): |
189 def clientConnectionFailed(self, connector, reason): |
192 if not IsCorrectUri(url): |
204 if not IsCorrectUri(url): |
193 raise annotate.ValidateError( |
205 raise annotate.ValidateError( |
194 {"url": "Invalid URL: {}".format(url)}, |
206 {"url": "Invalid URL: {}".format(url)}, |
195 _("WAMP configuration error:")) |
207 _("WAMP configuration error:")) |
196 |
208 |
|
209 def UpdateWithDefault(d1, d2): |
|
210 for k, v in d2.items(): |
|
211 d1.setdefault(k, v) |
197 |
212 |
198 def GetConfiguration(): |
213 def GetConfiguration(): |
199 global lastKnownConfig |
214 global lastKnownConfig |
200 |
215 |
201 WampClientConf = None |
216 WampClientConf = None |
202 |
217 |
203 if os.path.exists(_WampConf): |
218 if os.path.exists(_WampConf): |
204 try: |
219 try: |
205 WampClientConf = json.load(open(_WampConf)) |
220 WampClientConf = json.load(open(_WampConf)) |
|
221 UpdateWithDefault(WampClientConf, defaultWampConfig) |
206 except ValueError: |
222 except ValueError: |
207 pass |
223 pass |
208 |
224 |
209 if WampClientConf is None: |
225 if WampClientConf is None: |
210 WampClientConf = defaultWampConfig.copy() |
226 WampClientConf = defaultWampConfig.copy() |
363 webExposedConfigItems = ['active', 'url', 'ID'] |
381 webExposedConfigItems = ['active', 'url', 'ID'] |
364 |
382 |
365 |
383 |
366 def wampConfigDefault(ctx, argument): |
384 def wampConfigDefault(ctx, argument): |
367 if lastKnownConfig is not None: |
385 if lastKnownConfig is not None: |
368 return lastKnownConfig.get(argument.name, None) |
386 # Check if name is composed with an intermediate dot symbol and go deep in lastKnownConfig if it is |
|
387 argument_name_path = argument.name.split(".") |
|
388 searchValue = lastKnownConfig |
|
389 while argument_name_path: |
|
390 if searchValue: |
|
391 searchValue = searchValue.get(argument_name_path.pop(0), None) |
|
392 else: |
|
393 break |
|
394 return searchValue |
369 |
395 |
370 |
396 |
371 def wampConfig(**kwargs): |
397 def wampConfig(**kwargs): |
372 secretfile_field = kwargs["secretfile"] |
398 secretfile_field = kwargs["secretfile"] |
373 if secretfile_field is not None: |
399 if secretfile_field is not None: |
376 secret = secretfile_field.file.read() |
402 secret = secretfile_field.file.read() |
377 SetWampSecret(secret) |
403 SetWampSecret(secret) |
378 |
404 |
379 newConfig = lastKnownConfig.copy() |
405 newConfig = lastKnownConfig.copy() |
380 for argname in webExposedConfigItems: |
406 for argname in webExposedConfigItems: |
|
407 # Check if name is composed with an intermediate dot symbol and go deep in lastKnownConfig if it is |
|
408 # and then set a new value. |
|
409 argname_path = argname.split(".") |
|
410 arg_last = argname_path.pop() |
381 arg = kwargs.get(argname, None) |
411 arg = kwargs.get(argname, None) |
382 if arg is not None: |
412 if arg is not None: |
383 newConfig[argname] = arg |
413 tmpConf = newConfig |
|
414 while argname_path: |
|
415 tmpConf = tmpConf.setdefault(argname_path.pop(0), {}) |
|
416 tmpConf[arg_last] = arg |
384 |
417 |
385 SetConfiguration(newConfig) |
418 SetConfiguration(newConfig) |
386 |
419 |
387 |
420 |
388 class FileUploadDownload(annotate.FileUpload): |
421 class FileUploadDownload(annotate.FileUpload): |