diff options
author | Olof Johansson <olof.johansson@axis.com> | 2014-01-20 12:03:22 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2014-03-24 17:54:46 +0000 |
commit | aca2d14e9350fde58aaaa95cdeff5b051c1d38d3 (patch) | |
tree | 503fbfed656119128b0632b59fdbfc66fb7095d9 /bitbake/lib/bb/fetch2/__init__.py | |
parent | 64fdd3abbbe9ab99c3bc5083d4172ea7bc17bae3 (diff) | |
download | openembedded-core-contrib-aca2d14e9350fde58aaaa95cdeff5b051c1d38d3.tar.gz |
bitbake: fetch2.URI: add support for query parameters
This change introduces the .query property of the URI class. It is a
read/write dict of the parameters supplied in the query string of the
URI. E.g.:
http://example.com/?foo=bar => .query = {'foo': 'bar'}
(Bitbake rev: 1cb2b3c458c8c5521591d2c8f2e0058143fc77bb)
Signed-off-by: Olof Johansson <olof.johansson@axis.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/fetch2/__init__.py')
-rw-r--r-- | bitbake/lib/bb/fetch2/__init__.py | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/bitbake/lib/bb/fetch2/__init__.py b/bitbake/lib/bb/fetch2/__init__.py index 5c6180bbb7..d9d193ab12 100644 --- a/bitbake/lib/bb/fetch2/__init__.py +++ b/bitbake/lib/bb/fetch2/__init__.py @@ -162,6 +162,7 @@ class URI(object): * path_quoted (read/write) A URI quoted version of path * params (dict) (read/write) + * query (dict) (read/write) * relative (bool) (read only) True if this is a "relative URI", (e.g. file:foo.diff) @@ -201,6 +202,7 @@ class URI(object): self.port = None self._path = '' self.params = {} + self.query = {} self.relative = False if not uri: @@ -253,36 +255,42 @@ class URI(object): self.path = urllib.unquote(path) if param_str: - self.params = self._param_dict(param_str) + self.params = self._param_str_split(param_str, ";") + if urlp.query: + self.query = self._param_str_split(urlp.query, "&") def __str__(self): userinfo = self.userinfo if userinfo: userinfo += '@' - return "%s:%s%s%s%s%s" % ( + return "%s:%s%s%s%s%s%s" % ( self.scheme, '' if self.relative else '//', userinfo, self.hostport, self.path_quoted, - self._param_str) + self._query_str(), + self._param_str()) - @property def _param_str(self): - ret = '' - for key, val in self.params.items(): - ret += ";%s=%s" % (key, val) + return ( + ''.join([';', self._param_str_join(self.params, ";")]) + if self.params else '') + + def _query_str(self): + return ( + ''.join(['?', self._param_str_join(self.query, "&")]) + if self.query else '') + + def _param_str_split(self, string, elmdelim, kvdelim="="): + ret = {} + for k, v in [x.split(kvdelim, 1) for x in string.split(elmdelim)]: + ret[k] = v return ret - def _param_dict(self, param_str): - parm = {} - - for keyval in param_str.split(";"): - key, val = keyval.split("=", 1) - parm[key] = val - - return parm + def _param_str_join(self, dict_, elmdelim, kvdelim="="): + return elmdelim.join([kvdelim.join([k, v]) for k, v in dict_.items()]) @property def hostport(self): |