Mercurial > libervia-backend
annotate sat/tools/common/data_objects.py @ 3274:430204a3cc10
tools (common/template): new `icon_from_client` method:
this method is available from template, and returns the name of the icon to use according
to disco client data.
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 18 May 2020 23:41:36 +0200 |
parents | 9896589487ae |
children | 9f0e28137cd0 |
rev | line source |
---|---|
3028 | 1 #!/usr/bin/env python3 |
3137 | 2 |
2160
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 |
3136 | 5 # Copyright (C) 2009-2020 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 |
2766
93a421de0e3d
tools (common/data_objects): metadata parsing in BlogItems:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
22 from sat.core.constants import Const as C |
2160
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 from sat.tools.common import data_format |
3261
a9e8e925ad99
tools (common/data_objects): new `avatar_basename` property
Goffi <goffi@goffi.org>
parents:
3170
diff
changeset
|
24 from os.path import basename |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
25 |
2160
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 try: |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 from jinja2 import Markup as safe |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 except ImportError: |
3028 | 29 safe = str |
2160
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 |
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
|
31 from sat.tools.common import uri as xmpp_uri |
3028 | 32 import urllib.request, urllib.parse, urllib.error |
2482
ac6097a66944
tools (common/data_objects): accept same parameters as format en quote their values in OnClick.formatUrl
Goffi <goffi@goffi.org>
parents:
2478
diff
changeset
|
33 |
3028 | 34 q = lambda value: urllib.parse.quote(value.encode("utf-8"), safe="@") |
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 |
2160
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 |
2770
2d353b74010e
tools (common/data_objects): moved BlogItems._parseMetadata to a parsePubSubMetadata function, so it can be used in a more generic way
Goffi <goffi@goffi.org>
parents:
2766
diff
changeset
|
37 def parsePubSubMetadata(metadata, items): |
2d353b74010e
tools (common/data_objects): moved BlogItems._parseMetadata to a parsePubSubMetadata function, so it can be used in a more generic way
Goffi <goffi@goffi.org>
parents:
2766
diff
changeset
|
38 """Helper method to have nicer metadata while doing a PubSub request |
2d353b74010e
tools (common/data_objects): moved BlogItems._parseMetadata to a parsePubSubMetadata function, so it can be used in a more generic way
Goffi <goffi@goffi.org>
parents:
2766
diff
changeset
|
39 |
2d353b74010e
tools (common/data_objects): moved BlogItems._parseMetadata to a parsePubSubMetadata function, so it can be used in a more generic way
Goffi <goffi@goffi.org>
parents:
2766
diff
changeset
|
40 The "rsm_index" and "rsm_count" keys will be converted to int |
2d353b74010e
tools (common/data_objects): moved BlogItems._parseMetadata to a parsePubSubMetadata function, so it can be used in a more generic way
Goffi <goffi@goffi.org>
parents:
2766
diff
changeset
|
41 The "mam_stable" and "mam_complete" keys will be converted to boolean |
2d353b74010e
tools (common/data_objects): moved BlogItems._parseMetadata to a parsePubSubMetadata function, so it can be used in a more generic way
Goffi <goffi@goffi.org>
parents:
2766
diff
changeset
|
42 A "complete" key can have the following values: |
2d353b74010e
tools (common/data_objects): moved BlogItems._parseMetadata to a parsePubSubMetadata function, so it can be used in a more generic way
Goffi <goffi@goffi.org>
parents:
2766
diff
changeset
|
43 - True: we are on the last page, i.e. last items have been received |
2d353b74010e
tools (common/data_objects): moved BlogItems._parseMetadata to a parsePubSubMetadata function, so it can be used in a more generic way
Goffi <goffi@goffi.org>
parents:
2766
diff
changeset
|
44 - False: we are not on the last page |
2d353b74010e
tools (common/data_objects): moved BlogItems._parseMetadata to a parsePubSubMetadata function, so it can be used in a more generic way
Goffi <goffi@goffi.org>
parents:
2766
diff
changeset
|
45 - None: we don't have enough data fo know our position in the pagination |
2d353b74010e
tools (common/data_objects): moved BlogItems._parseMetadata to a parsePubSubMetadata function, so it can be used in a more generic way
Goffi <goffi@goffi.org>
parents:
2766
diff
changeset
|
46 @param metadata(dict): dict retrieved fro bridge with request metadata |
2d353b74010e
tools (common/data_objects): moved BlogItems._parseMetadata to a parsePubSubMetadata function, so it can be used in a more generic way
Goffi <goffi@goffi.org>
parents:
2766
diff
changeset
|
47 @param items(list): items retrieved (used to determine "complete" value) |
2d353b74010e
tools (common/data_objects): moved BlogItems._parseMetadata to a parsePubSubMetadata function, so it can be used in a more generic way
Goffi <goffi@goffi.org>
parents:
2766
diff
changeset
|
48 @return (dict): parsed metadata |
2d353b74010e
tools (common/data_objects): moved BlogItems._parseMetadata to a parsePubSubMetadata function, so it can be used in a more generic way
Goffi <goffi@goffi.org>
parents:
2766
diff
changeset
|
49 """ |
2d353b74010e
tools (common/data_objects): moved BlogItems._parseMetadata to a parsePubSubMetadata function, so it can be used in a more generic way
Goffi <goffi@goffi.org>
parents:
2766
diff
changeset
|
50 data = {} |
2d353b74010e
tools (common/data_objects): moved BlogItems._parseMetadata to a parsePubSubMetadata function, so it can be used in a more generic way
Goffi <goffi@goffi.org>
parents:
2766
diff
changeset
|
51 assert "complete" not in metadata |
2d353b74010e
tools (common/data_objects): moved BlogItems._parseMetadata to a parsePubSubMetadata function, so it can be used in a more generic way
Goffi <goffi@goffi.org>
parents:
2766
diff
changeset
|
52 |
3028 | 53 for key, value in metadata.items(): |
54 if key in ("rsm_index", "rsm_count"): | |
2770
2d353b74010e
tools (common/data_objects): moved BlogItems._parseMetadata to a parsePubSubMetadata function, so it can be used in a more generic way
Goffi <goffi@goffi.org>
parents:
2766
diff
changeset
|
55 value = int(value) |
3028 | 56 elif key == "mam_stable": |
2770
2d353b74010e
tools (common/data_objects): moved BlogItems._parseMetadata to a parsePubSubMetadata function, so it can be used in a more generic way
Goffi <goffi@goffi.org>
parents:
2766
diff
changeset
|
57 value = C.bool(value) |
3028 | 58 elif key == "mam_complete": |
59 key = "complete" | |
2770
2d353b74010e
tools (common/data_objects): moved BlogItems._parseMetadata to a parsePubSubMetadata function, so it can be used in a more generic way
Goffi <goffi@goffi.org>
parents:
2766
diff
changeset
|
60 value = C.bool(value) |
2d353b74010e
tools (common/data_objects): moved BlogItems._parseMetadata to a parsePubSubMetadata function, so it can be used in a more generic way
Goffi <goffi@goffi.org>
parents:
2766
diff
changeset
|
61 data[key] = value |
3028 | 62 if "complete" not in data: |
63 index = data.get("rsm_index") | |
64 count = data.get("rsm_count") | |
2770
2d353b74010e
tools (common/data_objects): moved BlogItems._parseMetadata to a parsePubSubMetadata function, so it can be used in a more generic way
Goffi <goffi@goffi.org>
parents:
2766
diff
changeset
|
65 if index is None or count is None: |
2d353b74010e
tools (common/data_objects): moved BlogItems._parseMetadata to a parsePubSubMetadata function, so it can be used in a more generic way
Goffi <goffi@goffi.org>
parents:
2766
diff
changeset
|
66 # we don't have enough information to know if the data is complete or not |
3028 | 67 data["complete"] = None |
2770
2d353b74010e
tools (common/data_objects): moved BlogItems._parseMetadata to a parsePubSubMetadata function, so it can be used in a more generic way
Goffi <goffi@goffi.org>
parents:
2766
diff
changeset
|
68 else: |
2d353b74010e
tools (common/data_objects): moved BlogItems._parseMetadata to a parsePubSubMetadata function, so it can be used in a more generic way
Goffi <goffi@goffi.org>
parents:
2766
diff
changeset
|
69 # normally we have a strict equality here but XEP-0059 states |
2d353b74010e
tools (common/data_objects): moved BlogItems._parseMetadata to a parsePubSubMetadata function, so it can be used in a more generic way
Goffi <goffi@goffi.org>
parents:
2766
diff
changeset
|
70 # that index MAY be approximative, so just in case… |
3028 | 71 data["complete"] = index + len(items) >= count |
2770
2d353b74010e
tools (common/data_objects): moved BlogItems._parseMetadata to a parsePubSubMetadata function, so it can be used in a more generic way
Goffi <goffi@goffi.org>
parents:
2766
diff
changeset
|
72 return data |
2d353b74010e
tools (common/data_objects): moved BlogItems._parseMetadata to a parsePubSubMetadata function, so it can be used in a more generic way
Goffi <goffi@goffi.org>
parents:
2766
diff
changeset
|
73 |
2d353b74010e
tools (common/data_objects): moved BlogItems._parseMetadata to a parsePubSubMetadata function, so it can be used in a more generic way
Goffi <goffi@goffi.org>
parents:
2766
diff
changeset
|
74 |
2160
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 class BlogItem(object): |
2942
8dbef2d190eb
tools (common/data_objects): added a "deserialise" argument to BlogItem:
Goffi <goffi@goffi.org>
parents:
2807
diff
changeset
|
76 def __init__(self, mb_data, parent, deserialise=True): |
8dbef2d190eb
tools (common/data_objects): added a "deserialise" argument to BlogItem:
Goffi <goffi@goffi.org>
parents:
2807
diff
changeset
|
77 """ |
8dbef2d190eb
tools (common/data_objects): added a "deserialise" argument to BlogItem:
Goffi <goffi@goffi.org>
parents:
2807
diff
changeset
|
78 @param deserialise(bool): if True, mb_data is a serialised string which must |
8dbef2d190eb
tools (common/data_objects): added a "deserialise" argument to BlogItem:
Goffi <goffi@goffi.org>
parents:
2807
diff
changeset
|
79 be deserialised |
8dbef2d190eb
tools (common/data_objects): added a "deserialise" argument to BlogItem:
Goffi <goffi@goffi.org>
parents:
2807
diff
changeset
|
80 """ |
8dbef2d190eb
tools (common/data_objects): added a "deserialise" argument to BlogItem:
Goffi <goffi@goffi.org>
parents:
2807
diff
changeset
|
81 # FIXME: deserialise should not be done here, but before BlogItem is called |
8dbef2d190eb
tools (common/data_objects): added a "deserialise" argument to BlogItem:
Goffi <goffi@goffi.org>
parents:
2807
diff
changeset
|
82 if deserialise: |
8dbef2d190eb
tools (common/data_objects): added a "deserialise" argument to BlogItem:
Goffi <goffi@goffi.org>
parents:
2807
diff
changeset
|
83 self.mb_data = data_format.deserialise(mb_data) |
8dbef2d190eb
tools (common/data_objects): added a "deserialise" argument to BlogItem:
Goffi <goffi@goffi.org>
parents:
2807
diff
changeset
|
84 else: |
8dbef2d190eb
tools (common/data_objects): added a "deserialise" argument to BlogItem:
Goffi <goffi@goffi.org>
parents:
2807
diff
changeset
|
85 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
|
86 self.parent = parent |
2160
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 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
|
88 self._comments_items_list = None |
2160
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
89 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 @property |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
91 def id(self): |
3028 | 92 return self.mb_data.get("id") |
2160
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
94 @property |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
95 def atom_id(self): |
3028 | 96 return self.mb_data.get("atom_id") |
2160
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
98 @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
|
99 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
|
100 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
|
101 service = self.parent.service |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
102 return xmpp_uri.buildXMPPUri( |
3028 | 103 "pubsub", subtype="microblog", path=service, node=node, item=self.id |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
104 ) |
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
|
105 |
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
|
106 @property |
2160
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
107 def published(self): |
3028 | 108 return self.mb_data.get("published") |
2160
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 updated(self): |
3028 | 112 return self.mb_data.get("updated") |
2160
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 |
2264
a8eaaac4d80f
plugin XEP-0277, tools/common/data_objects: language handling
Goffi <goffi@goffi.org>
parents:
2257
diff
changeset
|
115 def language(self): |
3028 | 116 return self.mb_data.get("language") |
2264
a8eaaac4d80f
plugin XEP-0277, tools/common/data_objects: language handling
Goffi <goffi@goffi.org>
parents:
2257
diff
changeset
|
117 |
a8eaaac4d80f
plugin XEP-0277, tools/common/data_objects: language handling
Goffi <goffi@goffi.org>
parents:
2257
diff
changeset
|
118 @property |
2160
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 def author(self): |
3028 | 120 return self.mb_data.get("author") |
2160
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
122 @property |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
123 def author_jid(self): |
3028 | 124 return self.mb_data.get("author_jid") |
2160
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
125 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
126 @property |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
127 def author_jid_verified(self): |
3028 | 128 return self.mb_data.get("author_jid_verified") |
2160
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
130 @property |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
131 def author_email(self): |
3028 | 132 return self.mb_data.get("author_email") |
2160
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
133 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
134 @property |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
135 def tags(self): |
3028 | 136 return self.mb_data.get('tags', []) |
2160
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
137 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
138 @property |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
139 def groups(self): |
3028 | 140 return self.mb_data.get('groups', []) |
2160
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
141 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
142 @property |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
143 def title(self): |
3028 | 144 return self.mb_data.get("title") |
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 @property |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
147 def title_xhtml(self): |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
148 try: |
3028 | 149 return safe(self.mb_data["title_xhtml"]) |
2160
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
150 except KeyError: |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
151 return None |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
152 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
153 @property |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
154 def content(self): |
3028 | 155 return self.mb_data.get("content") |
2160
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
156 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
157 @property |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
158 def content_xhtml(self): |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
159 try: |
3028 | 160 return safe(self.mb_data["content_xhtml"]) |
2160
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
161 except KeyError: |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
162 return None |
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 @property |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
165 def comments(self): |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
166 if self._comments is None: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
167 self._comments = data_format.dict2iterdict( |
3028 | 168 "comments", self.mb_data, ("node", "service") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
169 ) |
2160
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
170 return self._comments |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
171 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
172 @property |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
173 def comments_service(self): |
3028 | 174 return self.mb_data.get("comments_service") |
2160
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 @property |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
177 def comments_node(self): |
3028 | 178 return self.mb_data.get("comments_node") |
2160
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
179 |
2228
cf6c539672c7
tools (common/data_objects): comments items can now be chained to their parent
Goffi <goffi@goffi.org>
parents:
2160
diff
changeset
|
180 @property |
cf6c539672c7
tools (common/data_objects): comments items can now be chained to their parent
Goffi <goffi@goffi.org>
parents:
2160
diff
changeset
|
181 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
|
182 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
|
183 |
cf6c539672c7
tools (common/data_objects): comments items can now be chained to their parent
Goffi <goffi@goffi.org>
parents:
2160
diff
changeset
|
184 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
|
185 """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
|
186 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
|
187 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
|
188 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
|
189 |
2160
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
190 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
191 class BlogItems(object): |
2942
8dbef2d190eb
tools (common/data_objects): added a "deserialise" argument to BlogItem:
Goffi <goffi@goffi.org>
parents:
2807
diff
changeset
|
192 def __init__(self, mb_data, deserialise=True): |
8dbef2d190eb
tools (common/data_objects): added a "deserialise" argument to BlogItem:
Goffi <goffi@goffi.org>
parents:
2807
diff
changeset
|
193 """ |
8dbef2d190eb
tools (common/data_objects): added a "deserialise" argument to BlogItem:
Goffi <goffi@goffi.org>
parents:
2807
diff
changeset
|
194 @param deserialise(bool): if True, mb_data is a serialised string which must |
8dbef2d190eb
tools (common/data_objects): added a "deserialise" argument to BlogItem:
Goffi <goffi@goffi.org>
parents:
2807
diff
changeset
|
195 be deserialised |
8dbef2d190eb
tools (common/data_objects): added a "deserialise" argument to BlogItem:
Goffi <goffi@goffi.org>
parents:
2807
diff
changeset
|
196 """ |
8dbef2d190eb
tools (common/data_objects): added a "deserialise" argument to BlogItem:
Goffi <goffi@goffi.org>
parents:
2807
diff
changeset
|
197 # FIXME: deserialise should not be done here, but before BlogItem is called |
8dbef2d190eb
tools (common/data_objects): added a "deserialise" argument to BlogItem:
Goffi <goffi@goffi.org>
parents:
2807
diff
changeset
|
198 self.items = [BlogItem(i, self, deserialise=deserialise) for i in mb_data[0]] |
2770
2d353b74010e
tools (common/data_objects): moved BlogItems._parseMetadata to a parsePubSubMetadata function, so it can be used in a more generic way
Goffi <goffi@goffi.org>
parents:
2766
diff
changeset
|
199 self.metadata = parsePubSubMetadata(mb_data[1], self.items) |
2160
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
200 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
201 @property |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
202 def service(self): |
3028 | 203 return self.metadata["service"] |
2160
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
204 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
205 @property |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
206 def node(self): |
3028 | 207 return self.metadata["node"] |
2160
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
208 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
209 @property |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
210 def uri(self): |
3028 | 211 return self.metadata["uri"] |
2160
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
212 |
2766
93a421de0e3d
tools (common/data_objects): metadata parsing in BlogItems:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
213 @property |
93a421de0e3d
tools (common/data_objects): metadata parsing in BlogItems:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
214 def with_rsm(self): |
93a421de0e3d
tools (common/data_objects): metadata parsing in BlogItems:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
215 """Return True if RSM is activated on this request""" |
3028 | 216 return "rsm_first" in self.metadata |
2766
93a421de0e3d
tools (common/data_objects): metadata parsing in BlogItems:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
217 |
93a421de0e3d
tools (common/data_objects): metadata parsing in BlogItems:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
218 @property |
93a421de0e3d
tools (common/data_objects): metadata parsing in BlogItems:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
219 def rsm_first(self): |
3028 | 220 return self.metadata["rsm_first"] |
2766
93a421de0e3d
tools (common/data_objects): metadata parsing in BlogItems:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
221 |
93a421de0e3d
tools (common/data_objects): metadata parsing in BlogItems:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
222 @property |
93a421de0e3d
tools (common/data_objects): metadata parsing in BlogItems:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
223 def rsm_last(self): |
3028 | 224 return self.metadata["rsm_last"] |
2766
93a421de0e3d
tools (common/data_objects): metadata parsing in BlogItems:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
225 |
93a421de0e3d
tools (common/data_objects): metadata parsing in BlogItems:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
226 @property |
93a421de0e3d
tools (common/data_objects): metadata parsing in BlogItems:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
227 def rsm_index(self): |
3028 | 228 return self.metadata["rsm_index"] |
2766
93a421de0e3d
tools (common/data_objects): metadata parsing in BlogItems:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
229 |
93a421de0e3d
tools (common/data_objects): metadata parsing in BlogItems:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
230 @property |
93a421de0e3d
tools (common/data_objects): metadata parsing in BlogItems:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
231 def rsm_count(self): |
3028 | 232 return self.metadata["rsm_count"] |
2766
93a421de0e3d
tools (common/data_objects): metadata parsing in BlogItems:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
233 |
93a421de0e3d
tools (common/data_objects): metadata parsing in BlogItems:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
234 @property |
93a421de0e3d
tools (common/data_objects): metadata parsing in BlogItems:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
235 def complete(self): |
3028 | 236 return self.metadata["complete"] |
2766
93a421de0e3d
tools (common/data_objects): metadata parsing in BlogItems:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
237 |
2160
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
238 def __len__(self): |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
239 return self.items.__len__() |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
240 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
241 def __missing__(self, key): |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
242 return self.items.__missing__(key) |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
243 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
244 def __getitem__(self, key): |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
245 return self.items.__getitem__(key) |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
246 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
247 def __iter__(self): |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
248 return self.items.__iter__() |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
249 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
250 def __reversed__(self): |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
251 return self.items.__reversed__() |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
252 |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
253 def __contains__(self, item): |
e67e8cd24141
core (tools/common): data objects first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
254 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
|
255 |
0ffa8ba0857c
core (tools/common/data_objects): added classes to handle Identities
Goffi <goffi@goffi.org>
parents:
2228
diff
changeset
|
256 |
2464
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
257 class Message(object): |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
258 def __init__(self, msg_data): |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
259 self._uid = msg_data[0] |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
260 self._timestamp = msg_data[1] |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
261 self._from_jid = msg_data[2] |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
262 self._to_jid = msg_data[3] |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
263 self._message_data = msg_data[4] |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
264 self._subject_data = msg_data[5] |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
265 self._type = msg_data[6] |
3170
39d7327583e1
core: use serialised dict for `extra` in messageNew and historyGet
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
266 self._extra = data_format.deserialise(msg_data[7]) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
267 self._html = dict(data_format.getSubDict("xhtml", self._extra)) |
2464
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
268 |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
269 @property |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
270 def id(self): |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
271 return self._uid |
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 @property |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
274 def timestamp(self): |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
275 return self._timestamp |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
276 |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
277 @property |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
278 def from_(self): |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
279 return self._from_jid |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
280 |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
281 @property |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
282 def text(self): |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
283 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
284 return self._message_data[""] |
2464
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
285 except KeyError: |
3028 | 286 return next(iter(self._message_data.values())) |
2464
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
287 |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
288 @property |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
289 def subject(self): |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
290 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
291 return self._subject_data[""] |
2464
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
292 except KeyError: |
3028 | 293 return next(iter(self._subject_data.values())) |
2464
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
294 |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
295 @property |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
296 def type(self): |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
297 return self._type |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
298 |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
299 @property |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
300 def thread(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
301 return self._extra.get("thread") |
2464
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
302 |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
303 @property |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
304 def thread_parent(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
305 return self._extra.get("thread_parent") |
2464
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
306 |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
307 @property |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
308 def received(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
309 return self._extra.get("received_timestamp", self._timestamp) |
2464
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
310 |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
311 @property |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
312 def delay_sender(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
313 return self._extra.get("delay_sender") |
2464
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
314 |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
315 @property |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
316 def info_type(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
317 return self._extra.get("info_type") |
2464
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
318 |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
319 @property |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
320 def html(self): |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
321 if not self._html: |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
322 return None |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
323 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
324 return safe(self._html[""]) |
2464
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
325 except KeyError: |
3028 | 326 return safe(next(iter(self._html.values()))) |
2464
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
327 |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
328 |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
329 class Messages(object): |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
330 def __init__(self, msgs_data): |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
331 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
|
332 |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
333 def __len__(self): |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
334 return self.messages.__len__() |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
335 |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
336 def __missing__(self, key): |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
337 return self.messages.__missing__(key) |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
338 |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
339 def __getitem__(self, key): |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
340 return self.messages.__getitem__(key) |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
341 |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
342 def __iter__(self): |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
343 return self.messages.__iter__() |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
344 |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
345 def __reversed__(self): |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
346 return self.messages.__reversed__() |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
347 |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
348 def __contains__(self, item): |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
349 return self.messages.__contains__(item) |
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
350 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
351 |
2469
adcc35625e17
tools (common/data_objects): added Room class
Goffi <goffi@goffi.org>
parents:
2464
diff
changeset
|
352 class Room(object): |
adcc35625e17
tools (common/data_objects): added Room class
Goffi <goffi@goffi.org>
parents:
2464
diff
changeset
|
353 def __init__(self, jid, name=None, url=None): |
adcc35625e17
tools (common/data_objects): added Room class
Goffi <goffi@goffi.org>
parents:
2464
diff
changeset
|
354 self.jid = jid |
adcc35625e17
tools (common/data_objects): added Room class
Goffi <goffi@goffi.org>
parents:
2464
diff
changeset
|
355 self.name = name or jid |
adcc35625e17
tools (common/data_objects): added Room class
Goffi <goffi@goffi.org>
parents:
2464
diff
changeset
|
356 if url is not None: |
adcc35625e17
tools (common/data_objects): added Room class
Goffi <goffi@goffi.org>
parents:
2464
diff
changeset
|
357 self.url = url |
adcc35625e17
tools (common/data_objects): added Room class
Goffi <goffi@goffi.org>
parents:
2464
diff
changeset
|
358 |
2464
8788c217a49e
tools (common/data_objects): added classes for messages
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
359 |
2257
0ffa8ba0857c
core (tools/common/data_objects): added classes to handle Identities
Goffi <goffi@goffi.org>
parents:
2228
diff
changeset
|
360 class Identity(object): |
0ffa8ba0857c
core (tools/common/data_objects): added classes to handle Identities
Goffi <goffi@goffi.org>
parents:
2228
diff
changeset
|
361 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
|
362 self.jid_str = jid_str |
0ffa8ba0857c
core (tools/common/data_objects): added classes to handle Identities
Goffi <goffi@goffi.org>
parents:
2228
diff
changeset
|
363 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
|
364 |
3261
a9e8e925ad99
tools (common/data_objects): new `avatar_basename` property
Goffi <goffi@goffi.org>
parents:
3170
diff
changeset
|
365 @property |
a9e8e925ad99
tools (common/data_objects): new `avatar_basename` property
Goffi <goffi@goffi.org>
parents:
3170
diff
changeset
|
366 def avatar_basename(self): |
a9e8e925ad99
tools (common/data_objects): new `avatar_basename` property
Goffi <goffi@goffi.org>
parents:
3170
diff
changeset
|
367 try: |
a9e8e925ad99
tools (common/data_objects): new `avatar_basename` property
Goffi <goffi@goffi.org>
parents:
3170
diff
changeset
|
368 return basename(self.data['avatar']['path']) |
a9e8e925ad99
tools (common/data_objects): new `avatar_basename` property
Goffi <goffi@goffi.org>
parents:
3170
diff
changeset
|
369 except (TypeError, KeyError): |
a9e8e925ad99
tools (common/data_objects): new `avatar_basename` property
Goffi <goffi@goffi.org>
parents:
3170
diff
changeset
|
370 return None |
a9e8e925ad99
tools (common/data_objects): new `avatar_basename` property
Goffi <goffi@goffi.org>
parents:
3170
diff
changeset
|
371 |
2537
8cf58a415126
tools (common/data_objects): fixed Identity
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
372 def __getitem__(self, key): |
8cf58a415126
tools (common/data_objects): fixed Identity
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
373 return self.data[key] |
8cf58a415126
tools (common/data_objects): fixed Identity
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
374 |
8cf58a415126
tools (common/data_objects): fixed Identity
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
375 def __getattr__(self, key): |
8cf58a415126
tools (common/data_objects): fixed Identity
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
376 try: |
8cf58a415126
tools (common/data_objects): fixed Identity
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
377 return self.data[key] |
8cf58a415126
tools (common/data_objects): fixed Identity
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
378 except KeyError: |
8cf58a415126
tools (common/data_objects): fixed Identity
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
379 raise AttributeError(key) |
2257
0ffa8ba0857c
core (tools/common/data_objects): added classes to handle Identities
Goffi <goffi@goffi.org>
parents:
2228
diff
changeset
|
380 |
0ffa8ba0857c
core (tools/common/data_objects): added classes to handle Identities
Goffi <goffi@goffi.org>
parents:
2228
diff
changeset
|
381 |
3264
9896589487ae
tools (common/data_objects): added __iter__ to Identities
Goffi <goffi@goffi.org>
parents:
3261
diff
changeset
|
382 class Identities: |
2257
0ffa8ba0857c
core (tools/common/data_objects): added classes to handle Identities
Goffi <goffi@goffi.org>
parents:
2228
diff
changeset
|
383 def __init__(self): |
0ffa8ba0857c
core (tools/common/data_objects): added classes to handle Identities
Goffi <goffi@goffi.org>
parents:
2228
diff
changeset
|
384 self.identities = {} |
0ffa8ba0857c
core (tools/common/data_objects): added classes to handle Identities
Goffi <goffi@goffi.org>
parents:
2228
diff
changeset
|
385 |
3264
9896589487ae
tools (common/data_objects): added __iter__ to Identities
Goffi <goffi@goffi.org>
parents:
3261
diff
changeset
|
386 def __iter__(self): |
9896589487ae
tools (common/data_objects): added __iter__ to Identities
Goffi <goffi@goffi.org>
parents:
3261
diff
changeset
|
387 return iter(self.identities) |
9896589487ae
tools (common/data_objects): added __iter__ to Identities
Goffi <goffi@goffi.org>
parents:
3261
diff
changeset
|
388 |
2257
0ffa8ba0857c
core (tools/common/data_objects): added classes to handle Identities
Goffi <goffi@goffi.org>
parents:
2228
diff
changeset
|
389 def __getitem__(self, jid_str): |
0ffa8ba0857c
core (tools/common/data_objects): added classes to handle Identities
Goffi <goffi@goffi.org>
parents:
2228
diff
changeset
|
390 try: |
0ffa8ba0857c
core (tools/common/data_objects): added classes to handle Identities
Goffi <goffi@goffi.org>
parents:
2228
diff
changeset
|
391 return self.identities[jid_str] |
0ffa8ba0857c
core (tools/common/data_objects): added classes to handle Identities
Goffi <goffi@goffi.org>
parents:
2228
diff
changeset
|
392 except KeyError: |
0ffa8ba0857c
core (tools/common/data_objects): added classes to handle Identities
Goffi <goffi@goffi.org>
parents:
2228
diff
changeset
|
393 return None |
0ffa8ba0857c
core (tools/common/data_objects): added classes to handle Identities
Goffi <goffi@goffi.org>
parents:
2228
diff
changeset
|
394 |
0ffa8ba0857c
core (tools/common/data_objects): added classes to handle Identities
Goffi <goffi@goffi.org>
parents:
2228
diff
changeset
|
395 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
|
396 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
|
397 |
0ffa8ba0857c
core (tools/common/data_objects): added classes to handle Identities
Goffi <goffi@goffi.org>
parents:
2228
diff
changeset
|
398 def __contains__(self, jid_str): |
0ffa8ba0857c
core (tools/common/data_objects): added classes to handle Identities
Goffi <goffi@goffi.org>
parents:
2228
diff
changeset
|
399 return jid_str in self.identities |
2383
a37457da2bb7
tools (common/data_objects): new OnClick class
Goffi <goffi@goffi.org>
parents:
2300
diff
changeset
|
400 |
a37457da2bb7
tools (common/data_objects): new OnClick class
Goffi <goffi@goffi.org>
parents:
2300
diff
changeset
|
401 |
2482
ac6097a66944
tools (common/data_objects): accept same parameters as format en quote their values in OnClick.formatUrl
Goffi <goffi@goffi.org>
parents:
2478
diff
changeset
|
402 class ObjectQuoter(object): |
ac6097a66944
tools (common/data_objects): accept same parameters as format en quote their values in OnClick.formatUrl
Goffi <goffi@goffi.org>
parents:
2478
diff
changeset
|
403 """object wrapper which quote attribues (to be used in templates)""" |
ac6097a66944
tools (common/data_objects): accept same parameters as format en quote their values in OnClick.formatUrl
Goffi <goffi@goffi.org>
parents:
2478
diff
changeset
|
404 |
ac6097a66944
tools (common/data_objects): accept same parameters as format en quote their values in OnClick.formatUrl
Goffi <goffi@goffi.org>
parents:
2478
diff
changeset
|
405 def __init__(self, obj): |
ac6097a66944
tools (common/data_objects): accept same parameters as format en quote their values in OnClick.formatUrl
Goffi <goffi@goffi.org>
parents:
2478
diff
changeset
|
406 self.obj = obj |
ac6097a66944
tools (common/data_objects): accept same parameters as format en quote their values in OnClick.formatUrl
Goffi <goffi@goffi.org>
parents:
2478
diff
changeset
|
407 |
ac6097a66944
tools (common/data_objects): accept same parameters as format en quote their values in OnClick.formatUrl
Goffi <goffi@goffi.org>
parents:
2478
diff
changeset
|
408 def __unicode__(self): |
ac6097a66944
tools (common/data_objects): accept same parameters as format en quote their values in OnClick.formatUrl
Goffi <goffi@goffi.org>
parents:
2478
diff
changeset
|
409 return q(self.obj.__unicode__()) |
ac6097a66944
tools (common/data_objects): accept same parameters as format en quote their values in OnClick.formatUrl
Goffi <goffi@goffi.org>
parents:
2478
diff
changeset
|
410 |
ac6097a66944
tools (common/data_objects): accept same parameters as format en quote their values in OnClick.formatUrl
Goffi <goffi@goffi.org>
parents:
2478
diff
changeset
|
411 def __str__(self): |
ac6097a66944
tools (common/data_objects): accept same parameters as format en quote their values in OnClick.formatUrl
Goffi <goffi@goffi.org>
parents:
2478
diff
changeset
|
412 return self.__unicode__() |
ac6097a66944
tools (common/data_objects): accept same parameters as format en quote their values in OnClick.formatUrl
Goffi <goffi@goffi.org>
parents:
2478
diff
changeset
|
413 |
ac6097a66944
tools (common/data_objects): accept same parameters as format en quote their values in OnClick.formatUrl
Goffi <goffi@goffi.org>
parents:
2478
diff
changeset
|
414 def __getattr__(self, name): |
ac6097a66944
tools (common/data_objects): accept same parameters as format en quote their values in OnClick.formatUrl
Goffi <goffi@goffi.org>
parents:
2478
diff
changeset
|
415 return q(self.obj.__getattr__(name)) |
ac6097a66944
tools (common/data_objects): accept same parameters as format en quote their values in OnClick.formatUrl
Goffi <goffi@goffi.org>
parents:
2478
diff
changeset
|
416 |
ac6097a66944
tools (common/data_objects): accept same parameters as format en quote their values in OnClick.formatUrl
Goffi <goffi@goffi.org>
parents:
2478
diff
changeset
|
417 def __getitem__(self, key): |
ac6097a66944
tools (common/data_objects): accept same parameters as format en quote their values in OnClick.formatUrl
Goffi <goffi@goffi.org>
parents:
2478
diff
changeset
|
418 return q(self.obj.__getitem__(key)) |
ac6097a66944
tools (common/data_objects): accept same parameters as format en quote their values in OnClick.formatUrl
Goffi <goffi@goffi.org>
parents:
2478
diff
changeset
|
419 |
ac6097a66944
tools (common/data_objects): accept same parameters as format en quote their values in OnClick.formatUrl
Goffi <goffi@goffi.org>
parents:
2478
diff
changeset
|
420 |
2383
a37457da2bb7
tools (common/data_objects): new OnClick class
Goffi <goffi@goffi.org>
parents:
2300
diff
changeset
|
421 class OnClick(object): |
a37457da2bb7
tools (common/data_objects): new OnClick class
Goffi <goffi@goffi.org>
parents:
2300
diff
changeset
|
422 """Class to handle clickable elements targets""" |
a37457da2bb7
tools (common/data_objects): new OnClick class
Goffi <goffi@goffi.org>
parents:
2300
diff
changeset
|
423 |
a37457da2bb7
tools (common/data_objects): new OnClick class
Goffi <goffi@goffi.org>
parents:
2300
diff
changeset
|
424 def __init__(self, url=None): |
a37457da2bb7
tools (common/data_objects): new OnClick class
Goffi <goffi@goffi.org>
parents:
2300
diff
changeset
|
425 self.url = url |
a37457da2bb7
tools (common/data_objects): new OnClick class
Goffi <goffi@goffi.org>
parents:
2300
diff
changeset
|
426 |
2482
ac6097a66944
tools (common/data_objects): accept same parameters as format en quote their values in OnClick.formatUrl
Goffi <goffi@goffi.org>
parents:
2478
diff
changeset
|
427 def formatUrl(self, *args, **kwargs): |
ac6097a66944
tools (common/data_objects): accept same parameters as format en quote their values in OnClick.formatUrl
Goffi <goffi@goffi.org>
parents:
2478
diff
changeset
|
428 """format URL using Python formatting |
2383
a37457da2bb7
tools (common/data_objects): new OnClick class
Goffi <goffi@goffi.org>
parents:
2300
diff
changeset
|
429 |
2482
ac6097a66944
tools (common/data_objects): accept same parameters as format en quote their values in OnClick.formatUrl
Goffi <goffi@goffi.org>
parents:
2478
diff
changeset
|
430 values will be quoted before being used |
2383
a37457da2bb7
tools (common/data_objects): new OnClick class
Goffi <goffi@goffi.org>
parents:
2300
diff
changeset
|
431 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
432 return self.url.format( |
3028 | 433 *[q(a) for a in args], **{k: ObjectQuoter(v) for k, v in kwargs.items()} |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
434 ) |