Show More
@@ -78,6 +78,10 b' class parsedrequest(object):' | |||||
78 | dispatchpath = attr.ib() |
|
78 | dispatchpath = attr.ib() | |
79 | # Raw query string (part after "?" in URL). |
|
79 | # Raw query string (part after "?" in URL). | |
80 | querystring = attr.ib() |
|
80 | querystring = attr.ib() | |
|
81 | # List of 2-tuples of query string arguments. | |||
|
82 | querystringlist = attr.ib() | |||
|
83 | # Dict of query string arguments. Values are lists with at least 1 item. | |||
|
84 | querystringdict = attr.ib() | |||
81 |
|
85 | |||
82 | def parserequestfromenv(env): |
|
86 | def parserequestfromenv(env): | |
83 | """Parse URL components from environment variables. |
|
87 | """Parse URL components from environment variables. | |
@@ -168,12 +172,25 b' def parserequestfromenv(env):' | |||||
168 |
|
172 | |||
169 | querystring = env.get('QUERY_STRING', '') |
|
173 | querystring = env.get('QUERY_STRING', '') | |
170 |
|
174 | |||
|
175 | # We store as a list so we have ordering information. We also store as | |||
|
176 | # a dict to facilitate fast lookup. | |||
|
177 | querystringlist = util.urlreq.parseqsl(querystring, keep_blank_values=True) | |||
|
178 | ||||
|
179 | querystringdict = {} | |||
|
180 | for k, v in querystringlist: | |||
|
181 | if k in querystringdict: | |||
|
182 | querystringdict[k].append(v) | |||
|
183 | else: | |||
|
184 | querystringdict[k] = [v] | |||
|
185 | ||||
171 | return parsedrequest(url=fullurl, baseurl=baseurl, |
|
186 | return parsedrequest(url=fullurl, baseurl=baseurl, | |
172 | advertisedurl=advertisedfullurl, |
|
187 | advertisedurl=advertisedfullurl, | |
173 | advertisedbaseurl=advertisedbaseurl, |
|
188 | advertisedbaseurl=advertisedbaseurl, | |
174 | apppath=apppath, |
|
189 | apppath=apppath, | |
175 | dispatchparts=dispatchparts, dispatchpath=dispatchpath, |
|
190 | dispatchparts=dispatchparts, dispatchpath=dispatchpath, | |
176 |
querystring=querystring |
|
191 | querystring=querystring, | |
|
192 | querystringlist=querystringlist, | |||
|
193 | querystringdict=querystringdict) | |||
177 |
|
194 | |||
178 | class wsgirequest(object): |
|
195 | class wsgirequest(object): | |
179 | """Higher-level API for a WSGI request. |
|
196 | """Higher-level API for a WSGI request. |
@@ -48,6 +48,7 b' if pycompat.ispy3:' | |||||
48 | "urlunparse", |
|
48 | "urlunparse", | |
49 | )) |
|
49 | )) | |
50 | urlreq._registeralias(urllib.parse, "parse_qs", "parseqs") |
|
50 | urlreq._registeralias(urllib.parse, "parse_qs", "parseqs") | |
|
51 | urlreq._registeralias(urllib.parse, "parse_qsl", "parseqsl") | |||
51 | urlreq._registeralias(urllib.parse, "unquote_to_bytes", "unquote") |
|
52 | urlreq._registeralias(urllib.parse, "unquote_to_bytes", "unquote") | |
52 | import urllib.request |
|
53 | import urllib.request | |
53 | urlreq._registeraliases(urllib.request, ( |
|
54 | urlreq._registeraliases(urllib.request, ( | |
@@ -159,6 +160,7 b' else:' | |||||
159 | "urlunparse", |
|
160 | "urlunparse", | |
160 | )) |
|
161 | )) | |
161 | urlreq._registeralias(urlparse, "parse_qs", "parseqs") |
|
162 | urlreq._registeralias(urlparse, "parse_qs", "parseqs") | |
|
163 | urlreq._registeralias(urlparse, "parse_qsl", "parseqsl") | |||
162 | urlerr._registeraliases(urllib2, ( |
|
164 | urlerr._registeraliases(urllib2, ( | |
163 | "HTTPError", |
|
165 | "HTTPError", | |
164 | "URLError", |
|
166 | "URLError", |
General Comments 0
You need to be logged in to leave comments.
Login now