def parse_qs(qstr, ignore_exc=True, encoding=DEFAULT_ENCODING): """ Parse a url encoded string (a=b&c=d) into a QueryString object. :param qstr: The string to parse :return: A QueryString object (a dict wrapper). """ if not isinstance(qstr, basestring): raise TypeError("parse_qs requires a basestring as input.") qs = QueryString(encoding=encoding) if qstr: # convert to string if unicode if isinstance(qstr, unicode): qstr = qstr.encode(encoding, "ignore") try: odict = OrderedDict() for name, value in parse_qsl(qstr, keep_blank_values=True, strict_parsing=False): if name in odict: odict[name].append(value) else: odict[name] = [value] except Exception: if not ignore_exc: raise BaseFrameworkException('Error while parsing "%r"' % qstr) else: def decode(item): return (item[0].decode(encoding, "ignore"), [e.decode(encoding, "ignore") for e in item[1]]) qs.update((decode(item) for item in odict.items())) return qs
def get_data_container(self): """ :return: An OrderedDict ready to use in the fuzzer, which is based on the self._fuzzable_parameters attribute. You'll need to process an XML before accessing this method, else the result will be empty. """ init_val = OrderedDict() for name, value in self.fuzzable_parameters: value_list = init_val.setdefault(name, []) if name == BASE_64: value_list.append(base64.b64decode(value)) else: value_list.append(value) return init_val
def parse_qs(qstr, ignore_exc=True, encoding=DEFAULT_ENCODING): """ Parse a url encoded string (a=b&c=d) into a QueryString object. :param qstr: The string to parse :return: A QueryString object (a dict wrapper). """ if not isinstance(qstr, basestring): raise TypeError('parse_qs requires a basestring as input.') qs = QueryString(encoding=encoding) if qstr: # convert to string if unicode if isinstance(qstr, unicode): qstr = qstr.encode(encoding, 'ignore') try: odict = OrderedDict() for name, value in parse_qsl(qstr, keep_blank_values=True, strict_parsing=False): if name in odict: odict[name].append(value) else: odict[name] = [value] except Exception: if not ignore_exc: raise BaseFrameworkException('Error while parsing "%r"' % qstr) else: def decode(item): return (item[0].decode(encoding, 'ignore'), [e.decode(encoding, 'ignore') for e in item[1]]) qs.update((decode(item) for item in odict.items())) return qs