ZTUtils.Zope.complex_mashal doesn't handle :records

Bug #142945 reported by Dylan Jay
This bug report is a duplicate of:  Bug #143335: ZTutils marshalling functions. Edit Remove
2
Affects Status Importance Assigned to Milestone
Zope 2
New
Wishlist
Unassigned

Bug Description

This simple patch allows complex_marshal to return appropriate values for the case when a value is a list of dictionaries. Or at least the test in this code is when the first element of the list is a dictionary. Perhaps this could be tightened.

 def complex_marshal(pairs):
    '''Add request marshalling information to a list of name-value pairs.

    Names must be strings. Values may be strings,
    integers, floats, or DateTimes, and they may also be lists or
    namespaces containing these types.

    The list is edited in place so that each (name, value) pair
    becomes a (name, marshal, value) triple. The middle value is the
    request marshalling string. Integer, float, and DateTime values
    will have ":int", ":float", or ":date" as their marshal string.
    Lists that contain dictionaries will be marshalled using ":records".
    Other lists will be flattened, and the elements given ":list" in
    addition to their simple marshal string. Dictionaries will be
    flattened and marshalled using ":record".
    '''
    i = len(pairs)
    while i > 0:
        i = i - 1
        k, v = pairs[i]
        m = ''
        sublist = None
        if isinstance(v, StringType):
            pass
        elif hasattr(v, 'items'):
            sublist = []
            for sk, sv in v.items():
                sm = simple_marshal(sv)
                sublist.append(('%s.%s' % (k, sk), '%s:record' % sm, sv))
        elif isinstance(v, ListType):
            sublist = []
            if len(v) > 0 and hasattr(v[0], 'items'):
                for rec in v:
                    for sk, sv in rec.items():
                        sm = simple_marshal(sv)
                        sublist.append(('%s.%s' % (k, sk), '%s:records' % sm, sv))
            else:
                for sv in v:
                    sm = simple_marshal(sv)
                    sublist.append((k, '%s:list' % sm, sv))
        else:
            m = simple_marshal(v)
        if sublist is None:
            pairs[i] = (k, m, v)
        else:
            pairs[i:i + 1] = sublist

    return pairs

Changed in zope2:
importance: Medium → Wishlist
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.