annotate frontends/src/quick_frontend/quick_utils.py @ 510:886754295efe

quick frontend, primitivus, wix: MUC private messages management /!\ not fully finished, backend part is not done yet /!\ - as resources are discarded to manage chat windows lists, a pretty dirty hack is done to work around this: full jid is escaped using a prefix (it becomes invalid and resource is preserved). - new quick_utils module, with helper methods. escapePrivate and unescapePrivate implementations - MUC private messages are not managed in Wix yet
author Goffi <goffi@goffi.org>
date Thu, 11 Oct 2012 00:48:35 +0200
parents
children 3eeb6c865e4d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
510
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
diff changeset
3
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
diff changeset
4 """
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
diff changeset
5 Primitivus: a SAT frontend
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
diff changeset
6 Copyright (C) 2009, 2010, 2011, 2012 Jérôme Poisson (goffi@goffi.org)
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
diff changeset
7
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
diff changeset
8 This program is free software: you can redistribute it and/or modify
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
diff changeset
9 it under the terms of the GNU Affero General Public License as published by
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
diff changeset
11 (at your option) any later version.
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
diff changeset
12
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
diff changeset
16 GNU Affero General Public License for more details.
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
diff changeset
17
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
diff changeset
18 You should have received a copy of the GNU Affero General Public License
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
diff changeset
20 """
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
diff changeset
21
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
diff changeset
22 from sat.tools.jid import JID
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
diff changeset
23
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
diff changeset
24 def escapePrivate(ori_jid):
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
diff changeset
25 """Escape a private jid"""
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
diff changeset
26 return JID(const_PRIVATE_PREFIX + ori_jid.short + '@' + ori_jid.resource)
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
diff changeset
27
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
diff changeset
28 def unescapePrivate(escaped_jid):
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
diff changeset
29 if not escaped_jid.startswith(const_PRIVATE_PREFIX):
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
diff changeset
30 return escaped_jid
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
diff changeset
31 escaped_split = tuple(escaped_jid[len(const_PRIVATE_PREFIX):].split('@'))
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
diff changeset
32 assert(len(escaped_split) == 3)
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
diff changeset
33 return JID("%s@%s/%s" % escaped_split)