def _preprocess(method, headers, url):
"""Unify input.
Example:
_preprocess('POST', {'Content-Type': 'Foo'},
'http://localhost:8080/_ah/gcs/b/f?foo=bar')
-> 'POST', {'content-type': 'Foo'}, '/b/f', {'foo':'bar'}
Args:
method: HTTP method used by the request.
headers: HTTP request headers in a dict.
url: HTTP request url.
Returns:
method: method in all upper case.
headers: headers with keys in all lower case.
filename: a google storage filename of form /bucket/filename or
a bucket path of form /bucket
param_dict: a dict of query parameters.
Raises:
ValueError: invalid path.
"""
_, _, path, query, _ = urlparse.urlsplit(url)
if not path.startswith(common.LOCAL_GCS_ENDPOINT):
raise ValueError('Invalid GCS path: %s' % path, httplib.BAD_REQUEST)
filename = path[len(common.LOCAL_GCS_ENDPOINT):]
param_dict = urlparse.parse_qs(query, True)
for k in param_dict:
param_dict[k] = urllib.unquote(param_dict[k][0])
headers = dict((k.lower(), v) for k, v in headers.iteritems())
return method, headers, urllib.unquote(filename), param_dict
评论列表
文章目录