Mercurial > libervia-backend
annotate src/memory/memory.py @ 1245:84d06701f5c4
plugin misc_imap: fixes call to log.debug with more than one argument
author | souliane <souliane@mailoo.org> |
---|---|
date | Sun, 19 Oct 2014 12:31:28 +0200 |
parents | 22adf1eb59f5 |
children | c6cf44e6330b |
rev | line source |
---|---|
0 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
592
diff
changeset
|
4 # SAT: a jabber client |
811 | 5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Jérôme Poisson (goffi@goffi.org) |
0 | 6 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
592
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
592
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
592
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
592
diff
changeset
|
10 # (at your option) any later version. |
0 | 11 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
592
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
592
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
592
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
592
diff
changeset
|
15 # GNU Affero General Public License for more details. |
0 | 16 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
592
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
592
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
0 | 19 |
771 | 20 from sat.core.i18n import _ |
0 | 21 |
22 import os.path | |
364 | 23 from ConfigParser import SafeConfigParser, NoOptionError, NoSectionError |
756
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
24 from uuid import uuid4 |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
946
diff
changeset
|
25 from sat.core.log import getLogger |
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
946
diff
changeset
|
26 log = getLogger(__name__) |
756
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
27 from twisted.internet import defer, reactor |
47 | 28 from twisted.words.protocols.jabber import jid |
914
1a3ba959f0ab
core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents:
909
diff
changeset
|
29 from sat.core import exceptions |
1a3ba959f0ab
core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents:
909
diff
changeset
|
30 from sat.core.constants import Const as C |
432
31e8c48b5f5d
core: - memory refactoring (moved memory.py and sqlite.py from tools to memory)
Goffi <goffi@goffi.org>
parents:
428
diff
changeset
|
31 from sat.memory.sqlite import SqliteStorage |
31e8c48b5f5d
core: - memory refactoring (moved memory.py and sqlite.py from tools to memory)
Goffi <goffi@goffi.org>
parents:
428
diff
changeset
|
32 from sat.memory.persistent import PersistentDict |
914
1a3ba959f0ab
core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents:
909
diff
changeset
|
33 from sat.memory.params import Params |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
34 from sat.memory.disco import Discovery |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
35 from sat.memory.crypto import BlockCipher |
1064
7ee9d9db67b9
memory, tools (config): move special config retrieval from memory to tools
souliane <souliane@mailoo.org>
parents:
1046
diff
changeset
|
36 from sat.tools import config as tools_config |
420
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
37 |
679
59c9a7ff903d
wix, misc: use picture of dimension 32x32 for tray icon + better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
677
diff
changeset
|
38 |
756
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
39 class Sessions(object): |
1029
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
40 """Sessions are data associated to key used for a temporary moment, with optional profile checking.""" |
756
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
41 DEFAULT_TIMEOUT = 600 |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
42 |
1215
d9c399ec5dd9
memory: session timeout won't be reset on each access if the Sessions() is called with resettable_timeout=False
souliane <souliane@mailoo.org>
parents:
1214
diff
changeset
|
43 def __init__(self, timeout=None, resettable_timeout=True): |
756
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
44 """ |
1215
d9c399ec5dd9
memory: session timeout won't be reset on each access if the Sessions() is called with resettable_timeout=False
souliane <souliane@mailoo.org>
parents:
1214
diff
changeset
|
45 @param timeout (int): nb of seconds before session destruction |
d9c399ec5dd9
memory: session timeout won't be reset on each access if the Sessions() is called with resettable_timeout=False
souliane <souliane@mailoo.org>
parents:
1214
diff
changeset
|
46 @param resettable_timeout (bool): if True, the timeout is reset on each access |
756
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
47 """ |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
48 self._sessions = dict() |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
49 self.timeout = timeout or Sessions.DEFAULT_TIMEOUT |
1215
d9c399ec5dd9
memory: session timeout won't be reset on each access if the Sessions() is called with resettable_timeout=False
souliane <souliane@mailoo.org>
parents:
1214
diff
changeset
|
50 self.resettable_timeout = resettable_timeout |
756
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
51 |
1212
628e320eab1f
memory: Sessions.newSession can be called with a forced session ID
souliane <souliane@mailoo.org>
parents:
1199
diff
changeset
|
52 def newSession(self, session_data=None, session_id=None, profile=None): |
756
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
53 """ Create a new session |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
54 @param session_data: mutable data to use, default to a dict |
1212
628e320eab1f
memory: Sessions.newSession can be called with a forced session ID
souliane <souliane@mailoo.org>
parents:
1199
diff
changeset
|
55 @param session_id (str): force the session_id to the given string |
757
bbe55c7bee43
core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents:
756
diff
changeset
|
56 @param profile: if set, the session is owned by the profile, |
bbe55c7bee43
core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents:
756
diff
changeset
|
57 and profileGet must be used instead of __getitem__ |
756
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
58 @return: session_id, session_data |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
59 """ |
1212
628e320eab1f
memory: Sessions.newSession can be called with a forced session ID
souliane <souliane@mailoo.org>
parents:
1199
diff
changeset
|
60 if session_id is None: |
628e320eab1f
memory: Sessions.newSession can be called with a forced session ID
souliane <souliane@mailoo.org>
parents:
1199
diff
changeset
|
61 session_id = str(uuid4()) |
1213
b5928601d7aa
memory: handle the case where an existing session ID is re-used for creating a new session
souliane <souliane@mailoo.org>
parents:
1212
diff
changeset
|
62 elif session_id in self._sessions: |
b5928601d7aa
memory: handle the case where an existing session ID is re-used for creating a new session
souliane <souliane@mailoo.org>
parents:
1212
diff
changeset
|
63 self._sessions[session_id][0].cancel() |
b5928601d7aa
memory: handle the case where an existing session ID is re-used for creating a new session
souliane <souliane@mailoo.org>
parents:
1212
diff
changeset
|
64 log.warning("Session [{id}] is going to be re-initialised".format(id=session_id)) |
756
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
65 timer = reactor.callLater(self.timeout, self._purgeSession, session_id) |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
66 if session_data is None: |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
67 session_data = {} |
757
bbe55c7bee43
core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents:
756
diff
changeset
|
68 self._sessions[session_id] = (timer, session_data) if profile is None else (timer, session_data, profile) |
756
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
69 return session_id, session_data |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
70 |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
71 def _purgeSession(self, session_id): |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
72 del self._sessions[session_id] |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
946
diff
changeset
|
73 log.debug("Session [%s] purged" % session_id) |
756
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
74 |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
75 def __len__(self): |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
76 return len(self._sessions) |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
77 |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
78 def __contains__(self, session_id): |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
79 return session_id in self._sessions |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
80 |
757
bbe55c7bee43
core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents:
756
diff
changeset
|
81 def profileGet(self, session_id, profile): |
bbe55c7bee43
core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents:
756
diff
changeset
|
82 try: |
bbe55c7bee43
core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents:
756
diff
changeset
|
83 timer, session_data, profile_set = self._sessions[session_id] |
bbe55c7bee43
core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents:
756
diff
changeset
|
84 except ValueError: |
bbe55c7bee43
core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents:
756
diff
changeset
|
85 raise exceptions.InternalError("You need to use __getitem__ when profile is not set") |
bbe55c7bee43
core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents:
756
diff
changeset
|
86 if profile_set != profile: |
bbe55c7bee43
core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents:
756
diff
changeset
|
87 raise exceptions.InternalError("current profile differ from set profile !") |
1215
d9c399ec5dd9
memory: session timeout won't be reset on each access if the Sessions() is called with resettable_timeout=False
souliane <souliane@mailoo.org>
parents:
1214
diff
changeset
|
88 if self.resettable_timeout: |
d9c399ec5dd9
memory: session timeout won't be reset on each access if the Sessions() is called with resettable_timeout=False
souliane <souliane@mailoo.org>
parents:
1214
diff
changeset
|
89 timer.reset(self.timeout) |
757
bbe55c7bee43
core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents:
756
diff
changeset
|
90 return session_data |
bbe55c7bee43
core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents:
756
diff
changeset
|
91 |
756
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
92 def __getitem__(self, session_id): |
757
bbe55c7bee43
core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents:
756
diff
changeset
|
93 try: |
bbe55c7bee43
core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents:
756
diff
changeset
|
94 timer, session_data = self._sessions[session_id] |
bbe55c7bee43
core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents:
756
diff
changeset
|
95 except ValueError: |
bbe55c7bee43
core (memory): added optional profile checking in Sessions:
Goffi <goffi@goffi.org>
parents:
756
diff
changeset
|
96 raise exceptions.InternalError("You need to use profileGet instead of __getitem__ when profile is set") |
1215
d9c399ec5dd9
memory: session timeout won't be reset on each access if the Sessions() is called with resettable_timeout=False
souliane <souliane@mailoo.org>
parents:
1214
diff
changeset
|
97 if self.resettable_timeout: |
d9c399ec5dd9
memory: session timeout won't be reset on each access if the Sessions() is called with resettable_timeout=False
souliane <souliane@mailoo.org>
parents:
1214
diff
changeset
|
98 timer.reset(self.timeout) |
756
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
99 return session_data |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
100 |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
101 def __setitem__(self, key, value): |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
102 raise NotImplementedError("You need do use newSession to create a session") |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
103 |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
104 def __delitem__(self, session_id): |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
105 """ Cancel the timer, then actually delete the session data """ |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
106 try: |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
107 timer = self._sessions[session_id][0] |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
108 timer.cancel() |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
109 self._purgeSession(session_id) |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
110 except KeyError: |
1029
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
111 log.debug("Session [%s] doesn't exists, timeout expired?" % session_id) |
756
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
112 |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
113 def keys(self): |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
114 return self._sessions.keys() |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
115 |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
116 def iterkeys(self): |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
117 return self._sessions.iterkeys() |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
118 |
efa0e0f57950
core (memory): new Sessions management class (similar to dict)
Goffi <goffi@goffi.org>
parents:
751
diff
changeset
|
119 |
1029
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
120 class ProfileSessions(Sessions): |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
121 """ProfileSessions extends the Sessions class, but here the profile can be |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
122 used as the key to retrieve data or delete a session (instead of session id). |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
123 """ |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
124 |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
125 def _profileGetAllIds(self, profile): |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
126 """Return a list of the sessions ids that are associated to the given profile. |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
127 |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
128 @param profile: %(doc_profile)s |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
129 @return: a list containing the sessions ids |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
130 """ |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
131 ret = [] |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
132 for session_id in self._sessions: |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
133 try: |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
134 timer, session_data, profile_set = self._sessions[session_id] |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
135 except ValueError: |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
136 continue |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
137 if profile == profile_set: |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
138 ret.append(session_id) |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
139 return ret |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
140 |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
141 def profileGetUnique(self, profile): |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
142 """Return the data of the unique session that is associated to the given profile. |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
143 |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
144 @param profile: %(doc_profile)s |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
145 @return: |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
146 - mutable data (default: dict) of the unique session |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
147 - None if no session is associated to the profile |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
148 - raise an error if more than one session are found |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
149 """ |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
150 ids = self._profileGetAllIds(profile) |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
151 if len(ids) > 1: |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
152 raise exceptions.InternalError('profileGetUnique has been used but more than one session has been found!') |
1215
d9c399ec5dd9
memory: session timeout won't be reset on each access if the Sessions() is called with resettable_timeout=False
souliane <souliane@mailoo.org>
parents:
1214
diff
changeset
|
153 return self.profileGet(ids[0], profile) if len(ids) == 1 else None # XXX: timeout might be reset |
1214
ed3b01ed70d7
memory: profileSessions.profileGetUnique was not resetting the timer
souliane <souliane@mailoo.org>
parents:
1213
diff
changeset
|
154 |
1029
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
155 |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
156 def profileDelUnique(self, profile): |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
157 """Delete the unique session that is associated to the given profile. |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
158 |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
159 @param profile: %(doc_profile)s |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
160 @return: None, but raise an error if more than one session are found |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
161 """ |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
162 ids = self._profileGetAllIds(profile) |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
163 if len(ids) > 1: |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
164 raise exceptions.InternalError('profileDelUnique has been used but more than one session has been found!') |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
165 if len(ids) == 1: |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
166 del self._sessions[ids[0]] |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
167 |
f6182f6418ea
memory: add class ProfileSessions based on Sessions
souliane <souliane@mailoo.org>
parents:
1015
diff
changeset
|
168 |
1003
52ec79aa5bbe
memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
169 # XXX: tmp update code, will be removed in the future |
52ec79aa5bbe
memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
170 # When you remove this, please add the default value for |
52ec79aa5bbe
memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
171 # 'local_dir' in sat.core.constants.Const.DEFAULT_CONFIG |
52ec79aa5bbe
memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
172 def fixLocalDir(silent=True): |
52ec79aa5bbe
memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
173 """Retro-compatibility with the previous local_dir default value. |
52ec79aa5bbe
memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
174 |
52ec79aa5bbe
memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
175 @param silent (boolean): toggle logging output (must be True when called from sat.sh) |
52ec79aa5bbe
memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
176 """ |
52ec79aa5bbe
memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
177 user_config = SafeConfigParser() |
52ec79aa5bbe
memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
178 try: |
52ec79aa5bbe
memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
179 user_config.read(C.CONFIG_FILES) |
52ec79aa5bbe
memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
180 except: |
52ec79aa5bbe
memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
181 pass # file is readable but its structure if wrong |
52ec79aa5bbe
memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
182 try: |
52ec79aa5bbe
memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
183 current_value = user_config.get('DEFAULT', 'local_dir') |
52ec79aa5bbe
memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
184 except (NoOptionError, NoSectionError): |
52ec79aa5bbe
memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
185 current_value = '' |
52ec79aa5bbe
memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
186 if current_value: |
52ec79aa5bbe
memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
187 return # nothing to do |
52ec79aa5bbe
memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
188 old_default = '~/.sat' |
52ec79aa5bbe
memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
189 if os.path.isfile(os.path.expanduser(old_default) + '/' + C.SAVEFILE_DATABASE): |
52ec79aa5bbe
memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
190 if not silent: |
52ec79aa5bbe
memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
191 log.warning(_("A database has been found in the default local_dir for previous versions (< 0.5)")) |
1064
7ee9d9db67b9
memory, tools (config): move special config retrieval from memory to tools
souliane <souliane@mailoo.org>
parents:
1046
diff
changeset
|
192 tools_config.fixConfigOption('', 'local_dir', old_default, silent) |
1003
52ec79aa5bbe
memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
193 |
52ec79aa5bbe
memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
194 |
588
beaf6bec2fcd
Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
195 class Memory(object): |
1199 | 196 """This class manage all the persistent information""" |
0 | 197 |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
198 def __init__(self, host): |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
946
diff
changeset
|
199 log.info(_("Memory manager init")) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
200 self.initialized = defer.Deferred() |
41
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
201 self.host = host |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
202 self._entities_cache = {} # XXX: keep presence/last resource/other data in cache |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
203 # /!\ an entity is not necessarily in roster |
592
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
204 self.subscriptions = {} |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
205 self.auth_sessions = ProfileSessions() # remember the authenticated profiles |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
206 self.disco = Discovery(host) |
1003
52ec79aa5bbe
memory: fixes the method fixLocalDir for pid_dir and log_dir to use local_dir as default
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
207 fixLocalDir(False) # XXX: tmp update code, will be removed in the future |
364 | 208 self.config = self.parseMainConf() |
923 | 209 database_file = os.path.expanduser(os.path.join(self.getConfig('', 'local_dir'), C.SAVEFILE_DATABASE)) |
853
c2f6ada7858f
core (sqlite): automatic database update:
Goffi <goffi@goffi.org>
parents:
844
diff
changeset
|
210 self.storage = SqliteStorage(database_file, host.__version__) |
432
31e8c48b5f5d
core: - memory refactoring (moved memory.py and sqlite.py from tools to memory)
Goffi <goffi@goffi.org>
parents:
428
diff
changeset
|
211 PersistentDict.storage = self.storage |
592
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
212 self.params = Params(host, self.storage) |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
946
diff
changeset
|
213 log.info(_("Loading default params template")) |
677
9a50aa7feefb
core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents:
669
diff
changeset
|
214 self.params.load_default_params() |
592
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
215 d = self.storage.initialized.addCallback(lambda ignore: self.load()) |
443
7099ea9c1b12
core: getPrivate/setPrivate removed from memory, private values now use database storage and persistent dicts \o/
Goffi <goffi@goffi.org>
parents:
432
diff
changeset
|
216 self.memory_data = PersistentDict("memory") |
7099ea9c1b12
core: getPrivate/setPrivate removed from memory, private values now use database storage and persistent dicts \o/
Goffi <goffi@goffi.org>
parents:
432
diff
changeset
|
217 d.addCallback(lambda ignore: self.memory_data.load()) |
428
a4a9efadabfc
core: fixed memory initialisation sequence
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
218 d.chainDeferred(self.initialized) |
0 | 219 |
364 | 220 def parseMainConf(self): |
221 """look for main .ini configuration file, and parse it""" | |
930
cbf4122baae7
core, memory: use XDG recommended paths as the defaults for the config and local directories
souliane <souliane@mailoo.org>
parents:
923
diff
changeset
|
222 config = SafeConfigParser(defaults=C.DEFAULT_CONFIG) |
365
efbfccfed623
core: local_dir moved to config file
Goffi <goffi@goffi.org>
parents:
364
diff
changeset
|
223 try: |
930
cbf4122baae7
core, memory: use XDG recommended paths as the defaults for the config and local directories
souliane <souliane@mailoo.org>
parents:
923
diff
changeset
|
224 config.read(C.CONFIG_FILES) |
365
efbfccfed623
core: local_dir moved to config file
Goffi <goffi@goffi.org>
parents:
364
diff
changeset
|
225 except: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
946
diff
changeset
|
226 log.error(_("Can't read main config !")) |
930
cbf4122baae7
core, memory: use XDG recommended paths as the defaults for the config and local directories
souliane <souliane@mailoo.org>
parents:
923
diff
changeset
|
227 return config |
365
efbfccfed623
core: local_dir moved to config file
Goffi <goffi@goffi.org>
parents:
364
diff
changeset
|
228 |
1234
9c17bd37e6e5
core: better management of default value in getConfig
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
229 def getConfig(self, section, name, default=None): |
364 | 230 """Get the main configuration option |
1234
9c17bd37e6e5
core: better management of default value in getConfig
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
231 |
364 | 232 @param section: section of the config file (None or '' for DEFAULT) |
233 @param name: name of the option | |
1234
9c17bd37e6e5
core: better management of default value in getConfig
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
234 @param default: value to use if not found |
9c17bd37e6e5
core: better management of default value in getConfig
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
235 @return: str, list or dict |
365
efbfccfed623
core: local_dir moved to config file
Goffi <goffi@goffi.org>
parents:
364
diff
changeset
|
236 """ |
1234
9c17bd37e6e5
core: better management of default value in getConfig
Goffi <goffi@goffi.org>
parents:
1224
diff
changeset
|
237 return tools_config.getConfig(self.config, section, name, default) |
364 | 238 |
677
9a50aa7feefb
core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents:
669
diff
changeset
|
239 def load_xml(self, filename): |
1015
fee00f2e11c2
memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
1007
diff
changeset
|
240 """Load parameters template from xml file |
fee00f2e11c2
memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
1007
diff
changeset
|
241 |
fee00f2e11c2
memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
1007
diff
changeset
|
242 @param filename (str): input file |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
243 @return: bool: True in case of success |
1015
fee00f2e11c2
memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
1007
diff
changeset
|
244 """ |
fee00f2e11c2
memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
1007
diff
changeset
|
245 if not filename: |
677
9a50aa7feefb
core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents:
669
diff
changeset
|
246 return False |
9a50aa7feefb
core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents:
669
diff
changeset
|
247 filename = os.path.expanduser(filename) |
9a50aa7feefb
core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents:
669
diff
changeset
|
248 if os.path.exists(filename): |
0 | 249 try: |
677
9a50aa7feefb
core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents:
669
diff
changeset
|
250 self.params.load_xml(filename) |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
946
diff
changeset
|
251 log.debug(_("Parameters loaded from file: %s") % filename) |
677
9a50aa7feefb
core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents:
669
diff
changeset
|
252 return True |
557
4f856dd4c0d0
core: paramaters are now merged: if a parameter doens't exist in loaded xml but exists in default parameters, it is added
Goffi <goffi@goffi.org>
parents:
556
diff
changeset
|
253 except Exception as e: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
946
diff
changeset
|
254 log.error(_("Can't load parameters from file: %s") % e) |
677
9a50aa7feefb
core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents:
669
diff
changeset
|
255 return False |
0 | 256 |
443
7099ea9c1b12
core: getPrivate/setPrivate removed from memory, private values now use database storage and persistent dicts \o/
Goffi <goffi@goffi.org>
parents:
432
diff
changeset
|
257 def load(self): |
428
a4a9efadabfc
core: fixed memory initialisation sequence
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
258 """Load parameters and all memory things from db""" |
412 | 259 #parameters data |
428
a4a9efadabfc
core: fixed memory initialisation sequence
Goffi <goffi@goffi.org>
parents:
425
diff
changeset
|
260 return self.params.loadGenParams() |
412 | 261 |
416
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
262 def loadIndividualParams(self, profile): |
412 | 263 """Load individual parameters for a profile |
416
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
264 @param profile: %(doc_profile)s""" |
412 | 265 return self.params.loadIndParams(profile) |
266 | |
484
23cbdf0a0777
core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
267 def startProfileSession(self, profile): |
23cbdf0a0777
core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
268 """"Iniatialise session for a profile |
23cbdf0a0777
core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
269 @param profile: %(doc_profile)s""" |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
946
diff
changeset
|
270 log.info(_("[%s] Profile session started" % profile)) |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
271 self._entities_cache[profile] = {} |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
272 |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
273 def newAuthSession(self, key, profile): |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
274 """Start a new session for the authenticated profile. |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
275 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
276 The personal key is loaded encrypted from a PersistentDict before being decrypted. |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
277 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
278 @param key: the key to decrypt the personal key |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
279 @param profile: %(doc_profile)s |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
280 @return: a deferred None value |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
281 """ |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
282 def gotPersonalKey(personal_key): |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
283 """Create the session for this profile and store the personal key""" |
1212
628e320eab1f
memory: Sessions.newSession can be called with a forced session ID
souliane <souliane@mailoo.org>
parents:
1199
diff
changeset
|
284 self.auth_sessions.newSession({C.MEMORY_CRYPTO_KEY: personal_key}, profile=profile) |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
285 log.debug('auth session created for profile %s' % profile) |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
286 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
287 d = PersistentDict(C.MEMORY_CRYPTO_NAMESPACE, profile).load() |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
288 d.addCallback(lambda data: BlockCipher.decrypt(key, data[C.MEMORY_CRYPTO_KEY])) |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
289 return d.addCallback(gotPersonalKey) |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
290 |
484
23cbdf0a0777
core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
291 def purgeProfileSession(self, profile): |
416
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
292 """Delete cache of data of profile |
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
293 @param profile: %(doc_profile)s""" |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
946
diff
changeset
|
294 log.info(_("[%s] Profile session purge" % profile)) |
416
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
295 self.params.purgeProfile(profile) |
484
23cbdf0a0777
core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
296 try: |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
297 del self._entities_cache[profile] |
484
23cbdf0a0777
core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
298 except KeyError: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
946
diff
changeset
|
299 log.error(_("Trying to purge roster status cache for a profile not in memory: [%s]") % profile) |
484
23cbdf0a0777
core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
300 |
1015
fee00f2e11c2
memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
1007
diff
changeset
|
301 def save_xml(self, filename): |
fee00f2e11c2
memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
1007
diff
changeset
|
302 """Save parameters template to xml file |
fee00f2e11c2
memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
1007
diff
changeset
|
303 |
fee00f2e11c2
memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
1007
diff
changeset
|
304 @param filename (str): output file |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
305 @return: bool: True in case of success |
1015
fee00f2e11c2
memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
1007
diff
changeset
|
306 """ |
fee00f2e11c2
memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents:
1007
diff
changeset
|
307 if not filename: |
677
9a50aa7feefb
core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents:
669
diff
changeset
|
308 return False |
38 | 309 #TODO: need to encrypt files (at least passwords !) and set permissions |
677
9a50aa7feefb
core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents:
669
diff
changeset
|
310 filename = os.path.expanduser(filename) |
9a50aa7feefb
core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents:
669
diff
changeset
|
311 try: |
9a50aa7feefb
core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents:
669
diff
changeset
|
312 self.params.save_xml(filename) |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
946
diff
changeset
|
313 log.debug(_("Parameters saved to file: %s") % filename) |
677
9a50aa7feefb
core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents:
669
diff
changeset
|
314 return True |
9a50aa7feefb
core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents:
669
diff
changeset
|
315 except Exception as e: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
946
diff
changeset
|
316 log.error(_("Can't save parameters to file: %s") % e) |
677
9a50aa7feefb
core (memory): cleaned the part for load/save to xml (not used)
souliane <souliane@mailoo.org>
parents:
669
diff
changeset
|
317 return False |
0 | 318 |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
319 def getProfilesList(self): |
412 | 320 return self.storage.getProfilesList() |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
321 |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
322 def getProfileName(self, profile_key, return_profile_keys=False): |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
323 """Return name of profile from keyword |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
324 @param profile_key: can be the profile name or a keywork (like @DEFAULT@) |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
325 @return: profile name or None if it doesn't exist""" |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
722
diff
changeset
|
326 return self.params.getProfileName(profile_key, return_profile_keys) |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
327 |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
328 def asyncCreateProfile(self, name, password=''): |
420
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
329 """Create a new profile |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
330 @param name: profile name |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
331 @param password: profile password |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
332 @return: Deferred |
420
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
418
diff
changeset
|
333 """ |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
334 personal_key = BlockCipher.getRandomKey(base64=True) # generated once for all and saved in a PersistentDict |
1212
628e320eab1f
memory: Sessions.newSession can be called with a forced session ID
souliane <souliane@mailoo.org>
parents:
1199
diff
changeset
|
335 self.auth_sessions.newSession({C.MEMORY_CRYPTO_KEY: personal_key}, profile=name) # will be encrypted by setParam |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
336 d = self.params.asyncCreateProfile(name) |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
337 d.addCallback(lambda dummy: self.setParam(C.PROFILE_PASS_PATH[1], password, C.PROFILE_PASS_PATH[0], profile_key=name)) |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
338 return d |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
339 |
894
57c32d8ec847
core (memory): asyncDeleteProfile can force the deletion of a profile, even if it's connected (when called from the backend only)
souliane <souliane@mailoo.org>
parents:
893
diff
changeset
|
340 def asyncDeleteProfile(self, name, force=False): |
68 | 341 """Delete an existing profile |
894
57c32d8ec847
core (memory): asyncDeleteProfile can force the deletion of a profile, even if it's connected (when called from the backend only)
souliane <souliane@mailoo.org>
parents:
893
diff
changeset
|
342 @param name: Name of the profile |
57c32d8ec847
core (memory): asyncDeleteProfile can force the deletion of a profile, even if it's connected (when called from the backend only)
souliane <souliane@mailoo.org>
parents:
893
diff
changeset
|
343 @param force: force the deletion even if the profile is connected. |
57c32d8ec847
core (memory): asyncDeleteProfile can force the deletion of a profile, even if it's connected (when called from the backend only)
souliane <souliane@mailoo.org>
parents:
893
diff
changeset
|
344 To be used for direct calls only (not through the bridge). |
57c32d8ec847
core (memory): asyncDeleteProfile can force the deletion of a profile, even if it's connected (when called from the backend only)
souliane <souliane@mailoo.org>
parents:
893
diff
changeset
|
345 @return: a Deferred instance |
57c32d8ec847
core (memory): asyncDeleteProfile can force the deletion of a profile, even if it's connected (when called from the backend only)
souliane <souliane@mailoo.org>
parents:
893
diff
changeset
|
346 """ |
1097
dace0ede919c
memory (memory): delete profile session on profile deletion
souliane <souliane@mailoo.org>
parents:
1090
diff
changeset
|
347 self.auth_sessions.profileDelUnique(name) |
894
57c32d8ec847
core (memory): asyncDeleteProfile can force the deletion of a profile, even if it's connected (when called from the backend only)
souliane <souliane@mailoo.org>
parents:
893
diff
changeset
|
348 return self.params.asyncDeleteProfile(name, force) |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
349 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
914
diff
changeset
|
350 def addToHistory(self, from_jid, to_jid, message, type_='chat', extra=None, timestamp=None, profile=C.PROF_KEY_NONE): |
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
914
diff
changeset
|
351 assert profile != C.PROF_KEY_NONE |
669
ffb716804580
core, bridge: extra parameter is saved in history:
Goffi <goffi@goffi.org>
parents:
662
diff
changeset
|
352 if extra is None: |
ffb716804580
core, bridge: extra parameter is saved in history:
Goffi <goffi@goffi.org>
parents:
662
diff
changeset
|
353 extra = {} |
722
04aabc3f2684
core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents:
679
diff
changeset
|
354 return self.storage.addToHistory(from_jid, to_jid, message, type_, extra, timestamp, profile) |
0 | 355 |
1224
f0c9b149ed99
bridge, memory: add "search" attribute to getHistory (filter the results with a unix globbing pattern)
souliane <souliane@mailoo.org>
parents:
1222
diff
changeset
|
356 def getHistory(self, from_jid, to_jid, limit=C.HISTORY_LIMIT_NONE, between=True, search=None, profile=C.PROF_KEY_NONE): |
1222
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
357 """Retrieve messages in history |
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
358 @param from_jid (JID): source JID (full, or bare for catchall) |
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
359 @param to_jid (JID): dest JID (full, or bare for catchall) |
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
360 @param limit (int): maximum number of messages to get: |
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
361 - 0 for no message (returns the empty list) |
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
362 - C.HISTORY_LIMIT_NONE or None for unlimited |
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
363 - C.HISTORY_LIMIT_DEFAULT to use the HISTORY_LIMIT parameter value |
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
364 @param between (bool): confound source and dest (ignore the direction) |
1224
f0c9b149ed99
bridge, memory: add "search" attribute to getHistory (filter the results with a unix globbing pattern)
souliane <souliane@mailoo.org>
parents:
1222
diff
changeset
|
365 @param search (str): pattern to filter the history results |
1222
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
366 @param profile (str): %(doc_profile)s |
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
367 @return: list of tuple as in http://wiki.goffi.org/wiki/Bridge_API#getHistory |
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
368 """ |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
914
diff
changeset
|
369 assert profile != C.PROF_KEY_NONE |
1222
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
370 if limit == C.HISTORY_LIMIT_DEFAULT: |
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
371 limit = int(self.getParamA(C.HISTORY_LIMIT, 'General', profile_key=profile)) |
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
372 elif limit == C.HISTORY_LIMIT_NONE: |
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
373 limit = None |
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
374 if limit == 0: |
e6e0ea4dc835
memory: add Parameter "Chat history limit"
souliane <souliane@mailoo.org>
parents:
1221
diff
changeset
|
375 return defer.succeed([]) |
1224
f0c9b149ed99
bridge, memory: add "search" attribute to getHistory (filter the results with a unix globbing pattern)
souliane <souliane@mailoo.org>
parents:
1222
diff
changeset
|
376 return self.storage.getHistory(jid.JID(from_jid), jid.JID(to_jid), limit, between, search, profile) |
0 | 377 |
919
ed9841e6d84a
core: added IQ_SET to core.constants + getLastResource now manage correctly jid.JID
Goffi <goffi@goffi.org>
parents:
916
diff
changeset
|
378 def _getLastResource(self, jid_s, profile_key): |
ed9841e6d84a
core: added IQ_SET to core.constants + getLastResource now manage correctly jid.JID
Goffi <goffi@goffi.org>
parents:
916
diff
changeset
|
379 jid_ = jid.JID(jid_s) |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
380 return self.getLastResource(jid_, profile_key) or "" |
919
ed9841e6d84a
core: added IQ_SET to core.constants + getLastResource now manage correctly jid.JID
Goffi <goffi@goffi.org>
parents:
916
diff
changeset
|
381 |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
382 def getLastResource(self, entity_jid, profile_key): |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
383 """Return the last resource used by an entity |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
384 @param entity_jid: entity jid |
399 | 385 @param profile_key: %(doc_profile_key)s""" |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
386 data = self.getEntityData(entity_jid.userhostJID(), [C.ENTITY_LAST_RESOURCE], profile_key) |
399 | 387 try: |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
388 return data[C.ENTITY_LAST_RESOURCE] |
484
23cbdf0a0777
core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
389 except KeyError: |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
390 return None |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
391 |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
392 def _getPresenceStatuses(self, profile_key): |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
393 ret = self.getPresenceStatuses(profile_key) |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
394 return {entity.full():data for entity, data in ret.iteritems()} |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
395 |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
396 def getPresenceStatuses(self, profile_key): |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
397 """Get all the presence status of a profile |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
398 @param profile_key: %(doc_profile_key)s |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
399 @return: presence data: key=entity JID, value=presence data for this entity |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
400 """ |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
401 profile = self.getProfileName(profile_key) |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
402 if not profile: |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
403 raise exceptions.ProfileUnknownError(_('Trying to get entity data for a non-existant profile')) |
484
23cbdf0a0777
core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
404 entities_presence = {} |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
405 for entity in self._entities_cache[profile]: |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
406 if "presence" in self._entities_cache[profile][entity]: |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
407 entities_presence[entity] = self._entities_cache[profile][entity]["presence"] |
484
23cbdf0a0777
core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
408 |
1007
a7d33c7a8277
core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents:
1003
diff
changeset
|
409 log.debug("Memory getPresenceStatus (%s)" % entities_presence) |
484
23cbdf0a0777
core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
410 return entities_presence |
0 | 411 |
486
0d9908ac775e
core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents:
484
diff
changeset
|
412 def setPresenceStatus(self, entity_jid, show, priority, statuses, profile_key): |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
413 """Change the presence status of an entity |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
414 @param entity_jid: jid.JID of the entity |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
415 @param show: show status |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
416 @param priotity: priotity |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
417 @param statuses: dictionary of statuses |
486
0d9908ac775e
core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents:
484
diff
changeset
|
418 @param profile_key: %(doc_profile_key)s |
0d9908ac775e
core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents:
484
diff
changeset
|
419 """ |
0d9908ac775e
core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents:
484
diff
changeset
|
420 profile = self.getProfileName(profile_key) |
0d9908ac775e
core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents:
484
diff
changeset
|
421 if not profile: |
656
7d6e5807504a
bridge, memory: added the parameter security_limit to asyncGetParamA so it can be used from libervia. refactorization in memory.py are related to that.
souliane <souliane@mailoo.org>
parents:
645
diff
changeset
|
422 raise exceptions.ProfileUnknownError(_('Trying to get entity data for a non-existant profile')) |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
423 entity_data = self._getEntitiesData(entity_jid, profile)[entity_jid] |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
424 resource = entity_jid.resource |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
425 if resource: |
1240
22adf1eb59f5
memory: don't save last resource in entity data for the MUC jids
souliane <souliane@mailoo.org>
parents:
1234
diff
changeset
|
426 try: |
22adf1eb59f5
memory: don't save last resource in entity data for the MUC jids
souliane <souliane@mailoo.org>
parents:
1234
diff
changeset
|
427 type_ = self.getEntityDatum(entity_jid.userhostJID(), 'type', profile) |
22adf1eb59f5
memory: don't save last resource in entity data for the MUC jids
souliane <souliane@mailoo.org>
parents:
1234
diff
changeset
|
428 except KeyError: |
22adf1eb59f5
memory: don't save last resource in entity data for the MUC jids
souliane <souliane@mailoo.org>
parents:
1234
diff
changeset
|
429 type_ = 'contact' |
22adf1eb59f5
memory: don't save last resource in entity data for the MUC jids
souliane <souliane@mailoo.org>
parents:
1234
diff
changeset
|
430 if type_ != 'chatroom': |
22adf1eb59f5
memory: don't save last resource in entity data for the MUC jids
souliane <souliane@mailoo.org>
parents:
1234
diff
changeset
|
431 self.updateEntityData(entity_jid.userhostJID(), C.ENTITY_LAST_RESOURCE, resource, profile) |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
432 entity_data.setdefault("presence", {})[resource or ''] = (show, priority, statuses) |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
433 |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
434 def _getEntitiesData(self, entity_jid, profile): |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
435 """Get data dictionary for entities |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
436 @param entity_jid: JID of the entity, or C.ENTITY_ALL for all entities) |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
437 @param profile: %(doc_profile)s |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
438 @return: entities_data (key=jid, value=entity_data) |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
439 @raise: exceptions.ProfileNotInCacheError if profile is not in cache |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
440 """ |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
441 if not profile in self._entities_cache: |
486
0d9908ac775e
core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents:
484
diff
changeset
|
442 raise exceptions.ProfileNotInCacheError |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
443 if entity_jid == C.ENTITY_ALL: |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
444 entities_data = self._entities_cache[profile] |
635
eff8772fd472
core: memory's updateEntityData improvments.
souliane <souliane@mailoo.org>
parents:
634
diff
changeset
|
445 else: |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
446 entity_data = self._entities_cache[profile].setdefault(entity_jid, {}) |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
447 entities_data = {entity_jid: entity_data} |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
448 return entities_data |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
449 |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
450 def _updateEntityResources(self, entity_jid, profile): |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
451 """Add a known resource to bare entity_jid cache |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
452 @param entity_jid: full entity_jid (with resource) |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
453 @param profile: %(doc_profile)s |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
454 """ |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
455 assert(entity_jid.resource) |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
456 entity_data = self._getEntitiesData(entity_jid.userhostJID(), profile)[entity_jid.userhostJID()] |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
457 resources = entity_data.setdefault('resources', set()) |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
458 resources.add(entity_jid.resource) |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
459 |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
460 def updateEntityData(self, entity_jid, key, value, profile_key): |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
461 """Set a misc data for an entity |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
462 @param entity_jid: JID of the entity, or C.ENTITY_ALL to update all entities) |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
463 @param key: key to set (eg: "type") |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
464 @param value: value for this key (eg: "chatroom") |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
465 @param profile_key: %(doc_profile_key)s |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
466 """ |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
467 profile = self.getProfileName(profile_key) |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
468 if not profile: |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
469 raise exceptions.ProfileUnknownError(_('Trying to get entity data for a non-existant profile')) |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
470 entities_data = self._getEntitiesData(entity_jid, profile) |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
471 if entity_jid.resource and entity_jid != C.ENTITY_ALL: |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
472 self._updateEntityResources(entity_jid, profile) |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
473 |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
474 for jid_ in entities_data: |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
475 entity_data = entities_data[jid_] |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
476 if value == C.PROF_KEY_NONE and key in entity_data: |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
477 del entity_data[key] |
635
eff8772fd472
core: memory's updateEntityData improvments.
souliane <souliane@mailoo.org>
parents:
634
diff
changeset
|
478 else: |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
479 entity_data[key] = value |
635
eff8772fd472
core: memory's updateEntityData improvments.
souliane <souliane@mailoo.org>
parents:
634
diff
changeset
|
480 if isinstance(value, basestring): |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
481 self.host.bridge.entityDataUpdated(jid_.full(), key, value, profile) |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
482 |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
483 def delEntityData(self, entity_jid, key, profile_key): |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
484 """Delete data for an entity |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
485 @param entity_jid: JID of the entity, or C.ENTITY_ALL to delete data from all entities) |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
486 @param key: key to delete (eg: "type") |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
487 @param profile_key: %(doc_profile_key)s |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
488 """ |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
489 entities_data = self._getEntitiesData(entity_jid, profile_key) |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
490 for entity_jid in entities_data: |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
491 entity_data = entities_data[entity_jid] |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
492 try: |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
493 del entity_data[key] |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
494 except KeyError: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
946
diff
changeset
|
495 log.debug("Key [%s] doesn't exist for [%s] in entities_cache" % (key, entity_jid.full())) |
399 | 496 |
486
0d9908ac775e
core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents:
484
diff
changeset
|
497 def getEntityData(self, entity_jid, keys_list, profile_key): |
0d9908ac775e
core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents:
484
diff
changeset
|
498 """Get a list of cached values for entity |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
499 |
486
0d9908ac775e
core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents:
484
diff
changeset
|
500 @param entity_jid: JID of the entity |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
501 @param keys_list (iterable): list of keys to get, empty list for everything |
486
0d9908ac775e
core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents:
484
diff
changeset
|
502 @param profile_key: %(doc_profile_key)s |
0d9908ac775e
core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents:
484
diff
changeset
|
503 @return: dict withs values for each key in keys_list. |
504
65ecbb473cbb
core, quick frontend, plugin xep-0054, bridge: use of memory's entities data for vcard:
Goffi <goffi@goffi.org>
parents:
494
diff
changeset
|
504 if there is no value of a given key, resulting dict will |
486
0d9908ac775e
core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents:
484
diff
changeset
|
505 have nothing with that key nether |
0d9908ac775e
core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents:
484
diff
changeset
|
506 @raise: exceptions.UnknownEntityError if entity is not in cache |
0d9908ac775e
core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents:
484
diff
changeset
|
507 """ |
0d9908ac775e
core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents:
484
diff
changeset
|
508 profile = self.getProfileName(profile_key) |
0d9908ac775e
core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents:
484
diff
changeset
|
509 if not profile: |
656
7d6e5807504a
bridge, memory: added the parameter security_limit to asyncGetParamA so it can be used from libervia. refactorization in memory.py are related to that.
souliane <souliane@mailoo.org>
parents:
645
diff
changeset
|
510 raise exceptions.ProfileUnknownError(_('Trying to get entity data for a non-existant profile')) |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
511 entity_data = self._getEntitiesData(entity_jid, profile)[entity_jid] |
486
0d9908ac775e
core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents:
484
diff
changeset
|
512 if not keys_list: |
0d9908ac775e
core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents:
484
diff
changeset
|
513 return entity_data |
0d9908ac775e
core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents:
484
diff
changeset
|
514 ret = {} |
0d9908ac775e
core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents:
484
diff
changeset
|
515 for key in keys_list: |
0d9908ac775e
core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents:
484
diff
changeset
|
516 if key in entity_data: |
0d9908ac775e
core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents:
484
diff
changeset
|
517 ret[key] = entity_data[key] |
0d9908ac775e
core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents:
484
diff
changeset
|
518 return ret |
47 | 519 |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
520 def getEntityDatum(self, entity_jid, key, profile_key): |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
521 """Get a datum from entity |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
522 |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
523 @param entity_jid: JID of the entity |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
524 @param keys: key to get |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
525 @param profile_key: %(doc_profile_key)s |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
526 @return: requested value |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
527 |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
528 @raise: exceptions.UnknownEntityError if entity is not in cache |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
529 @raise: KeyError if there is no value for this key and this entity |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
530 """ |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
531 return self.getEntityData(entity_jid, (key,), profile_key)[key] |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
532 |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
533 def delEntityCache(self, entity_jid, delete_all_resources=True, profile_key=C.PROF_KEY_NONE): |
507
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
504
diff
changeset
|
534 """Remove cached data for entity |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
535 @param entity_jid: JID of the entity to delete |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
536 @param delete_all_resources: if True also delete all known resources form cache |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
537 @param profile_key: %(doc_profile_key)s |
507
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
504
diff
changeset
|
538 """ |
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
504
diff
changeset
|
539 profile = self.getProfileName(profile_key) |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
540 if not profile: |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
541 raise exceptions.ProfileUnknownError(_('Trying to get entity data for a non-existant profile')) |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
542 to_delete = set([entity_jid]) |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
543 |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
544 if delete_all_resources: |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
545 if entity_jid.resource: |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
546 raise ValueError(_("Need a bare jid to delete all resources")) |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
547 entity_data = self._getEntitiesData(entity_jid, profile)[entity_jid] |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
548 resources = entity_data.setdefault('resources', set()) |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
549 to_delete.update([jid.JID("%s/%s" % (entity_jid.userhost(), resource)) for resource in resources]) |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
550 |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
551 for entity in to_delete: |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
552 try: |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
553 del self._entities_cache[profile][entity] |
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
935
diff
changeset
|
554 except KeyError: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
946
diff
changeset
|
555 log.debug("Can't delete entity [%s]: not in cache" % entity.full()) |
507
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
504
diff
changeset
|
556 |
1090
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
557 def encryptValue(self, value, profile): |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
558 """Encrypt a value for the given profile. The personal key must be loaded |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
559 already in the profile session, that should be the case if the profile is |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
560 already authenticated. |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
561 |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
562 @param value (str): the value to encrypt |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
563 @param profile (str): %(doc_profile)s |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
564 @return: the deferred encrypted value |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
565 """ |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
566 try: |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
567 personal_key = self.host.memory.auth_sessions.profileGetUnique(profile)[C.MEMORY_CRYPTO_KEY] |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
568 except TypeError: |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
569 raise exceptions.InternalError(_('Trying to encrypt a value for %s while the personal key is undefined!') % profile) |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
570 return BlockCipher.encrypt(personal_key, value) |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
571 |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
572 def decryptValue(self, value, profile): |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
573 """Decrypt a value for the given profile. The personal key must be loaded |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
574 already in the profile session, that should be the case if the profile is |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
575 already authenticated. |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
576 |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
577 @param value (str): the value to decrypt |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
578 @param profile (str): %(doc_profile)s |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
579 @return: the deferred decrypted value |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
580 """ |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
581 try: |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
582 personal_key = self.host.memory.auth_sessions.profileGetUnique(profile)[C.MEMORY_CRYPTO_KEY] |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
583 except TypeError: |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
584 raise exceptions.InternalError(_('Trying to decrypt a value for %s while the personal key is undefined!') % profile) |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
585 return BlockCipher.decrypt(personal_key, value) |
594fbdda4a87
memory: add helper methods encryptValue and decryptValue
souliane <souliane@mailoo.org>
parents:
1064
diff
changeset
|
586 |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
587 def encryptPersonalData(self, data_key, data_value, crypto_key, profile): |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
588 """Re-encrypt a personal data (saved to a PersistentDict). |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
589 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
590 @param data_key: key for the individual PersistentDict instance |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
591 @param data_value: the value to be encrypted |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
592 @param crypto_key: the key to encrypt the value |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
593 @param profile: %(profile_doc)s |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
594 @return: a deferred None value |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
595 """ |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
596 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
597 def gotIndMemory(data): |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
598 d = BlockCipher.encrypt(crypto_key, data_value) |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
599 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
600 def cb(cipher): |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
601 data[data_key] = cipher |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
602 return data.force(data_key) |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
603 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
604 return d.addCallback(cb) |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
605 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
606 def done(dummy): |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
607 log.debug(_('Personal data (%(ns)s, %(key)s) has been successfuly encrypted') % |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
608 {'ns': C.MEMORY_CRYPTO_NAMESPACE, 'key': data_key}) |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
609 |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
610 d = PersistentDict(C.MEMORY_CRYPTO_NAMESPACE, profile).load() |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
611 return d.addCallback(gotIndMemory).addCallback(done) |
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1029
diff
changeset
|
612 |
722
04aabc3f2684
core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents:
679
diff
changeset
|
613 def addWaitingSub(self, type_, entity_jid, profile_key): |
47 | 614 """Called when a subcription request is received""" |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
615 profile = self.getProfileName(profile_key) |
592
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
616 assert profile |
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
617 if profile not in self.subscriptions: |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
618 self.subscriptions[profile] = {} |
722
04aabc3f2684
core (memory): fixed setDefault behaviour + minor refactoring
Goffi <goffi@goffi.org>
parents:
679
diff
changeset
|
619 self.subscriptions[profile][entity_jid] = type_ |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
620 |
486
0d9908ac775e
core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents:
484
diff
changeset
|
621 def delWaitingSub(self, entity_jid, profile_key): |
47 | 622 """Called when a subcription request is finished""" |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
623 profile = self.getProfileName(profile_key) |
592
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
624 assert profile |
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
625 if profile in self.subscriptions and entity_jid in self.subscriptions[profile]: |
486
0d9908ac775e
core: entity cache misc data management + error moved to core.exceptions in memory
Goffi <goffi@goffi.org>
parents:
484
diff
changeset
|
626 del self.subscriptions[profile][entity_jid] |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
627 |
346
ca3a041fed30
core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents:
327
diff
changeset
|
628 def getWaitingSub(self, profile_key): |
47 | 629 """Called to get a list of currently waiting subscription requests""" |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
630 profile = self.getProfileName(profile_key) |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
631 if not profile: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
946
diff
changeset
|
632 log.error(_('Asking waiting subscriptions for a non-existant profile')) |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
633 return {} |
592
e5a875a3311b
Fix pep8 support in src/memory.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
634 if profile not in self.subscriptions: |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
635 return {} |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
636 |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
637 return self.subscriptions[profile] |
0 | 638 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
914
diff
changeset
|
639 def getStringParamA(self, name, category, attr="value", profile_key=C.PROF_KEY_NONE): |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
512
diff
changeset
|
640 return self.params.getStringParamA(name, category, attr, profile_key) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
641 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
914
diff
changeset
|
642 def getParamA(self, name, category, attr="value", profile_key=C.PROF_KEY_NONE): |
64 | 643 return self.params.getParamA(name, category, attr, profile_key) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
644 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
914
diff
changeset
|
645 def asyncGetParamA(self, name, category, attr="value", security_limit=C.NO_SECURITY_LIMIT, profile_key=C.PROF_KEY_NONE): |
656
7d6e5807504a
bridge, memory: added the parameter security_limit to asyncGetParamA so it can be used from libervia. refactorization in memory.py are related to that.
souliane <souliane@mailoo.org>
parents:
645
diff
changeset
|
646 return self.params.asyncGetParamA(name, category, attr, security_limit, profile_key) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
647 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
914
diff
changeset
|
648 def asyncGetStringParamA(self, name, category, attr="value", security_limit=C.NO_SECURITY_LIMIT, profile_key=C.PROF_KEY_NONE): |
656
7d6e5807504a
bridge, memory: added the parameter security_limit to asyncGetParamA so it can be used from libervia. refactorization in memory.py are related to that.
souliane <souliane@mailoo.org>
parents:
645
diff
changeset
|
649 return self.params.asyncGetStringParamA(name, category, attr, security_limit, profile_key) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
650 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
914
diff
changeset
|
651 def getParamsUI(self, security_limit=C.NO_SECURITY_LIMIT, app='', profile_key=C.PROF_KEY_NONE): |
777
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
652 return self.params.getParamsUI(security_limit, app, profile_key) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
653 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
914
diff
changeset
|
654 def getParams(self, security_limit=C.NO_SECURITY_LIMIT, app='', profile_key=C.PROF_KEY_NONE): |
777
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
655 return self.params.getParams(security_limit, app, profile_key) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
656 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
914
diff
changeset
|
657 def getParamsForCategory(self, category, security_limit=C.NO_SECURITY_LIMIT, app='', profile_key=C.PROF_KEY_NONE): |
777
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
658 return self.params.getParamsForCategory(category, security_limit, app, profile_key) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
659 |
0 | 660 def getParamsCategories(self): |
17
74a39f40eb6d
refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
661 return self.params.getParamsCategories() |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
662 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
914
diff
changeset
|
663 def setParam(self, name, value, category, security_limit=C.NO_SECURITY_LIMIT, profile_key=C.PROF_KEY_NONE): |
641
49587e170f53
core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents:
639
diff
changeset
|
664 return self.params.setParam(name, value, category, security_limit, profile_key) |
19
f2a745ca0fbc
refactoring: using xml params part III (parameters import)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
665 |
662
4f747d7fde8c
core: importParams renamed to updateParams: it now updates the parameter instead of appending children if it find an existing one.
Goffi <goffi@goffi.org>
parents:
656
diff
changeset
|
666 def updateParams(self, xml): |
4f747d7fde8c
core: importParams renamed to updateParams: it now updates the parameter instead of appending children if it find an existing one.
Goffi <goffi@goffi.org>
parents:
656
diff
changeset
|
667 return self.params.updateParams(xml) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
574
diff
changeset
|
668 |
914
1a3ba959f0ab
core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents:
909
diff
changeset
|
669 def paramsRegisterApp(self, xml, security_limit=C.NO_SECURITY_LIMIT, app=''): |
777
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
670 return self.params.paramsRegisterApp(xml, security_limit, app) |
5642939d254e
core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
671 |
20
fc8c202cda87
refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
672 def setDefault(self, name, category, callback, errback=None): |
fc8c202cda87
refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
673 return self.params.setDefault(name, category, callback, errback) |