Ejemplo n.º 1
0
def http_build_query(interp, w_data, num_prefix="", arg_sep=None, enctype=1):
    space = interp.space
    if arg_sep is None:
        arg_sep = interp.config.get_ini_str("arg_separator.output")
    w_data = w_data.deref()
    out = StringBuilder()
    if not w_data.tp in [space.tp_array, space.tp_object]:
        interp.space.ec.warn("http_build_query(): Parameter 1 "
                             "expected to be Array or Object.  "
                             "Incorrect value given")
    if w_data.tp == space.tp_array:
        with space.iter(w_data) as itr:
            while not itr.done():
                w_key, w_value = itr.next_item(space)
                key = _get_key(space, num_prefix, w_key)
                res = _build_query(space, [], key, w_value, num_prefix,
                                   arg_sep, enctype)
                out.append(''.join(res))

    if w_data.tp == space.tp_object:
        for key, w_value in w_data.get_instance_attrs(interp).iteritems():
            _, prop = demangle_property(key)
            if prop:
                continue
            res = _build_query(space, [], key, w_value, num_prefix, arg_sep,
                               enctype)
            out.append(''.join(res))

    outstr = out.build()
    if outstr.endswith(arg_sep):
        outstr = outstr.rstrip(arg_sep)
    return interp.space.newstr(outstr)
Ejemplo n.º 2
0
def http_build_query(interp,  w_data,
                     num_prefix="",  arg_sep=None,  enctype=1):
    space = interp.space
    if arg_sep is None:
        arg_sep = interp.config.get_ini_str("arg_separator.output")
    w_data = w_data.deref()
    out = StringBuilder()
    if not w_data.tp in [space.tp_array,  space.tp_object]:
        interp.space.ec.warn("http_build_query(): Parameter 1 "
                             "expected to be Array or Object.  "
                             "Incorrect value given")
    if w_data.tp == space.tp_array:
        with space.iter(w_data) as itr:
            while not itr.done():
                w_key,  w_value = itr.next_item(space)
                key = _get_key(space,  num_prefix,  w_key)
                res = _build_query(space,  [],  key,  w_value,
                                   num_prefix,  arg_sep,  enctype)
                out.append(''.join(res))

    if w_data.tp == space.tp_object:
        for key, w_value in w_data.get_instance_attrs(interp).iteritems():
            _,  prop = demangle_property(key)
            if prop:
                continue
            res = _build_query(space, [], key, w_value, num_prefix,
                               arg_sep, enctype)
            out.append(''.join(res))

    outstr = out.build()
    if outstr.endswith(arg_sep):
        outstr = outstr.rstrip(arg_sep)
    return interp.space.newstr(outstr)
Ejemplo n.º 3
0
def _print_r(space, w_x, indent, recursion, builder):
    if w_x.tp == space.tp_array:
        if w_x in recursion:
            builder.append('Array\n *RECURSION*')
            return
        recursion[w_x] = None
        builder.append('Array\n%s(' % indent)
        subindent = indent + '        '
        with space.iter(w_x) as w_iter:
            while not w_iter.done():
                w_key, w_value = w_iter.next_item(space)
                if w_key.tp == space.tp_int:
                    key = space.int_w(w_key)
                    s = '\n%s    [%d] => ' % (indent, key)
                else:
                    key = space.str_w(w_key)
                    s = '\n%s    [%s] => ' % (indent, key)
                builder.append(s)
                _print_r(space, w_value.deref(), subindent, recursion, builder)
        builder.append('\n%s)\n' % indent)
        del recursion[w_x]
    elif isinstance(w_x, W_InstanceObject):
        builder.append('%s Object\n' % w_x.klass.name)
        if w_x in recursion:
            builder.append(' *RECURSION*')
            return
        recursion[w_x] = None
        builder.append('%s(' % indent)
        keyindent = indent + ' ' * 4
        subindent = indent + ' ' * 8
        dct_w = w_x.get_instance_attrs()
        for name, w_value in dct_w.iteritems():
            name, access = demangle_property(name)
            if access == '':
                key = '%s' % name
            elif access == '*':
                key = '%s:protected' % name
            else:
                key = '%s:%s:private' % (name, access)
            builder.append('\n%s[%s] => ' % (keyindent, key))
            _print_r(space, w_value.deref(), subindent, recursion, builder)
        builder.append('\n%s)\n' % indent)
        del recursion[w_x]
    else:
        builder.append(space.str_w(w_x))
Ejemplo n.º 4
0
def _print_r(space, w_x, indent, recursion, builder):
    if w_x.tp == space.tp_array:
        if w_x in recursion:
            builder.append('Array\n *RECURSION*')
            return
        recursion[w_x] = None
        builder.append('Array\n%s(' % indent)
        subindent = indent + '        '
        with space.iter(w_x) as w_iter:
            while not w_iter.done():
                w_key, w_value = w_iter.next_item(space)
                if w_key.tp == space.tp_int:
                    key = space.int_w(w_key)
                    s = '\n%s    [%d] => ' % (indent, key)
                else:
                    key = space.str_w(w_key)
                    s = '\n%s    [%s] => ' % (indent, key)
                builder.append(s)
                _print_r(space, w_value.deref(), subindent, recursion, builder)
        builder.append('\n%s)\n' % indent)
        del recursion[w_x]
    elif isinstance(w_x, W_InstanceObject):
        builder.append('%s Object\n' % w_x.klass.name)
        if w_x in recursion:
            builder.append(' *RECURSION*')
            return
        recursion[w_x] = None
        builder.append('%s(' % indent)
        keyindent = indent + ' ' * 4
        subindent = indent + ' ' * 8
        dct_w = w_x.get_instance_attrs()
        for name, w_value in dct_w.iteritems():
            name, access = demangle_property(name)
            if access == '':
                key = '%s' % name
            elif access == '*':
                key = '%s:protected' % name
            else:
                key = '%s:%s:private' % (name, access)
            builder.append('\n%s[%s] => ' % (keyindent, key))
            _print_r(space, w_value.deref(), subindent, recursion, builder)
        builder.append('\n%s)\n' % indent)
        del recursion[w_x]
    else:
        builder.append(space.str_w(w_x))