Ejemplo n.º 1
0
    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
Ejemplo n.º 2
0
def deepish_copy(org):
    """
    Much, much faster than deepcopy, for a dict of the simple python types.

    http://writeonly.wordpress.com/2009/05/07/deepcopy-is-a-pig-for-simple-data/
    """
    out = OrderedDict().fromkeys(org)

    for k, v in org.iteritems():
        try:
            out[k] = v.copy()  # dicts, sets
        except AttributeError:
            try:
                out[k] = v[:]  # lists, tuples, strings, unicode
            except TypeError:
                out[k] = v  # ints

    return out
Ejemplo n.º 3
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 url_enc_str: 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