async def form(self, *, encoding=None): # Like `.read`, but assumes that body parts contains form url_encoded data. # encoding : `str`, Optional : Custom form encoding. Overrides specified in charset param of `Content-Type` # header data = await self.read(decode=True) if not data: return None encoding = encoding or self.get_charset(default='utf-8') return parse_query_string_list(data.rstrip().decode(encoding), keep_blank_values=True, encoding=encoding)
def query(self): """ A multidict representing parsed query parameters in decoded representation. An empty multidict is returned if the url has no query parts. Returns ------- query : `multidict` of (`str`, `Any`) items """ return multidict(parse_query_string_list(self.query_string, keep_blank_values=True))
def extend_query(self, params): """ Returns a new URL with it's query parameters extended. Parameters ---------- params : `None`, `str`, (`dict`, `list`, `set`) of \ (`str`, (`str`, `int`, `bool`, `NoneType`, `float`, (`list`, `set`, `tuple`) of repeat value)) items The query parameters to extend the actual. Returns ------- new_url : ``URL`` Raises ------ TypeError - If `query` was given as an invalid type. - If `query` was given as `set` or `list`, but `1` of it's elements cannot be unpacked correctly. - If a query key was not given as `str` instance. - If a query value was not given as any of the expected types. ValueError - If a query value was given as `float`, but as `inf`. - If a query value was given as `float`, but as `nan`. Notes ----- The returned URL's `fragment` will be same as the source one's. """ if (params is None) or (not params): new_url = self else: query = self.query.copy() if isinstance(params, str): params = parse_query_string_list(params, keep_blank_values=True) query.extend(params) new_url = self.with_query(query) return new_url