Use ODict for Request.get_query and Request.set_query
This commit is contained in:
parent
2616f490fe
commit
fa11b7c9be
|
@ -374,7 +374,7 @@ class ConnectionView(common.WWrap):
|
|||
conn.headers = flow.ODict(lst)
|
||||
|
||||
def set_query(self, lst, conn):
|
||||
conn.set_query(lst)
|
||||
conn.set_query(flow.ODict(lst))
|
||||
|
||||
def set_form(self, lst, conn):
|
||||
conn.set_form_urlencoded(lst)
|
||||
|
@ -396,7 +396,7 @@ class ConnectionView(common.WWrap):
|
|||
elif part == "h":
|
||||
self.master.view_kveditor("Editing headers", conn.headers.lst, self.set_headers, conn)
|
||||
elif part == "q":
|
||||
self.master.view_kveditor("Editing query", conn.get_query(), self.set_query, conn)
|
||||
self.master.view_kveditor("Editing query", conn.get_query().lst, self.set_query, conn)
|
||||
elif part == "u" and self.state.view_flow_mode == common.VIEW_FLOW_REQUEST:
|
||||
self.master.prompt_edit("URL", conn.get_url(), self.set_url)
|
||||
elif part == "m" and self.state.view_flow_mode == common.VIEW_FLOW_REQUEST:
|
||||
|
|
|
@ -69,6 +69,9 @@ class ODict:
|
|||
new.append(i)
|
||||
return new
|
||||
|
||||
def __len__(self):
|
||||
return len(self.lst)
|
||||
|
||||
def __setitem__(self, k, values):
|
||||
if isinstance(values, basestring):
|
||||
raise ValueError("ODict values should be lists.")
|
||||
|
@ -323,7 +326,7 @@ class Request(HTTPMsg):
|
|||
_, _, _, _, query, _ = urlparse.urlparse(self.get_url())
|
||||
if not query:
|
||||
return []
|
||||
return utils.urldecode(query)
|
||||
return ODict(utils.urldecode(query))
|
||||
|
||||
def set_query(self, q):
|
||||
"""
|
||||
|
@ -331,7 +334,7 @@ class Request(HTTPMsg):
|
|||
string.
|
||||
"""
|
||||
scheme, netloc, path, params, _, fragment = urlparse.urlparse(self.get_url())
|
||||
query = utils.urlencode(q)
|
||||
query = utils.urlencode(q.lst)
|
||||
self.set_url(urlparse.urlunparse([scheme, netloc, path, params, query, fragment]))
|
||||
|
||||
def get_url(self):
|
||||
|
|
|
@ -657,7 +657,7 @@ class uRequest(libpry.AutoTree):
|
|||
|
||||
r = flow.Request(None, "host", 22, "https", "GET", "/foo?x=y&a=b", h, "content")
|
||||
q = r.get_query()
|
||||
assert q == [("x", "y"), ("a", "b")]
|
||||
assert q.lst == [("x", "y"), ("a", "b")]
|
||||
|
||||
r = flow.Request(None, "host", 22, "https", "GET", "/", h, "content")
|
||||
q = r.get_query()
|
||||
|
@ -669,9 +669,9 @@ class uRequest(libpry.AutoTree):
|
|||
|
||||
r = flow.Request(None, "host", 22, "https", "GET", "/foo?x=y&a=b", h, "content")
|
||||
assert r.get_query()
|
||||
r.set_query([])
|
||||
r.set_query(flow.ODict([]))
|
||||
assert not r.get_query()
|
||||
qv = [("a", "b"), ("c", "d")]
|
||||
qv = flow.ODict([("a", "b"), ("c", "d")])
|
||||
r.set_query(qv)
|
||||
assert r.get_query() == qv
|
||||
|
||||
|
|
Loading…
Reference in New Issue