def urlencoded_form(self, odict): """ Sets the body to the URL-encoded form data, and adds the appropriate content-type header. This will overwrite the existing content if there is one. """ self.headers["content-type"] = "application/x-www-form-urlencoded" self.content = utils.urlencode(odict.lst)
def set_query(self, odict): """ Takes an ODict object, and sets the request query string. """ scheme, netloc, path, params, _, fragment = urlparse.urlparse(self.get_url()) query = utils.urlencode(odict.lst) self.set_url(urlparse.urlunparse([scheme, netloc, path, params, query, fragment]))
def query(self, odict): query = utils.urlencode(odict.lst) scheme, netloc, path, params, _, fragment = urllib.parse.urlparse( self.url) _, _, _, self.path = utils.parse_url( urllib.parse.urlunparse( [scheme, netloc, path, params, query, fragment]))
def _set_query(self, value): query = utils.urlencode(value) scheme, netloc, path, params, _, fragment = urllib.parse.urlparse( self.url) _, _, _, self.path = utils.parse_url( urllib.parse.urlunparse( [scheme, netloc, path, params, query, fragment]))
def set_query(self, odict): """ Takes an ODict object, and sets the request query string. """ scheme, netloc, path, params, _, fragment = urlparse.urlparse(self.url) query = utils.urlencode(odict.lst) self.url = urlparse.urlunparse( [scheme, netloc, path, params, query, fragment])
def set_form_urlencoded(self, odict): """ Sets the body to the URL-encoded form data, and adds the appropriate content-type header. Note that this will destory the existing body if there is one. """ # FIXME: If there's an existing content-type header indicating a # url-encoded form, leave it alone. self.headers["Content-Type"] = [HDR_FORM_URLENCODED] self.content = utils.urlencode(odict.lst)
def test_urlencode(): assert utils.urlencode([('foo', 'bar')])
def query(self, odict): query = utils.urlencode(odict.lst) scheme, netloc, path, params, _, fragment = urllib.parse.urlparse(self.url) _, _, _, self.path = utils.parse_url( urllib.parse.urlunparse([scheme, netloc, path, params, query, fragment]))