From c7beeaf5c5f7c64e49ceadc94aa752a6e312c368 Mon Sep 17 00:00:00 2001 From: mdipierro Date: Tue, 19 Aug 2014 18:57:25 -0500 Subject: [PATCH] added utils.obj2dict --- VERSION | 2 +- applications/welcome/models/db.py | 1 + gluon/utils.py | 27 ++++++++++++++++++++++++++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index 890752ce..27f5ac32 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -Version 2.10.0-trunk+timestamp.2014.08.16.23.20.56 +Version 2.10.0-trunk+timestamp.2014.08.19.18.56.57 diff --git a/applications/welcome/models/db.py b/applications/welcome/models/db.py index b0dfdbaf..6b92a0d7 100644 --- a/applications/welcome/models/db.py +++ b/applications/welcome/models/db.py @@ -48,6 +48,7 @@ service = Service() plugins = PluginManager() ## create all tables needed by auth if not custom tables +auth.settings.extra_fields['auth_user'] = [Field('claims','list:string')] auth.define_tables(username=False, signature=False) ## configure email diff --git a/gluon/utils.py b/gluon/utils.py index e5b481b9..5b07eed5 100644 --- a/gluon/utils.py +++ b/gluon/utils.py @@ -23,7 +23,7 @@ import logging import socket import base64 import zlib - +import types _struct_2_long_long = struct.Struct('=QQ') @@ -351,3 +351,28 @@ def getipaddrinfo(host): and isinstance(addrinfo[4][0], basestring)] except socket.error: return [] + +def obj2dict(obj, processed=None): + """ + converts any objet into a dict, recursively + """ + processed = processed if not processed is None else set() + if obj is None: + return None + if isinstance(obj,(int,long,str,unicode,float,bool)): + return obj + if id(obj) in processed: + return '' + processed.add(id(obj)) + if isinstance(obj,(list,tuple)): + return [obj2dict(item,processed) for item in obj] + if not isinstance(obj, dict) and hasattr(obj,'__dict__'): + obj = obj.__dict__ + else: + return repr(obj) + return dict((key,obj2dict(value,processed)) for key,value in obj.items() + if not key.startswith('_') and + not type(value) in (types.FunctionType, + types.LambdaType, + types.BuiltinFunctionType, + types.BuiltinMethodType))