Example #1
0
 def defreezef(self, obj):
     return defreezef(obj, self.globs)
Example #2
0
                                __builtins__.eval('%s(*%s)'%(x[0][8:-2],x[1])))()
                        or     x.startswith('range://') 
                        and    range(*eval(x[8:]))
                        or     x.startswith('bytearray://') 
                        and    bytearray(eval(x[12:]))
                        or     x.startswith('memoryview://') 
                        and    memoryview(bytearray(eval(x[13:])))
                        or     x.startswith('complex://')
                        and    complex(x[10:])
                        or     x.startswith('type://')
                        and    (lambda x = eval(x[7:]):type(x[0],tuple((globs()[i])
                        if     i in globs() else __builtins__.eval(i)
                        for    i in [(i[9:] if i.startswith('__main__.') else i)
                        for    i in [(i[8:-2] if i.endswith('>') else i[8:-3])
                        for    i in x[1][1:-1].split(', ')]]),restore(x[2],globs)))()
                        or     x.startswith('function://')
                        and    defreezef(eval(x[11:]), globs = globs)
                        or     x.startswith('tuple://') 
                        and    tuple([restore(i,globs) for i in eval(x[8:])]))(obj) 
                        or     isinstance(obj, list) 
                        and    [restore(i, globs) for i in obj] 
                        or     isinstance(obj, dict) 
                        and    {restore(i, globs):restore(obj[i], globs) for i in obj} 
                        or     obj)

serialize   = lambda obj, *args, **kwargs: json.dumps(flatten(obj), *args, **kwargs)
deserialize = lambda obj, *args, **kwargs: restore(json.loads(obj, *args,
                                           **{arg:kwargs[arg] for arg in kwargs if not arg == 'globs'}),
                                           globs = (lambda: 'globs' in kwargs and
                                           kwargs['globs'] or (lambda:{'__builtins__':__builtins__}))())