TL DR
What libraries / calls are available for processing query strings containing half-columns differently than parse_qs?
>>> urlparse.parse_qs("tagged=python;ruby") >>> {'tagged': ['python']}
Full background
I am working with the StackExchange API to search for flagged questions.
Search is laid out like this, with tags separated by half-columns:
/2.1/search?order=desc&sort=activity&tagged=python;ruby&site=stackoverflow
Interacting with the API is great. The problem occurs when I want to test calls, especially when using httpretty to mock HTTP.
Under the hood, httpretty uses urlparse.parse_qs from the standard python libraries to parse the request.
>>> urlparse.parse_qs("tagged=python;ruby") {'tagged': ['python']}
Clearly this does not work well. This is a small example, here is a fragment of httpretty (out of context of testing).
import requests import httpretty httpretty.enable() httpretty.register_uri(httpretty.GET, "https://api.stackexchange.com/2.1/search", body='{"items":[]}') resp = requests.get("https://api.stackexchange.com/2.1/search", params={"tagged":"python;ruby"}) httpretty_request = httpretty.last_request() print(httpretty_request.querystring) httpretty.disable() httpretty.reset()
I want to use machinery from httpretty, but a parse_qs is required for parse_qs . At the moment, I can apply the httpretty patch clown, but I would like to see what else can be done.
Kyle Kelley Jan 03 '14 at 18:21 2014-01-03 18:21
source share