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 | |
| parent | 64fdd3abbbe9ab99c3bc5083d4172ea7bc17bae3 (diff) | |
| download | poky-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')
| -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): | |||
| 162 | * path_quoted (read/write) | 162 | * path_quoted (read/write) |
| 163 | A URI quoted version of path | 163 | A URI quoted version of path |
| 164 | * params (dict) (read/write) | 164 | * params (dict) (read/write) |
| 165 | * query (dict) (read/write) | ||
| 165 | * relative (bool) (read only) | 166 | * relative (bool) (read only) |
| 166 | True if this is a "relative URI", (e.g. file:foo.diff) | 167 | True if this is a "relative URI", (e.g. file:foo.diff) |
| 167 | 168 | ||
| @@ -201,6 +202,7 @@ class URI(object): | |||
| 201 | self.port = None | 202 | self.port = None |
| 202 | self._path = '' | 203 | self._path = '' |
| 203 | self.params = {} | 204 | self.params = {} |
| 205 | self.query = {} | ||
| 204 | self.relative = False | 206 | self.relative = False |
| 205 | 207 | ||
| 206 | if not uri: | 208 | if not uri: |
| @@ -253,36 +255,42 @@ class URI(object): | |||
| 253 | self.path = urllib.unquote(path) | 255 | self.path = urllib.unquote(path) |
| 254 | 256 | ||
| 255 | if param_str: | 257 | if param_str: |
| 256 | self.params = self._param_dict(param_str) | 258 | self.params = self._param_str_split(param_str, ";") |
| 259 | if urlp.query: | ||
| 260 | self.query = self._param_str_split(urlp.query, "&") | ||
| 257 | 261 | ||
| 258 | def __str__(self): | 262 | def __str__(self): |
| 259 | userinfo = self.userinfo | 263 | userinfo = self.userinfo |
| 260 | if userinfo: | 264 | if userinfo: |
| 261 | userinfo += '@' | 265 | userinfo += '@' |
| 262 | 266 | ||
| 263 | return "%s:%s%s%s%s%s" % ( | 267 | return "%s:%s%s%s%s%s%s" % ( |
| 264 | self.scheme, | 268 | self.scheme, |
| 265 | '' if self.relative else '//', | 269 | '' if self.relative else '//', |
| 266 | userinfo, | 270 | userinfo, |
| 267 | self.hostport, | 271 | self.hostport, |
| 268 | self.path_quoted, | 272 | self.path_quoted, |
| 269 | self._param_str) | 273 | self._query_str(), |
| 274 | self._param_str()) | ||
| 270 | 275 | ||
| 271 | @property | ||
| 272 | def _param_str(self): | 276 | def _param_str(self): |
| 273 | ret = '' | 277 | return ( |
| 274 | for key, val in self.params.items(): | 278 | ''.join([';', self._param_str_join(self.params, ";")]) |
| 275 | ret += ";%s=%s" % (key, val) | 279 | if self.params else '') |
| 280 | |||
| 281 | def _query_str(self): | ||
| 282 | return ( | ||
| 283 | ''.join(['?', self._param_str_join(self.query, "&")]) | ||
| 284 | if self.query else '') | ||
| 285 | |||
| 286 | def _param_str_split(self, string, elmdelim, kvdelim="="): | ||
| 287 | ret = {} | ||
| 288 | for k, v in [x.split(kvdelim, 1) for x in string.split(elmdelim)]: | ||
| 289 | ret[k] = v | ||
| 276 | return ret | 290 | return ret |
| 277 | 291 | ||
| 278 | def _param_dict(self, param_str): | 292 | def _param_str_join(self, dict_, elmdelim, kvdelim="="): |
| 279 | parm = {} | 293 | return elmdelim.join([kvdelim.join([k, v]) for k, v in dict_.items()]) |
| 280 | |||
| 281 | for keyval in param_str.split(";"): | ||
| 282 | key, val = keyval.split("=", 1) | ||
| 283 | parm[key] = val | ||
| 284 | |||
| 285 | return parm | ||
| 286 | 294 | ||
| 287 | @property | 295 | @property |
| 288 | def hostport(self): | 296 | def hostport(self): |
