annotate src/browser/sat_browser/json.py @ 1115:1f67b003c312 0.7.0a1

0.7.0a1 release
author Goffi <goffi@goffi.org>
date Tue, 03 Jul 2018 07:59:14 +0200
parents 09feea19d7b9
children 63a4b8fe9782
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
3
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 336
diff changeset
4 # Libervia: a Salut à Toi frontend
1054
f2170536ba23 date update
Goffi <goffi@goffi.org>
parents: 964
diff changeset
5 # Copyright (C) 2011-2018 Jérôme Poisson <goffi@goffi.org>
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
6
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 336
diff changeset
7 # This program is free software: you can redistribute it and/or modify
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 336
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 336
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 336
diff changeset
10 # (at your option) any later version.
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
11
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 336
diff changeset
12 # This program is distributed in the hope that it will be useful,
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 336
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 336
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 336
diff changeset
15 # GNU Affero General Public License for more details.
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
16
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 336
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 336
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
19
439
d52f529a6d42 browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents: 433
diff changeset
20
d52f529a6d42 browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents: 433
diff changeset
21 ### logging configuration ###
440
88461e9c3e47 browser_side (log): move logging configuration in a "logging" module + use custom backend with console.debug/info/etc output.
Goffi <goffi@goffi.org>
parents: 439
diff changeset
22 from sat.core.log import getLogger
439
d52f529a6d42 browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents: 433
diff changeset
23 log = getLogger(__name__)
d52f529a6d42 browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents: 433
diff changeset
24 ###
d52f529a6d42 browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents: 433
diff changeset
25
108
fad0e51cf565 on failure, Libervia now wait 5 s before trying again to call the serveur + only room name is now shown in tabs
Goffi <goffi@goffi.org>
parents: 107
diff changeset
26 from pyjamas.Timer import Timer
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
27 from pyjamas import Window
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
28 from pyjamas import JSONService
845
a5b5178ef6b9 browser (json): display a warning when connection with server is lost, and count down until the next try
Goffi <goffi@goffi.org>
parents: 843
diff changeset
29 import time
a5b5178ef6b9 browser (json): display a warning when connection with server is lost, and count down until the next try
Goffi <goffi@goffi.org>
parents: 843
diff changeset
30 from sat_browser import main_panel
323
0b7934e75e76 misc: reorganization of the file panels.py + clean the modules import:
souliane <souliane@mailoo.org>
parents: 321
diff changeset
31
467
97c72fe4a5f2 browser_side: import fixes:
Goffi <goffi@goffi.org>
parents: 462
diff changeset
32 from sat_browser.constants import Const as C
846
c1907a460f6a browser (json): changed rules for retry delay when connection with server is lost
Goffi <goffi@goffi.org>
parents: 845
diff changeset
33 import random
317
bbadd490e63c misc: gather the constants in a single file, as it is done for other frontends
souliane <souliane@mailoo.org>
parents: 316
diff changeset
34
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
35
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
36 class LiberviaMethodProxy(object):
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
37 """This class manage calling for one method"""
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
38
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
39 def __init__(self, parent, method):
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
40 self._parent = parent
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
41 self._method = method
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
42
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
43 def call(self, *args, **kwargs):
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
44 """Method called when self._method attribue is used in JSON_PROXY_PARENT
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
45
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
46 This method manage callback/errback in kwargs, and profile(_key) removing
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
47 @param *args: positional arguments of self._method
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
48 @param **kwargs: keyword arguments of self._method
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
49 """
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
50 callback=kwargs.pop('callback', None)
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
51 errback=kwargs.pop('errback', None)
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 229
diff changeset
52
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
53 # as profile is linked to browser session and managed server side, we remove them
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
54 profile_removed = False
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
55 try:
676
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 642
diff changeset
56 kwargs['profile'] # FIXME: workaround for pyjamas bug: KeyError is not raised with del
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
57 del kwargs['profile']
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
58 profile_removed = True
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
59 except KeyError:
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
60 pass
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
61
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
62 try:
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
63 kwargs['profile_key'] # FIXME: workaround for pyjamas bug: KeyError is not raised iwith del
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
64 del kwargs['profile_key']
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
65 profile_removed = True
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
66 except KeyError:
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
67 pass
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 229
diff changeset
68
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
69 if not profile_removed and args:
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
70 # if profile was not in kwargs, there is most probably one in args
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
71 args = list(args)
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
72 assert isinstance(args[-1], basestring) # Detect when we want to remove a callback (or something else) instead of the profile
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
73 del args[-1]
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
74
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
75 if kwargs:
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
76 # kwargs should be empty here, we don't manage keyword arguments on bridge calls
694
82123705474b massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 692
diff changeset
77 log.error(u"kwargs is not empty after treatment on method call: kwargs={}".format(kwargs))
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
78
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
79 id_ = self._parent.callMethod(self._method, args)
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
80
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
81 # callback or errback are managed in parent LiberviaJsonProxy with call id
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
82 if callback is not None:
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
83 self._parent.cb[id_] = callback
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
84 if errback is not None:
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
85 self._parent.eb[id_] = errback
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 229
diff changeset
86
58
4fa3d57f72f8 browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents: 57
diff changeset
87
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
88 class LiberviaJsonProxy(JSONService.JSONService):
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
89
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
90 def __init__(self, url, methods):
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
91 self._serviceURL = url
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
92 self.methods = methods
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
93 JSONService.JSONService.__init__(self, url, self)
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 223
diff changeset
94 self.cb = {}
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 223
diff changeset
95 self.eb = {}
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
96 self._registerMethods(methods)
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
97
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
98 def _registerMethods(self, methods):
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
99 if methods:
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
100 for method in methods:
694
82123705474b massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 692
diff changeset
101 log.debug(u"Registering JSON method call [{}]".format(method))
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
102 setattr(self,
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
103 method,
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
104 getattr(LiberviaMethodProxy(self, method), 'call')
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
105 )
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
106
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
107 def callMethod(self, method, params, handler = None):
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
108 ret = super(LiberviaJsonProxy, self).callMethod(method, params, handler)
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
109 return ret
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
110
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
111 def call(self, method, cb, *args):
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
112 # FIXME: deprecated call method, must be removed once it's not used anymore
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
113 id_ = self.callMethod(method, args)
694
82123705474b massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 692
diff changeset
114 log.debug(u"call: method={} [id={}], args={}".format(method, id_, args))
11
331c093e4eb3 magicBox is now able to send global microblog
Goffi <goffi@goffi.org>
parents: 9
diff changeset
115 if cb:
203
5fdea93b2541 browser side: errback management in bridge calls
Goffi <goffi@goffi.org>
parents: 202
diff changeset
116 if isinstance(cb, tuple):
5fdea93b2541 browser side: errback management in bridge calls
Goffi <goffi@goffi.org>
parents: 202
diff changeset
117 if len(cb) != 2:
439
d52f529a6d42 browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents: 433
diff changeset
118 log.error("tuple syntax for bridge.call is (callback, errback), aborting")
203
5fdea93b2541 browser side: errback management in bridge calls
Goffi <goffi@goffi.org>
parents: 202
diff changeset
119 return
296
92d76ab67156 server+browser side: fixed bridge errback handling
Goffi <goffi@goffi.org>
parents: 285
diff changeset
120 if cb[0] is not None:
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
121 self.cb[id_] = cb[0]
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
122 self.eb[id_] = cb[1]
203
5fdea93b2541 browser side: errback management in bridge calls
Goffi <goffi@goffi.org>
parents: 202
diff changeset
123 else:
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
124 self.cb[id_] = cb
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
125
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
126 def onRemoteResponse(self, response, request_info):
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
127 try:
132
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
128 _cb = self.cb[request_info.id]
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
129 except KeyError:
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
130 pass
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
131 else:
203
5fdea93b2541 browser side: errback management in bridge calls
Goffi <goffi@goffi.org>
parents: 202
diff changeset
132 _cb(response)
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 28
diff changeset
133 del self.cb[request_info.id]
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
134
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
135 try:
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
136 del self.eb[request_info.id]
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
137 except KeyError:
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
138 pass
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 223
diff changeset
139
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
140 def onRemoteError(self, code, errobj, request_info):
62
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 58
diff changeset
141 """def dump(obj):
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 58
diff changeset
142 print "\n\nDUMPING %s\n\n" % obj
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 58
diff changeset
143 for i in dir(obj):
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 58
diff changeset
144 print "%s: %s" % (i, getattr(obj,i))"""
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
145 try:
203
5fdea93b2541 browser side: errback management in bridge calls
Goffi <goffi@goffi.org>
parents: 202
diff changeset
146 _eb = self.eb[request_info.id]
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
147 except KeyError:
203
5fdea93b2541 browser side: errback management in bridge calls
Goffi <goffi@goffi.org>
parents: 202
diff changeset
148 if code != 0:
439
d52f529a6d42 browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents: 433
diff changeset
149 log.error("Internal server error")
203
5fdea93b2541 browser side: errback management in bridge calls
Goffi <goffi@goffi.org>
parents: 202
diff changeset
150 """for o in code, error, request_info:
5fdea93b2541 browser side: errback management in bridge calls
Goffi <goffi@goffi.org>
parents: 202
diff changeset
151 dump(o)"""
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
152 else:
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 223
diff changeset
153 if isinstance(errobj['message'], dict):
694
82123705474b massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 692
diff changeset
154 log.error(u"Error %s: %s" % (errobj['message']['faultCode'], errobj['message']['faultString']))
203
5fdea93b2541 browser side: errback management in bridge calls
Goffi <goffi@goffi.org>
parents: 202
diff changeset
155 else:
694
82123705474b massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 692
diff changeset
156 log.error(u"%s" % errobj['message'])
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
157 else:
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
158 _eb((code, errobj))
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
159 del self.eb[request_info.id]
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
160
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
161 try:
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
162 del self.cb[request_info.id]
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
163 except KeyError:
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
164 pass
239
b911f2b43fd4 browser_side: added input history in the unibox:
souliane <souliane@mailoo.org>
parents: 235
diff changeset
165
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
166
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
167 class RegisterCall(LiberviaJsonProxy):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
168 def __init__(self):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
169 LiberviaJsonProxy.__init__(self, "/register_api",
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
170 ["getSessionMetadata", "isConnected", "connect", "registerParams", "menusGet"])
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
171
239
b911f2b43fd4 browser_side: added input history in the unibox:
souliane <souliane@mailoo.org>
parents: 235
diff changeset
172
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
173 class BridgeCall(LiberviaJsonProxy):
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
174 def __init__(self):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
175 LiberviaJsonProxy.__init__(self, "/json_api",
909
e8b133b77aa4 browser, server: update to get compatibility with 0.7-dev (not finished):
Goffi <goffi@goffi.org>
parents: 869
diff changeset
176 ["getContacts", "addContact", "messageSend",
921
cf527974a0fa both: renamed psDeleteNode to psNodeDelete to follow backend change
Goffi <goffi@goffi.org>
parents: 914
diff changeset
177 "psNodeDelete", "psRetractItem", "psRetractItems",
724
994be887e843 browser and server sides: bridge method mbGetLast has been renamed to mbGet and takes a new parameter "item_ids"
souliane <souliane@mailoo.org>
parents: 716
diff changeset
178 "mbSend", "mbRetract", "mbGet", "mbGetFromMany", "mbGetFromManyRTResult",
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 700
diff changeset
179 "mbGetFromManyWithComments", "mbGetFromManyWithCommentsRTResult",
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
180 "historyGet", "getPresenceStatuses", "joinMUC", "mucLeave", "mucGetRoomsJoined",
909
e8b133b77aa4 browser, server: update to get compatibility with 0.7-dev (not finished):
Goffi <goffi@goffi.org>
parents: 869
diff changeset
181 "inviteMUC", "launchTarotGame", "getTarotCardsPaths", "tarotGameReady",
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 700
diff changeset
182 "tarotGamePlayCards", "launchRadioCollective",
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
183 "getWaitingSub", "subscription", "delContact", "updateContact", "avatarGet",
229
e632f77c4219 bridge: asyncGetParamA takes a security_limit argument
souliane <souliane@mailoo.org>
parents: 227
diff changeset
184 "getEntityData", "getParamsUI", "asyncGetParamA", "setParam", "launchAction",
913
58f611481e6d server, browser: removed deprecated methods which have been removed from backend, and associated code
Goffi <goffi@goffi.org>
parents: 909
diff changeset
185 "disconnect", "chatStateComposing", "getNewAccountDomain",
58f611481e6d server, browser: removed deprecated methods which have been removed from backend, and associated code
Goffi <goffi@goffi.org>
parents: 909
diff changeset
186 "syntaxConvert", "getAccountDialogUI", "getMainResource", "getEntitiesData",
909
e8b133b77aa4 browser, server: update to get compatibility with 0.7-dev (not finished):
Goffi <goffi@goffi.org>
parents: 869
diff changeset
187 "getVersion", "getLiberviaVersion", "mucGetDefaultService", "getFeatures",
1106
09feea19d7b9 browser, server: added namespacesGet, so Libervia legacy app can run again
Goffi <goffi@goffi.org>
parents: 1054
diff changeset
188 "namespacesGet",
148
8635bc9db9bf added parameter management to test XMLUI, but it's currently deactivated for security reasons (need some configuration options) + separated mainTabPanel CSS from LiberviaTabPanel
Goffi <goffi@goffi.org>
parents: 146
diff changeset
189 ])
697
b395d1309936 browser_side: clean the code that has been commented or isolated during the refactorisation to base libervia on quick_frontend
souliane <souliane@mailoo.org>
parents: 694
diff changeset
190
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
191 def __call__(self, *args, **kwargs):
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
192 return LiberviaJsonProxy.__call__(self, *args, **kwargs)
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
193
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
194 def getConfig(self, dummy1, dummy2): # FIXME
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
195 log.warning("getConfig is not implemeted in Libervia yet")
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
196 return ''
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
197
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
198 def isConnected(self, dummy, callback): # FIXME
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
199 log.warning("isConnected is not implemeted in Libervia as for now profile is connected if session is opened")
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
200 callback(True)
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
201
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
202 def bridgeConnect(self, callback, errback):
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
203 callback()
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
204
242
a25aa882e09a browser_side: add context menu for contact:
souliane <souliane@mailoo.org>
parents: 239
diff changeset
205
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
206 class BridgeSignals(LiberviaJsonProxy):
157
b17ec3a6a112 browser side: in case of error, retry delay is doubled at each try
Goffi <goffi@goffi.org>
parents: 148
diff changeset
207
99
ca4fc2b2471b browser side: signal management
Goffi <goffi@goffi.org>
parents: 85
diff changeset
208 def __init__(self, host):
ca4fc2b2471b browser side: signal management
Goffi <goffi@goffi.org>
parents: 85
diff changeset
209 self.host = host
845
a5b5178ef6b9 browser (json): display a warning when connection with server is lost, and count down until the next try
Goffi <goffi@goffi.org>
parents: 843
diff changeset
210 self.retry_time = None
a5b5178ef6b9 browser (json): display a warning when connection with server is lost, and count down until the next try
Goffi <goffi@goffi.org>
parents: 843
diff changeset
211 self.retry_nb = 0
a5b5178ef6b9 browser (json): display a warning when connection with server is lost, and count down until the next try
Goffi <goffi@goffi.org>
parents: 843
diff changeset
212 self.retry_warning = None
a5b5178ef6b9 browser (json): display a warning when connection with server is lost, and count down until the next try
Goffi <goffi@goffi.org>
parents: 843
diff changeset
213 self.retry_timer = None
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
214 LiberviaJsonProxy.__init__(self, "/json_signal_api",
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
215 ["getSignals"])
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
216 self._signals = {} # key: signal name, value: callback
210
3092f6b1710c browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents: 205
diff changeset
217
157
b17ec3a6a112 browser side: in case of error, retry delay is doubled at each try
Goffi <goffi@goffi.org>
parents: 148
diff changeset
218 def onRemoteResponse(self, response, request_info):
845
a5b5178ef6b9 browser (json): display a warning when connection with server is lost, and count down until the next try
Goffi <goffi@goffi.org>
parents: 843
diff changeset
219 if self.retry_time:
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
220 log.info("Connection with server restablished")
845
a5b5178ef6b9 browser (json): display a warning when connection with server is lost, and count down until the next try
Goffi <goffi@goffi.org>
parents: 843
diff changeset
221 self.retry_nb = 0
a5b5178ef6b9 browser (json): display a warning when connection with server is lost, and count down until the next try
Goffi <goffi@goffi.org>
parents: 843
diff changeset
222 self.retry_time = None
157
b17ec3a6a112 browser side: in case of error, retry delay is doubled at each try
Goffi <goffi@goffi.org>
parents: 148
diff changeset
223 LiberviaJsonProxy.onRemoteResponse(self, response, request_info)
210
3092f6b1710c browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents: 205
diff changeset
224
99
ca4fc2b2471b browser side: signal management
Goffi <goffi@goffi.org>
parents: 85
diff changeset
225 def onRemoteError(self, code, errobj, request_info):
158
58442ed28f2b browser side: basic disconnection management: hard reload is done on empty signal response
Goffi <goffi@goffi.org>
parents: 157
diff changeset
226 if errobj['message'] == 'Empty Response':
642
5af02673d047 browser side (json): replaced the Window.alert by a log warning when signal is lost
Goffi <goffi@goffi.org>
parents: 605
diff changeset
227 log.warning(u"Empty reponse bridgeSignal\ncode={}\nrequest_info: id={} method={} handler={}".format(code, request_info.id, request_info.method, request_info.handler))
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
228 # FIXME: to check/replace by a proper session end on disconnected signal
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
229 # Window.getLocation().reload() # XXX: reset page in case of session ended.
274
886b47896f3c browser_side: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 269
diff changeset
230 # FIXME: Should be done more properly without hard reload
158
58442ed28f2b browser side: basic disconnection management: hard reload is done on empty signal response
Goffi <goffi@goffi.org>
parents: 157
diff changeset
231 LiberviaJsonProxy.onRemoteError(self, code, errobj, request_info)
99
ca4fc2b2471b browser side: signal management
Goffi <goffi@goffi.org>
parents: 85
diff changeset
232 #we now try to reconnect
274
886b47896f3c browser_side: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 269
diff changeset
233 if isinstance(errobj['message'], dict) and errobj['message']['faultCode'] == 0:
886b47896f3c browser_side: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 269
diff changeset
234 Window.alert('You are not allowed to connect to server')
108
fad0e51cf565 on failure, Libervia now wait 5 s before trying again to call the serveur + only room name is now shown in tabs
Goffi <goffi@goffi.org>
parents: 107
diff changeset
235 else:
845
a5b5178ef6b9 browser (json): display a warning when connection with server is lost, and count down until the next try
Goffi <goffi@goffi.org>
parents: 843
diff changeset
236 def _timerCb(dummy):
a5b5178ef6b9 browser (json): display a warning when connection with server is lost, and count down until the next try
Goffi <goffi@goffi.org>
parents: 843
diff changeset
237 current = time.time()
a5b5178ef6b9 browser (json): display a warning when connection with server is lost, and count down until the next try
Goffi <goffi@goffi.org>
parents: 843
diff changeset
238 if current > self.retry_time:
a5b5178ef6b9 browser (json): display a warning when connection with server is lost, and count down until the next try
Goffi <goffi@goffi.org>
parents: 843
diff changeset
239 msg = "Trying to reconnect to server..."
a5b5178ef6b9 browser (json): display a warning when connection with server is lost, and count down until the next try
Goffi <goffi@goffi.org>
parents: 843
diff changeset
240 log.info(msg)
a5b5178ef6b9 browser (json): display a warning when connection with server is lost, and count down until the next try
Goffi <goffi@goffi.org>
parents: 843
diff changeset
241 self.retry_warning.showWarning("INFO", msg)
a5b5178ef6b9 browser (json): display a warning when connection with server is lost, and count down until the next try
Goffi <goffi@goffi.org>
parents: 843
diff changeset
242 self.retry_timer.cancel()
a5b5178ef6b9 browser (json): display a warning when connection with server is lost, and count down until the next try
Goffi <goffi@goffi.org>
parents: 843
diff changeset
243 self.retry_warning = self.retry_timer = None
a5b5178ef6b9 browser (json): display a warning when connection with server is lost, and count down until the next try
Goffi <goffi@goffi.org>
parents: 843
diff changeset
244 self.getSignals(callback=self.signalHandler, profile=None)
a5b5178ef6b9 browser (json): display a warning when connection with server is lost, and count down until the next try
Goffi <goffi@goffi.org>
parents: 843
diff changeset
245 else:
a5b5178ef6b9 browser (json): display a warning when connection with server is lost, and count down until the next try
Goffi <goffi@goffi.org>
parents: 843
diff changeset
246 remaining = int(self.retry_time - current)
a5b5178ef6b9 browser (json): display a warning when connection with server is lost, and count down until the next try
Goffi <goffi@goffi.org>
parents: 843
diff changeset
247 msg_html = u"Connection with server lost. Retrying in <strong>{}</strong> s".format(remaining)
a5b5178ef6b9 browser (json): display a warning when connection with server is lost, and count down until the next try
Goffi <goffi@goffi.org>
parents: 843
diff changeset
248 self.retry_warning.showWarning("WARNING", msg_html, None)
a5b5178ef6b9 browser (json): display a warning when connection with server is lost, and count down until the next try
Goffi <goffi@goffi.org>
parents: 843
diff changeset
249
846
c1907a460f6a browser (json): changed rules for retry delay when connection with server is lost
Goffi <goffi@goffi.org>
parents: 845
diff changeset
250 if self.retry_nb < 3:
c1907a460f6a browser (json): changed rules for retry delay when connection with server is lost
Goffi <goffi@goffi.org>
parents: 845
diff changeset
251 retry_delay = 1
c1907a460f6a browser (json): changed rules for retry delay when connection with server is lost
Goffi <goffi@goffi.org>
parents: 845
diff changeset
252 elif self.retry_nb < 10:
c1907a460f6a browser (json): changed rules for retry delay when connection with server is lost
Goffi <goffi@goffi.org>
parents: 845
diff changeset
253 retry_delay = random.randint(1,10)
c1907a460f6a browser (json): changed rules for retry delay when connection with server is lost
Goffi <goffi@goffi.org>
parents: 845
diff changeset
254 else:
c1907a460f6a browser (json): changed rules for retry delay when connection with server is lost
Goffi <goffi@goffi.org>
parents: 845
diff changeset
255 retry_delay = random.randint(1,60)
845
a5b5178ef6b9 browser (json): display a warning when connection with server is lost, and count down until the next try
Goffi <goffi@goffi.org>
parents: 843
diff changeset
256 self.retry_nb += 1
846
c1907a460f6a browser (json): changed rules for retry delay when connection with server is lost
Goffi <goffi@goffi.org>
parents: 845
diff changeset
257 log.warning(u"Lost connection, trying to reconnect in {} s (try #{})".format(retry_delay, self.retry_nb))
845
a5b5178ef6b9 browser (json): display a warning when connection with server is lost, and count down until the next try
Goffi <goffi@goffi.org>
parents: 843
diff changeset
258 self.retry_time = time.time() + retry_delay
a5b5178ef6b9 browser (json): display a warning when connection with server is lost, and count down until the next try
Goffi <goffi@goffi.org>
parents: 843
diff changeset
259 self.retry_warning = main_panel.WarningPopup()
a5b5178ef6b9 browser (json): display a warning when connection with server is lost, and count down until the next try
Goffi <goffi@goffi.org>
parents: 843
diff changeset
260 self.retry_timer = Timer(notify=_timerCb)
a5b5178ef6b9 browser (json): display a warning when connection with server is lost, and count down until the next try
Goffi <goffi@goffi.org>
parents: 843
diff changeset
261 self.retry_timer.scheduleRepeating(1000)
a5b5178ef6b9 browser (json): display a warning when connection with server is lost, and count down until the next try
Goffi <goffi@goffi.org>
parents: 843
diff changeset
262 _timerCb(None)
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
263
914
0c0551967bdf server, browser: partial Libervia fix
Goffi <goffi@goffi.org>
parents: 913
diff changeset
264 def register_signal(self, name, callback, with_profile=True):
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
265 """Register a signal
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 223
diff changeset
266
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
267 @param: name of the signal to register
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
268 @param callback: method to call
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
269 @param with_profile: True if the original bridge method need a profile
267
a76243c02074 browser_side: changes regarding widgets and tabs:
souliane <souliane@mailoo.org>
parents: 266
diff changeset
270 """
694
82123705474b massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 692
diff changeset
271 log.debug(u"Registering signal {}".format(name))
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
272 if name in self._signals:
694
82123705474b massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 692
diff changeset
273 log.error(u"Trying to register and already registered signal ({})".format(name))
267
a76243c02074 browser_side: changes regarding widgets and tabs:
souliane <souliane@mailoo.org>
parents: 266
diff changeset
274 else:
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
275 self._signals[name] = (callback, with_profile)
426
77d8f55fc5f0 browser_side: hide the presence/status panel until the connection is made
souliane <souliane@mailoo.org>
parents: 422
diff changeset
276
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
277 def signalHandler(self, signal_data):
843
83a40d786e7a browser: use new style calls for getSignals
Goffi <goffi@goffi.org>
parents: 818
diff changeset
278 self.getSignals(callback=self.signalHandler, profile=None)
548
530f3fc3e3d7 browser_side: fixes signal callback with no argument (e.g disconnected)
souliane <souliane@mailoo.org>
parents: 536
diff changeset
279 if len(signal_data) == 1:
530f3fc3e3d7 browser_side: fixes signal callback with no argument (e.g disconnected)
souliane <souliane@mailoo.org>
parents: 536
diff changeset
280 signal_data.append([])
694
82123705474b massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 692
diff changeset
281 log.debug(u"Got signal ==> name: %s, params: %s" % (signal_data[0], signal_data[1]))
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 223
diff changeset
282 name, args = signal_data
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
283 try:
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
284 callback, with_profile = self._signals[name]
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
285 except KeyError:
694
82123705474b massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 692
diff changeset
286 log.warning(u"Ignoring {} signal: no handler registered !".format(name))
205
ee744ffed7fc browser side: events data are cached until initialisation is finished (we get all microblogs)
Goffi <goffi@goffi.org>
parents: 204
diff changeset
287 return
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
288 if with_profile:
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
289 args.append(C.PROF_KEY_NONE)
700
b81816f42c81 browser side: added signal caching before profile is plugged, as QuickFrontend mechanism is not used
Goffi <goffi@goffi.org>
parents: 697
diff changeset
290 if not self.host._profile_plugged:
b81816f42c81 browser side: added signal caching before profile is plugged, as QuickFrontend mechanism is not used
Goffi <goffi@goffi.org>
parents: 697
diff changeset
291 log.debug("Profile is not plugged, we cache the signal")
b81816f42c81 browser side: added signal caching before profile is plugged, as QuickFrontend mechanism is not used
Goffi <goffi@goffi.org>
parents: 697
diff changeset
292 self.host.signals_cache[C.PROF_KEY_NONE].append((name, callback, args, {}))
b81816f42c81 browser side: added signal caching before profile is plugged, as QuickFrontend mechanism is not used
Goffi <goffi@goffi.org>
parents: 697
diff changeset
293 else:
b81816f42c81 browser side: added signal caching before profile is plugged, as QuickFrontend mechanism is not used
Goffi <goffi@goffi.org>
parents: 697
diff changeset
294 callback(*args)