annotate src/browser/sat_browser/json.py @ 845:a5b5178ef6b9

browser (json): display a warning when connection with server is lost, and count down until the next try
author Goffi <goffi@goffi.org>
date Fri, 15 Jan 2016 15:42:37 +0100
parents 83a40d786e7a
children c1907a460f6a
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
818
f8a7a046ff9c copyright update
Goffi <goffi@goffi.org>
parents: 751
diff changeset
5 # Copyright (C) 2011-2016 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
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
33
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
34
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
35 class LiberviaMethodProxy(object):
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
36 """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
37
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
38 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
39 self._parent = parent
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
40 self._method = method
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
41
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
42 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
43 """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
44
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
45 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
46 @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
47 @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
48 """
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
49 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
50 errback=kwargs.pop('errback', None)
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 229
diff changeset
51
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
52 # 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
53 profile_removed = False
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
54 try:
676
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 642
diff changeset
55 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
56 del kwargs['profile']
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
57 profile_removed = True
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
58 except KeyError:
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
59 pass
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
60
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
61 try:
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
62 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
63 del kwargs['profile_key']
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
64 profile_removed = True
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
65 except KeyError:
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
66 pass
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 229
diff changeset
67
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
68 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
69 # 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
70 args = list(args)
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
71 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
72 del args[-1]
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
73
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
74 if kwargs:
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
75 # 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
76 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
77
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
78 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
79
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
80 # 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
81 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
82 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
83 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
84 self._parent.eb[id_] = errback
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 229
diff changeset
85
58
4fa3d57f72f8 browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents: 57
diff changeset
86
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
87 class LiberviaJsonProxy(JSONService.JSONService):
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
88
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
89 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
90 self._serviceURL = url
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
91 self.methods = methods
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
92 JSONService.JSONService.__init__(self, url, self)
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 223
diff changeset
93 self.cb = {}
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 223
diff changeset
94 self.eb = {}
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
95 self._registerMethods(methods)
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
96
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
97 def _registerMethods(self, methods):
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
98 if methods:
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
99 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
100 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
101 setattr(self,
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
102 method,
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
103 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
104 )
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 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
107 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
108 return ret
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
109
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
110 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
111 # 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
112 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
113 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
114 if cb:
203
5fdea93b2541 browser side: errback management in bridge calls
Goffi <goffi@goffi.org>
parents: 202
diff changeset
115 if isinstance(cb, tuple):
5fdea93b2541 browser side: errback management in bridge calls
Goffi <goffi@goffi.org>
parents: 202
diff changeset
116 if len(cb) != 2:
439
d52f529a6d42 browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents: 433
diff changeset
117 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
118 return
296
92d76ab67156 server+browser side: fixed bridge errback handling
Goffi <goffi@goffi.org>
parents: 285
diff changeset
119 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
120 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
121 self.eb[id_] = cb[1]
203
5fdea93b2541 browser side: errback management in bridge calls
Goffi <goffi@goffi.org>
parents: 202
diff changeset
122 else:
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
123 self.cb[id_] = cb
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
124
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
125 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
126 try:
132
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
127 _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
128 except KeyError:
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
129 pass
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
130 else:
203
5fdea93b2541 browser side: errback management in bridge calls
Goffi <goffi@goffi.org>
parents: 202
diff changeset
131 _cb(response)
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 28
diff changeset
132 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
133
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
134 try:
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
135 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
136 except KeyError:
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
137 pass
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 223
diff changeset
138
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
139 def onRemoteError(self, code, errobj, request_info):
62
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 58
diff changeset
140 """def dump(obj):
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 58
diff changeset
141 print "\n\nDUMPING %s\n\n" % obj
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 58
diff changeset
142 for i in dir(obj):
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 58
diff changeset
143 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
144 try:
203
5fdea93b2541 browser side: errback management in bridge calls
Goffi <goffi@goffi.org>
parents: 202
diff changeset
145 _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
146 except KeyError:
203
5fdea93b2541 browser side: errback management in bridge calls
Goffi <goffi@goffi.org>
parents: 202
diff changeset
147 if code != 0:
439
d52f529a6d42 browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents: 433
diff changeset
148 log.error("Internal server error")
203
5fdea93b2541 browser side: errback management in bridge calls
Goffi <goffi@goffi.org>
parents: 202
diff changeset
149 """for o in code, error, request_info:
5fdea93b2541 browser side: errback management in bridge calls
Goffi <goffi@goffi.org>
parents: 202
diff changeset
150 dump(o)"""
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
151 else:
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 223
diff changeset
152 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
153 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
154 else:
694
82123705474b massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 692
diff changeset
155 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
156 else:
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
157 _eb((code, errobj))
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
158 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
159
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
160 try:
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
161 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
162 except KeyError:
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
163 pass
239
b911f2b43fd4 browser_side: added input history in the unibox:
souliane <souliane@mailoo.org>
parents: 235
diff changeset
164
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
165
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
166 class RegisterCall(LiberviaJsonProxy):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
167 def __init__(self):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
168 LiberviaJsonProxy.__init__(self, "/register_api",
456
da2a7f2b34c9 browser and server sides: use asyncConnect instead of connect
souliane <souliane@mailoo.org>
parents: 455
diff changeset
169 ["isRegistered", "isConnected", "asyncConnect", "registerParams", "getMenus"])
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
170
239
b911f2b43fd4 browser_side: added input history in the unibox:
souliane <souliane@mailoo.org>
parents: 235
diff changeset
171
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
172 class BridgeCall(LiberviaJsonProxy):
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
173 def __init__(self):
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
174 LiberviaJsonProxy.__init__(self, "/json_api",
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 700
diff changeset
175 ["getContacts", "addContact", "sendMessage",
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 700
diff changeset
176 "psDeleteNode", "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
177 "mbSend", "mbRetract", "mbGet", "mbGetFromMany", "mbGetFromManyRTResult",
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 700
diff changeset
178 "mbGetFromManyWithComments", "mbGetFromManyWithCommentsRTResult",
427
b5b440e6ea16 server + browser side, getPresenceStatuses has been renamed
Goffi <goffi@goffi.org>
parents: 426
diff changeset
179 "getHistory", "getPresenceStatuses", "joinMUC", "mucLeave", "getRoomsJoined",
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
180 "getRoomsSubjects", "inviteMUC", "launchTarotGame", "getTarotCardsPaths", "tarotGameReady",
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 700
diff changeset
181 "tarotGamePlayCards", "launchRadioCollective",
215
e830a0c60d32 server side: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents: 213
diff changeset
182 "getWaitingSub", "subscription", "delContact", "updateContact", "getCard",
229
e632f77c4219 bridge: asyncGetParamA takes a security_limit argument
souliane <souliane@mailoo.org>
parents: 227
diff changeset
183 "getEntityData", "getParamsUI", "asyncGetParamA", "setParam", "launchAction",
282
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 280
diff changeset
184 "disconnect", "chatStateComposing", "getNewAccountDomain", "confirmationAnswer",
679
a90cc8fc9605 merged branch frontends_multi_profiles
Goffi <goffi@goffi.org>
parents: 586 676
diff changeset
185 "syntaxConvert", "getAccountDialogUI", "getMainResource", "getWaitingConf", "getEntitiesData",
751
2ddd85551612 server + browser side: getFeatures bridge call
Goffi <goffi@goffi.org>
parents: 724
diff changeset
186 "getVersion", "getLiberviaVersion", "getDefaultMUC", "getFeatures",
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
187 ])
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
188
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
189 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
190 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
191
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
192 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
193 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
194 return ''
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
195
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
196 def isConnected(self, dummy): # FIXME
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
197 log.warning("isConnected is not implemeted in Libervia as for now profile is connected if session is opened")
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
198 return True
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
199
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
200 def getAvatarFile(self, hash_, callback=None):
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
201 log.warning("getAvatarFile only return hash in Libervia")
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
202 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
203 callback(hash_)
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
204 return hash_
0
140cec48224a Initial commit
Goffi <goffi@goffi.org>
parents:
diff changeset
205
242
a25aa882e09a browser_side: add context menu for contact:
souliane <souliane@mailoo.org>
parents: 239
diff changeset
206
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
207 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
208
99
ca4fc2b2471b browser side: signal management
Goffi <goffi@goffi.org>
parents: 85
diff changeset
209 def __init__(self, host):
ca4fc2b2471b browser side: signal management
Goffi <goffi@goffi.org>
parents: 85
diff changeset
210 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
211 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
212 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
213 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
214 self.retry_timer = None
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
215 LiberviaJsonProxy.__init__(self, "/json_signal_api",
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
216 ["getSignals"])
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
217 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
218
157
b17ec3a6a112 browser side: in case of error, retry delay is doubled at each try
Goffi <goffi@goffi.org>
parents: 148
diff changeset
219 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
220 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
221 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
222 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
223 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
224 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
225
99
ca4fc2b2471b browser side: signal management
Goffi <goffi@goffi.org>
parents: 85
diff changeset
226 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
227 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
228 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
229 # 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
230 # 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
231 # 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
232 LiberviaJsonProxy.onRemoteError(self, code, errobj, request_info)
99
ca4fc2b2471b browser side: signal management
Goffi <goffi@goffi.org>
parents: 85
diff changeset
233 #we now try to reconnect
274
886b47896f3c browser_side: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 269
diff changeset
234 if isinstance(errobj['message'], dict) and errobj['message']['faultCode'] == 0:
886b47896f3c browser_side: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 269
diff changeset
235 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
236 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
237 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
238 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
239 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
240 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
241 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
242 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
243 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
244 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
245 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
246 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
247 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
248 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
249 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
250
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
251 retry_delay = 2**self.retry_nb
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
252 self.retry_nb += 1
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
253 log.warning(u"Lost connection, trying to reconnect in {} s".format(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
254 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
255 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
256 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
257 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
258 _timerCb(None)
2
669c531a857e signals handling and first draft of microblogging
Goffi <goffi@goffi.org>
parents: 1
diff changeset
259
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
260 def register(self, name, callback, with_profile=True):
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
261 """Register a signal
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 223
diff changeset
262
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
263 @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
264 @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
265 @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
266 """
694
82123705474b massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 692
diff changeset
267 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
268 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
269 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
270 else:
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
271 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
272
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
273 def signalHandler(self, signal_data):
843
83a40d786e7a browser: use new style calls for getSignals
Goffi <goffi@goffi.org>
parents: 818
diff changeset
274 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
275 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
276 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
277 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
278 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
279 try:
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
280 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
281 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
282 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
283 return
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
284 if with_profile:
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 584
diff changeset
285 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
286 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
287 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
288 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
289 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
290 callback(*args)