annotate frontends/src/tools/strings.py @ 767:318acc83a392

quick_frontend: fix presence/status update (do not share between different resources)
author souliane <souliane@mailoo.org>
date Wed, 18 Dec 2013 09:55:02 +0100
parents 56aa0e98c92e
children 8b6137f7b4e1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
690
d8e7a58eaa00 misc: added a file for frontend's string operations:
souliane <souliane@mailoo.org>
parents:
diff changeset
1 #!/usr/bin/python
d8e7a58eaa00 misc: added a file for frontend's string operations:
souliane <souliane@mailoo.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
d8e7a58eaa00 misc: added a file for frontend's string operations:
souliane <souliane@mailoo.org>
parents:
diff changeset
3
d8e7a58eaa00 misc: added a file for frontend's string operations:
souliane <souliane@mailoo.org>
parents:
diff changeset
4 # SAT helpers methods for plugins
d8e7a58eaa00 misc: added a file for frontend's string operations:
souliane <souliane@mailoo.org>
parents:
diff changeset
5 # Copyright (C) 2013 Adrien Cossa (souliane@mailoo.org)
d8e7a58eaa00 misc: added a file for frontend's string operations:
souliane <souliane@mailoo.org>
parents:
diff changeset
6
d8e7a58eaa00 misc: added a file for frontend's string operations:
souliane <souliane@mailoo.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
d8e7a58eaa00 misc: added a file for frontend's string operations:
souliane <souliane@mailoo.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
d8e7a58eaa00 misc: added a file for frontend's string operations:
souliane <souliane@mailoo.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
d8e7a58eaa00 misc: added a file for frontend's string operations:
souliane <souliane@mailoo.org>
parents:
diff changeset
10 # (at your option) any later version.
d8e7a58eaa00 misc: added a file for frontend's string operations:
souliane <souliane@mailoo.org>
parents:
diff changeset
11
d8e7a58eaa00 misc: added a file for frontend's string operations:
souliane <souliane@mailoo.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
d8e7a58eaa00 misc: added a file for frontend's string operations:
souliane <souliane@mailoo.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
d8e7a58eaa00 misc: added a file for frontend's string operations:
souliane <souliane@mailoo.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d8e7a58eaa00 misc: added a file for frontend's string operations:
souliane <souliane@mailoo.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
d8e7a58eaa00 misc: added a file for frontend's string operations:
souliane <souliane@mailoo.org>
parents:
diff changeset
16
d8e7a58eaa00 misc: added a file for frontend's string operations:
souliane <souliane@mailoo.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
d8e7a58eaa00 misc: added a file for frontend's string operations:
souliane <souliane@mailoo.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
d8e7a58eaa00 misc: added a file for frontend's string operations:
souliane <souliane@mailoo.org>
parents:
diff changeset
19
d8e7a58eaa00 misc: added a file for frontend's string operations:
souliane <souliane@mailoo.org>
parents:
diff changeset
20
d8e7a58eaa00 misc: added a file for frontend's string operations:
souliane <souliane@mailoo.org>
parents:
diff changeset
21 def getURLParams(url):
d8e7a58eaa00 misc: added a file for frontend's string operations:
souliane <souliane@mailoo.org>
parents:
diff changeset
22 """This comes from pyjamas.Location.makeUrlDict with a small change
d8e7a58eaa00 misc: added a file for frontend's string operations:
souliane <souliane@mailoo.org>
parents:
diff changeset
23 to also parse full URLs, and parameters with no value specified
d8e7a58eaa00 misc: added a file for frontend's string operations:
souliane <souliane@mailoo.org>
parents:
diff changeset
24 (in that case the default value "" is used).
d8e7a58eaa00 misc: added a file for frontend's string operations:
souliane <souliane@mailoo.org>
parents:
diff changeset
25 @param url: any URL with or without parameters
d8e7a58eaa00 misc: added a file for frontend's string operations:
souliane <souliane@mailoo.org>
parents:
diff changeset
26 @return: a dictionary of the parameters, if any was given, or {}
d8e7a58eaa00 misc: added a file for frontend's string operations:
souliane <souliane@mailoo.org>
parents:
diff changeset
27 """
d8e7a58eaa00 misc: added a file for frontend's string operations:
souliane <souliane@mailoo.org>
parents:
diff changeset
28 dict_ = {}
d8e7a58eaa00 misc: added a file for frontend's string operations:
souliane <souliane@mailoo.org>
parents:
diff changeset
29 if "/" in url:
d8e7a58eaa00 misc: added a file for frontend's string operations:
souliane <souliane@mailoo.org>
parents:
diff changeset
30 # keep the part after the last "/"
d8e7a58eaa00 misc: added a file for frontend's string operations:
souliane <souliane@mailoo.org>
parents:
diff changeset
31 url = url[url.rindex("/") + 1:]
d8e7a58eaa00 misc: added a file for frontend's string operations:
souliane <souliane@mailoo.org>
parents:
diff changeset
32 if url.startswith("?"):
d8e7a58eaa00 misc: added a file for frontend's string operations:
souliane <souliane@mailoo.org>
parents:
diff changeset
33 # remove the first "?"
d8e7a58eaa00 misc: added a file for frontend's string operations:
souliane <souliane@mailoo.org>
parents:
diff changeset
34 url = url[1:]
d8e7a58eaa00 misc: added a file for frontend's string operations:
souliane <souliane@mailoo.org>
parents:
diff changeset
35 pairs = url.split("&")
d8e7a58eaa00 misc: added a file for frontend's string operations:
souliane <souliane@mailoo.org>
parents:
diff changeset
36 for pair in pairs:
d8e7a58eaa00 misc: added a file for frontend's string operations:
souliane <souliane@mailoo.org>
parents:
diff changeset
37 if len(pair) < 3:
d8e7a58eaa00 misc: added a file for frontend's string operations:
souliane <souliane@mailoo.org>
parents:
diff changeset
38 continue
d8e7a58eaa00 misc: added a file for frontend's string operations:
souliane <souliane@mailoo.org>
parents:
diff changeset
39 kv = pair.split("=", 1)
d8e7a58eaa00 misc: added a file for frontend's string operations:
souliane <souliane@mailoo.org>
parents:
diff changeset
40 dict_[kv[0]] = kv[1] if len(kv) > 1 else ""
d8e7a58eaa00 misc: added a file for frontend's string operations:
souliane <souliane@mailoo.org>
parents:
diff changeset
41 return dict_
d8e7a58eaa00 misc: added a file for frontend's string operations:
souliane <souliane@mailoo.org>
parents:
diff changeset
42