comparison src/tools/frontends/strings.py @ 690:d8e7a58eaa00

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