Mercurial > libervia-backend
annotate src/tools/common/data_objects.py @ 2477:cae326e962c3
tool (utils): import directly parser from dateutil
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 21 Jan 2018 13:04:16 +0100 |
parents | 6607bb29ab7b |
children | e5acc83a9d51 |
rev | line source |
---|---|
2160
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/env python2 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 # SAT: a jabber client |
2414
8b37a62336c3
misc: date update (yes it's a bit late :p )
Goffi <goffi@goffi.org>
parents:
2383
diff
changeset
|
5 # Copyright (C) 2009-2017 Jérôme Poisson (goffi@goffi.org) |
2160
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 # (at your option) any later version. |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 # GNU Affero General Public License for more details. |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
2300
173d56315529
jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents:
2264
diff
changeset
|
20 """Objects handling bridge data, with jinja2 safe markup handling""" |
2160
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 from sat.tools.common import data_format |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 try: |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 from jinja2 import Markup as safe |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 except ImportError: |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 safe = unicode |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 |
2476
6607bb29ab7b
tools (common/data_objects): BlogItem has now a uri property to generate its own XMPP URI
Goffi <goffi@goffi.org>
parents:
2469
diff
changeset
|
28 from sat.tools.common import uri as xmpp_uri |
6607bb29ab7b
tools (common/data_objects): BlogItem has now a uri property to generate its own XMPP URI
Goffi <goffi@goffi.org>
parents:
2469
diff
changeset
|
29 |
2160
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 class BlogItem(object): |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 |
2476
6607bb29ab7b
tools (common/data_objects): BlogItem has now a uri property to generate its own XMPP URI
Goffi <goffi@goffi.org>
parents:
2469
diff
changeset
|
33 def __init__(self, mb_data, parent): |
2160
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 self.mb_data = mb_data |
2476
6607bb29ab7b
tools (common/data_objects): BlogItem has now a uri property to generate its own XMPP URI
Goffi <goffi@goffi.org>
parents:
2469
diff
changeset
|
35 self.parent = parent |
2160
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 self._tags = None |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 self._groups = None |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 self._comments = None |
2228
cf6c539672c7
tools (common/data_objects): comments items can now be chained to their parent
Goffi <goffi@goffi.org>
parents:
2160
diff
changeset
|
39 self._comments_items_list = None |
2160
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 @property |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 def id(self): |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 return self.mb_data.get(u'id') |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 @property |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 def atom_id(self): |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 return self.mb_data.get(u'atom_id') |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 @property |
2476
6607bb29ab7b
tools (common/data_objects): BlogItem has now a uri property to generate its own XMPP URI
Goffi <goffi@goffi.org>
parents:
2469
diff
changeset
|
50 def uri(self): |
6607bb29ab7b
tools (common/data_objects): BlogItem has now a uri property to generate its own XMPP URI
Goffi <goffi@goffi.org>
parents:
2469
diff
changeset
|
51 node = self.parent.node |
6607bb29ab7b
tools (common/data_objects): BlogItem has now a uri property to generate its own XMPP URI
Goffi <goffi@goffi.org>
parents:
2469
diff
changeset
|
52 service = self.parent.service |
6607bb29ab7b
tools (common/data_objects): BlogItem has now a uri property to generate its own XMPP URI
Goffi <goffi@goffi.org>
parents:
2469
diff
changeset
|
53 return xmpp_uri.buildXMPPUri(u'pubsub', |
6607bb29ab7b
tools (common/data_objects): BlogItem has now a uri property to generate its own XMPP URI
Goffi <goffi@goffi.org>
parents:
2469
diff
changeset
|
54 subtype=u'microblog', |
6607bb29ab7b
tools (common/data_objects): BlogItem has now a uri property to generate its own XMPP URI
Goffi <goffi@goffi.org>
parents:
2469
diff
changeset
|
55 path=service, |
6607bb29ab7b
tools (common/data_objects): BlogItem has now a uri property to generate its own XMPP URI
Goffi <goffi@goffi.org>
parents:
2469
diff
changeset
|
56 node=node, |
6607bb29ab7b
tools (common/data_objects): BlogItem has now a uri property to generate its own XMPP URI
Goffi <goffi@goffi.org>
parents:
2469
diff
changeset
|
57 item=self.id) |
6607bb29ab7b
tools (common/data_objects): BlogItem has now a uri property to generate its own XMPP URI
Goffi <goffi@goffi.org>
parents:
2469
diff
changeset
|
58 |
6607bb29ab7b
tools (common/data_objects): BlogItem has now a uri property to generate its own XMPP URI
Goffi <goffi@goffi.org>
parents:
2469
diff
changeset
|
59 @property |
2160
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 def published(self): |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 return self.mb_data.get(u'published') |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 @property |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 def updated(self): |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 return self.mb_data.get(u'updated') |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 @property |
2264
a8eaaac4d80f
plugin XEP-0277, tools/common/data_objects: language handling
Goffi <goffi@goffi.org>
parents:
2257
diff
changeset
|
68 def language(self): |
a8eaaac4d80f
plugin XEP-0277, tools/common/data_objects: language handling
Goffi <goffi@goffi.org>
parents:
2257
diff
changeset
|
69 return self.mb_data.get(u'language') |
a8eaaac4d80f
plugin XEP-0277, tools/common/data_objects: language handling
Goffi <goffi@goffi.org>
parents:
2257
diff
changeset
|
70 |
a8eaaac4d80f
plugin XEP-0277, tools/common/data_objects: language handling
Goffi <goffi@goffi.org>
parents:
2257
diff
changeset
|
71 @property |
2160
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 def author(self): |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 return self.mb_data.get(u'author') |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 @property |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 def author_jid(self): |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 return self.mb_data.get(u'author_jid') |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 @property |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 def author_jid_verified(self): |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 return self.mb_data.get(u'author_jid_verified') |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 @property |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 def author_email(self): |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 return self.mb_data.get(u'author_email') |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 @property |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 def tags(self): |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
89 if self._tags is None: |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 self._tags = data_format.dict2iter('tag', self.mb_data) |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
91 return self._tags |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
92 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 @property |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
94 def groups(self): |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
95 if self._groups is None: |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 self._groups = data_format.dict2iter('group', self.mb_data) |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 return self._groups |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
98 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
99 @property |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
100 def title(self): |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
101 return self.mb_data.get(u'title') |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
102 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
103 @property |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
104 def title_xhtml(self): |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
105 try: |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
106 return safe(self.mb_data[u'title_xhtml']) |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
107 except KeyError: |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
108 return None |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
109 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
110 @property |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
111 def content(self): |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
112 return self.mb_data.get(u'content') |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
113 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
114 @property |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
115 def content_xhtml(self): |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
116 try: |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
117 return safe(self.mb_data[u'content_xhtml']) |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
118 except KeyError: |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 return None |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
120 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 @property |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
122 def comments(self): |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
123 if self._comments is None: |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
124 self._comments = data_format.dict2iterdict(u'comments', self.mb_data, (u'node', u'service')) |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
125 return self._comments |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
126 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
127 @property |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
128 def comments_service(self): |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 return self.mb_data.get(u'comments_service') |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
130 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
131 @property |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
132 def comments_node(self): |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
133 return self.mb_data.get(u'comments_node') |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
134 |
2228
cf6c539672c7
tools (common/data_objects): comments items can now be chained to their parent
Goffi <goffi@goffi.org>
parents:
2160
diff
changeset
|
135 @property |
cf6c539672c7
tools (common/data_objects): comments items can now be chained to their parent
Goffi <goffi@goffi.org>
parents:
2160
diff
changeset
|
136 def comments_items_list(self): |
cf6c539672c7
tools (common/data_objects): comments items can now be chained to their parent
Goffi <goffi@goffi.org>
parents:
2160
diff
changeset
|
137 return [] if self._comments_items_list is None else self._comments_items_list |
cf6c539672c7
tools (common/data_objects): comments items can now be chained to their parent
Goffi <goffi@goffi.org>
parents:
2160
diff
changeset
|
138 |
cf6c539672c7
tools (common/data_objects): comments items can now be chained to their parent
Goffi <goffi@goffi.org>
parents:
2160
diff
changeset
|
139 def appendCommentsItems(self, items): |
cf6c539672c7
tools (common/data_objects): comments items can now be chained to their parent
Goffi <goffi@goffi.org>
parents:
2160
diff
changeset
|
140 """append comments items to self.comments_items""" |
cf6c539672c7
tools (common/data_objects): comments items can now be chained to their parent
Goffi <goffi@goffi.org>
parents:
2160
diff
changeset
|
141 if self._comments_items_list is None: |
cf6c539672c7
tools (common/data_objects): comments items can now be chained to their parent
Goffi <goffi@goffi.org>
parents:
2160
diff
changeset
|
142 self._comments_items_list = [] |
cf6c539672c7
tools (common/data_objects): comments items can now be chained to their parent
Goffi <goffi@goffi.org>
parents:
2160
diff
changeset
|
143 self._comments_items_list.append(items) |
cf6c539672c7
tools (common/data_objects): comments items can now be chained to their parent
Goffi <goffi@goffi.org>
parents:
2160
diff
changeset
|
144 |
2160
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
145 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
146 class BlogItems(object): |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
147 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
148 def __init__(self, mb_data): |
2476
6607bb29ab7b
tools (common/data_objects): BlogItem has now a uri property to generate its own XMPP URI
Goffi <goffi@goffi.org>
parents:
2469
diff
changeset
|
149 self.items = [BlogItem(i, self) for i in mb_data[0]] |
2160
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
150 self.metadata = mb_data[1] |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
151 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
152 @property |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
153 def service(self): |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
154 return self.metadata[u'service'] |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
155 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
156 @property |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
157 def node(self): |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
158 return self.metadata[u'node'] |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
159 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
160 @property |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
161 def uri(self): |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
162 return self.metadata[u'uri'] |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
163 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
164 def __len__(self): |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
165 return self.items.__len__() |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
166 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
167 def __missing__(self, key): |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
168 return self.items.__missing__(key) |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
169 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
170 def __getitem__(self, key): |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
171 return self.items.__getitem__(key) |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
172 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
173 def __iter__(self): |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
174 return self.items.__iter__() |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
175 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
176 def __reversed__(self): |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
177 return self.items.__reversed__() |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
178 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
179 def __contains__(self, item): |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
180 return self.items.__contains__(item) |
2257
0ffa8ba0857c
core (tools/common/data_objects): added classes to handle Identities
Goffi <goffi@goffi.org>
parents:
2228
diff
changeset
|
181 |
0ffa8ba0857c
core (tools/common/data_objects): added classes to handle Identities
Goffi <goffi@goffi.org>
parents:
2228
diff
changeset
|
182 |
2464
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
183 class Message(object): |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
184 |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
185 def __init__(self, msg_data): |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
186 self._uid = msg_data[0] |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
187 self._timestamp = msg_data[1] |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
188 self._from_jid = msg_data[2] |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
189 self._to_jid = msg_data[3] |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
190 self._message_data = msg_data[4] |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
191 self._subject_data = msg_data[5] |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
192 self._type = msg_data[6] |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
193 self._extra = msg_data[7] |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
194 self._html = dict(data_format.getSubDict('xhtml', self._extra)) |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
195 |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
196 @property |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
197 def id(self): |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
198 return self._uid |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
199 |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
200 @property |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
201 def timestamp(self): |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
202 return self._timestamp |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
203 |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
204 @property |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
205 def from_(self): |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
206 return self._from_jid |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
207 |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
208 @property |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
209 def text(self): |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
210 try: |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
211 return self._message_data[''] |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
212 except KeyError: |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
213 return next(self._message_data.itervalues()) |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
214 |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
215 @property |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
216 def subject(self): |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
217 try: |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
218 return self._subject_data[''] |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
219 except KeyError: |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
220 return next(self._subject_data.itervalues()) |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
221 |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
222 @property |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
223 def type(self): |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
224 return self._type |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
225 |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
226 @property |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
227 def thread(self): |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
228 return self._extra.get('thread') |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
229 |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
230 @property |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
231 def thread_parent(self): |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
232 return self._extra.get('thread_parent') |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
233 |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
234 @property |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
235 def received(self): |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
236 return self._extra.get('received_timestamp', self._timestamp) |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
237 |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
238 @property |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
239 def delay_sender(self): |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
240 return self._extra.get('delay_sender') |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
241 |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
242 @property |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
243 def info_type(self): |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
244 return self._extra.get('info_type') |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
245 |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
246 @property |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
247 def html(self): |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
248 if not self._html: |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
249 return None |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
250 try: |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
251 return safe(self._html['']) |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
252 except KeyError: |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
253 return safe(next(self._html.itervalues())) |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
254 |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
255 |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
256 class Messages(object): |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
257 |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
258 def __init__(self, msgs_data): |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
259 self.messages = [Message(m) for m in msgs_data] |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
260 |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
261 def __len__(self): |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
262 return self.messages.__len__() |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
263 |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
264 def __missing__(self, key): |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
265 return self.messages.__missing__(key) |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
266 |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
267 def __getitem__(self, key): |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
268 return self.messages.__getitem__(key) |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
269 |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
270 def __iter__(self): |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
271 return self.messages.__iter__() |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
272 |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
273 def __reversed__(self): |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
274 return self.messages.__reversed__() |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
275 |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
276 def __contains__(self, item): |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
277 return self.messages.__contains__(item) |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
278 |
2469
adcc35625e17
tools (common/data_objects): added Room class
Goffi <goffi@goffi.org>
parents:
2464
diff
changeset
|
279 class Room(object): |
adcc35625e17
tools (common/data_objects): added Room class
Goffi <goffi@goffi.org>
parents:
2464
diff
changeset
|
280 |
adcc35625e17
tools (common/data_objects): added Room class
Goffi <goffi@goffi.org>
parents:
2464
diff
changeset
|
281 def __init__(self, jid, name=None, url=None): |
adcc35625e17
tools (common/data_objects): added Room class
Goffi <goffi@goffi.org>
parents:
2464
diff
changeset
|
282 self.jid = jid |
adcc35625e17
tools (common/data_objects): added Room class
Goffi <goffi@goffi.org>
parents:
2464
diff
changeset
|
283 self.name = name or jid |
adcc35625e17
tools (common/data_objects): added Room class
Goffi <goffi@goffi.org>
parents:
2464
diff
changeset
|
284 if url is not None: |
adcc35625e17
tools (common/data_objects): added Room class
Goffi <goffi@goffi.org>
parents:
2464
diff
changeset
|
285 self.url = url |
adcc35625e17
tools (common/data_objects): added Room class
Goffi <goffi@goffi.org>
parents:
2464
diff
changeset
|
286 |
2464
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
287 |
2257
0ffa8ba0857c
core (tools/common/data_objects): added classes to handle Identities
Goffi <goffi@goffi.org>
parents:
2228
diff
changeset
|
288 class Identity(object): |
0ffa8ba0857c
core (tools/common/data_objects): added classes to handle Identities
Goffi <goffi@goffi.org>
parents:
2228
diff
changeset
|
289 |
0ffa8ba0857c
core (tools/common/data_objects): added classes to handle Identities
Goffi <goffi@goffi.org>
parents:
2228
diff
changeset
|
290 def __init__(self, jid_str, data=None): |
0ffa8ba0857c
core (tools/common/data_objects): added classes to handle Identities
Goffi <goffi@goffi.org>
parents:
2228
diff
changeset
|
291 self.jid_str = jid_str |
0ffa8ba0857c
core (tools/common/data_objects): added classes to handle Identities
Goffi <goffi@goffi.org>
parents:
2228
diff
changeset
|
292 self.data = data if data is not None else {} |
0ffa8ba0857c
core (tools/common/data_objects): added classes to handle Identities
Goffi <goffi@goffi.org>
parents:
2228
diff
changeset
|
293 |
0ffa8ba0857c
core (tools/common/data_objects): added classes to handle Identities
Goffi <goffi@goffi.org>
parents:
2228
diff
changeset
|
294 @property |
0ffa8ba0857c
core (tools/common/data_objects): added classes to handle Identities
Goffi <goffi@goffi.org>
parents:
2228
diff
changeset
|
295 def nick(self): |
0ffa8ba0857c
core (tools/common/data_objects): added classes to handle Identities
Goffi <goffi@goffi.org>
parents:
2228
diff
changeset
|
296 return self.data.get(u'nick') |
0ffa8ba0857c
core (tools/common/data_objects): added classes to handle Identities
Goffi <goffi@goffi.org>
parents:
2228
diff
changeset
|
297 |
0ffa8ba0857c
core (tools/common/data_objects): added classes to handle Identities
Goffi <goffi@goffi.org>
parents:
2228
diff
changeset
|
298 |
0ffa8ba0857c
core (tools/common/data_objects): added classes to handle Identities
Goffi <goffi@goffi.org>
parents:
2228
diff
changeset
|
299 class Identities(object): |
0ffa8ba0857c
core (tools/common/data_objects): added classes to handle Identities
Goffi <goffi@goffi.org>
parents:
2228
diff
changeset
|
300 |
0ffa8ba0857c
core (tools/common/data_objects): added classes to handle Identities
Goffi <goffi@goffi.org>
parents:
2228
diff
changeset
|
301 def __init__(self): |
0ffa8ba0857c
core (tools/common/data_objects): added classes to handle Identities
Goffi <goffi@goffi.org>
parents:
2228
diff
changeset
|
302 self.identities = {} |
0ffa8ba0857c
core (tools/common/data_objects): added classes to handle Identities
Goffi <goffi@goffi.org>
parents:
2228
diff
changeset
|
303 |
0ffa8ba0857c
core (tools/common/data_objects): added classes to handle Identities
Goffi <goffi@goffi.org>
parents:
2228
diff
changeset
|
304 def __getitem__(self, jid_str): |
0ffa8ba0857c
core (tools/common/data_objects): added classes to handle Identities
Goffi <goffi@goffi.org>
parents:
2228
diff
changeset
|
305 try: |
0ffa8ba0857c
core (tools/common/data_objects): added classes to handle Identities
Goffi <goffi@goffi.org>
parents:
2228
diff
changeset
|
306 return self.identities[jid_str] |
0ffa8ba0857c
core (tools/common/data_objects): added classes to handle Identities
Goffi <goffi@goffi.org>
parents:
2228
diff
changeset
|
307 except KeyError: |
0ffa8ba0857c
core (tools/common/data_objects): added classes to handle Identities
Goffi <goffi@goffi.org>
parents:
2228
diff
changeset
|
308 return None |
0ffa8ba0857c
core (tools/common/data_objects): added classes to handle Identities
Goffi <goffi@goffi.org>
parents:
2228
diff
changeset
|
309 |
0ffa8ba0857c
core (tools/common/data_objects): added classes to handle Identities
Goffi <goffi@goffi.org>
parents:
2228
diff
changeset
|
310 def __setitem__(self, jid_str, data): |
0ffa8ba0857c
core (tools/common/data_objects): added classes to handle Identities
Goffi <goffi@goffi.org>
parents:
2228
diff
changeset
|
311 self.identities[jid_str] = Identity(jid_str, data) |
0ffa8ba0857c
core (tools/common/data_objects): added classes to handle Identities
Goffi <goffi@goffi.org>
parents:
2228
diff
changeset
|
312 |
0ffa8ba0857c
core (tools/common/data_objects): added classes to handle Identities
Goffi <goffi@goffi.org>
parents:
2228
diff
changeset
|
313 def __contains__(self, jid_str): |
0ffa8ba0857c
core (tools/common/data_objects): added classes to handle Identities
Goffi <goffi@goffi.org>
parents:
2228
diff
changeset
|
314 return jid_str in self.identities |
2383
a37457da2bb7
tools (common/data_objects): new OnClick class
Goffi <goffi@goffi.org>
parents:
2300
diff
changeset
|
315 |
a37457da2bb7
tools (common/data_objects): new OnClick class
Goffi <goffi@goffi.org>
parents:
2300
diff
changeset
|
316 |
a37457da2bb7
tools (common/data_objects): new OnClick class
Goffi <goffi@goffi.org>
parents:
2300
diff
changeset
|
317 class OnClick(object): |
a37457da2bb7
tools (common/data_objects): new OnClick class
Goffi <goffi@goffi.org>
parents:
2300
diff
changeset
|
318 """Class to handle clickable elements targets""" |
a37457da2bb7
tools (common/data_objects): new OnClick class
Goffi <goffi@goffi.org>
parents:
2300
diff
changeset
|
319 |
a37457da2bb7
tools (common/data_objects): new OnClick class
Goffi <goffi@goffi.org>
parents:
2300
diff
changeset
|
320 def __init__(self, url=None): |
a37457da2bb7
tools (common/data_objects): new OnClick class
Goffi <goffi@goffi.org>
parents:
2300
diff
changeset
|
321 self.url = url |
a37457da2bb7
tools (common/data_objects): new OnClick class
Goffi <goffi@goffi.org>
parents:
2300
diff
changeset
|
322 |
a37457da2bb7
tools (common/data_objects): new OnClick class
Goffi <goffi@goffi.org>
parents:
2300
diff
changeset
|
323 def formatUrl(self, item): |
a37457da2bb7
tools (common/data_objects): new OnClick class
Goffi <goffi@goffi.org>
parents:
2300
diff
changeset
|
324 """Use an item to format URL |
a37457da2bb7
tools (common/data_objects): new OnClick class
Goffi <goffi@goffi.org>
parents:
2300
diff
changeset
|
325 |
a37457da2bb7
tools (common/data_objects): new OnClick class
Goffi <goffi@goffi.org>
parents:
2300
diff
changeset
|
326 item will be formatted using "item=item" in format() |
a37457da2bb7
tools (common/data_objects): new OnClick class
Goffi <goffi@goffi.org>
parents:
2300
diff
changeset
|
327 """ |
a37457da2bb7
tools (common/data_objects): new OnClick class
Goffi <goffi@goffi.org>
parents:
2300
diff
changeset
|
328 return self.url.format(item=item) |