示例#1
0
    def localize(self, o, *args):
        '''Localize the specified keys in o, where o can be arbitrarily nested 
           lists, dicts, tuples and/or sets.

           @param o : list|dict|tuple|set
               the object to search through for the keys
           @param args : positional arguments
               the keys for datetimes that should be localized'''

        keys = set(args)
        def callback(key, value):
            if key in keys:
                return times.to_local(value, self.timezone)

        return recurse(o, callback)
示例#2
0
def serialize(o, **kwargs):
    '''(De)serialize the object with the serializers passed in as keyword
       arguments. The object may an arbitrary nesting of dicts/lists, however
       see regularity.utils.recurse() for the assumptions that are made about
       the data.

       @param o : dict | iterable
           the object to serialize
       @param kwargs : keyword arguments
           a mapping of field name -> serializer function'''

    def callback(key, value):
        if key in kwargs:
            function = kwargs[key]
            return function(value)

    return recurse(o, callback)