From 5a560fee8aaac37304188d601c38749e5569a82f Mon Sep 17 00:00:00 2001 From: mdipierro Date: Sat, 9 Mar 2013 00:17:56 -0600 Subject: [PATCH] cleaned up examples/controller/global.py --- VERSION | 2 +- applications/examples/controllers/global.py | 90 +++++++------------- applications/examples/views/global/vars.html | 77 +++++++++-------- 3 files changed, 76 insertions(+), 93 deletions(-) diff --git a/VERSION b/VERSION index 115d9c95..5753981f 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -Version 2.4.2-stable+timestamp.2013.03.08.19.22.01 +Version 2.4.2-stable+timestamp.2013.03.09.00.16.49 diff --git a/applications/examples/controllers/global.py b/applications/examples/controllers/global.py index a186037c..f1571c4d 100644 --- a/applications/examples/controllers/global.py +++ b/applications/examples/controllers/global.py @@ -4,72 +4,48 @@ response.menu = [['home', False, '/%s/default/index' % request.application], ['docs', True, '/%s/global/vars' % request.application]] - +def get(args): + try: + obj = globals(),get(args[0]) + for k in range(1,len(args)): + obj = getattr(obj,args[k]) + return obj + except: + return None + def vars(): """the running controller function!""" - + title = '.'.join(request.args) + attributes = {} if not request.args: - ( - doc, - keys, - t, - c, - d, - value, - ) = ( - 'Global variables', - globals(), - None, - None, - (), - None, - ) - (title, args) = ('globals()', '') + (doc,keys,t,c,d,value)=('Global variables',globals(),None,None,[],None) elif len(request.args) < 3: - args = '.'.join(request.args) - try: - doc = eval(args + '.__doc__') - except: - doc = 'no documentation' - try: - keys = eval('dir(%s)' % args) - except: + obj = get(request.args) + if obj: + doc = getattr(obj,'__doc__','no documentation') + keys = dir(obj) + t = type(obj) + c = getattr(obj,'__class__',None) + d = getattr(obj,'__bases__',None) + + for key in keys: + a = getattr(obj,key,None) + if a and not isinstance(a,DAL): + doc1 = getattr(a, '__doc__', '') + t1 = type(a) + c1 = getattr(a,'__class__',None) + d1 = getattr(a,'__bases__',None) + key = '.'.join(request.args)+'.'+key + attributes[key] = (doc1, t1, c1, d1) + else: + doc = 'Unkown' keys = [] - t = eval('type(%s)' % args) - try: - c = eval('%s.__class__' % args) - except: - c = None - try: - d = eval('%s.__bases__' % args) - except: - d = None - title = args - args += '.' + t = c = d = None else: raise HTTP(400) - attributes = {} - for key in keys: - a = args + key - if eval('isinstance(%s,SQLDB)' % a) or a == 'vars': - continue - try: - doc1 = eval(a + '.__doc__') - except: - doc1 = 'no documentation' - t1 = eval('type(%s)' % a) - try: - c1 = eval('%s.__class__' % a) - except: - c1 = None - try: - d1 = eval('%s.__bases__' % a) - except: - d1 = () - attributes[a] = (doc1, t1, c1, d1) return dict( title=title, - args=args, + args=request.args, t=t, c=c, d=d, diff --git a/applications/examples/views/global/vars.html b/applications/examples/views/global/vars.html index 04f928b0..f0806fe6 100644 --- a/applications/examples/views/global/vars.html +++ b/applications/examples/views/global/vars.html @@ -2,46 +2,53 @@ {{import cgi}}
-

{{=T('Docs for')}} {{=title}}

- -
+

{{=T('Docs for')}} {{=title}}

+ +
[ Python Tutorial ] [ Python Libraries ] [ web2py epydoc ] -
- -

{{=T('Description')}}

- -
- {{if t:}} - {{=t}}{{if d:}} extends {{=d}}{{pass}} - {{pass}} -
- {{pass}} - - {{if doc:}}

{{=CODE(str(doc),language=None,counter=None,_class='boxCode')}}{{pass}} -

-
+
+ +

{{=T('Description')}}

+ +
+ {{if t:}} + {{=t}}{{if d:}} extends {{=d}}{{pass}} + {{pass}} +
+ {{pass}} + + {{if doc:}}

{{=CODE(str(doc),language=None,counter=None,_class='boxCode')}}{{pass}} +

+
+ {{if attributes:}}

{{=T('Attributes')}}

- - {{keys=attributes.keys(); keys.sort()}} + - - {{for a in keys:}} - {{doc1,t1,c1,d1=attributes[a]}} - - - + {{for key in sorted(attributes):}} + {{doc1,t1,c1,d1=attributes[key]}} + + + - - - {{pass}} + + + {{pass}}

{{#=a}}{{=A(a,_href=URL(r=request,args=a.split('.')))}} - {{if t1:}} - {{=t1}}{{if d1:}} extends {{=d1}}{{pass}} - {{if c1:}} belongs to class {{=c1}}{{pass}} -
- {{pass}} - {{if doc1:}}{{=XML(cgi.escape(str(doc1)).replace(chr(13),'
'))}}{{pass}} +

+ {{if key.count('.')<2:}} + {{=A(key,_href=URL(args=key.split('.')))}} + {{else:}} + {{=key}} + {{pass}} + + {{if t1:}} + {{=t1}}{{if d1:}} extends {{=d1}}{{pass}} + {{if c1:}} belongs to class {{=c1}}{{pass}} +
+ {{pass}} + {{if doc1:}}{{=XML(cgi.escape(str(doc1)).replace(chr(13),'
'))}}{{pass}}


-
+
+ {{pass}}