예제 #1
0
파일: url.py 프로젝트: nixwizard/w3af
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
예제 #2
0
파일: xmlrpc.py 프로젝트: 0x554simon/w3af
    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
예제 #3
0
파일: xmlrpc.py 프로젝트: webvul/webfuzzer
    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
예제 #4
0
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