xml() error when BEAUTIFY globals()

29 views
Skip to first unread message

Lars

unread,
Mar 23, 2017, 3:46:33 PM3/23/17
to web2py-users
Hi,

Everything is in the title : I try to have a BEAUTIFY look at copy.copy(globals()) and I get an xml error line 131 in html.py :

data is empty for : return data.xml()

Why can't we beautify globals() ?

Thank you

Richard Vézina

unread,
Mar 23, 2017, 4:46:10 PM3/23/17
to web2py-users
Maybe because .xml() method of various web2py class in gluon.html and is intent to be used over markup type languages not python language :


You can search for "def xml(" on this page to see all the differents implementation...

Richard



--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Anthony

unread,
Mar 23, 2017, 7:08:16 PM3/23/17
to web2py-users
BEAUTIFY is not designed to take the entire global environment. The problem is that globals() includes all of the web2py HTML helper classes. Because BEAUTIFY is itself an HTML helper, it is serialized by recursively processing its components. The serialization process checks whether a given component has a callable "xml" attribute, and assuming such an attribute is an instance method, it attempts to call .xml(). The problem is the helper classes themselves do have a callable "xml" attribute, but it is not actually an instance method in that case (it is simply an attribute that belongs to the class itself) -- so calling it generates an exception.

You might try something like:

BEAUTIFY({k: v for k, v in globals().iteritems() if not hasattr(v, 'xml')})

But you're probably asking for trouble attempting to display the entire global environment.

Anthony

Richard Vézina

unread,
Mar 24, 2017, 11:18:50 AM3/24/17
to web2py-users
Thanks Anthony, clearer than my explanation.

Richard

--

Lars

unread,
Mar 24, 2017, 1:21:08 PM3/24/17
to web2py-users

I went for something even simpler : I bypass BEAUTIFUL.. I just wanted a view with everything named :
def my_beautify(component):
    t
= TABLE()
   
if isinstance(component, dict):
       
for k, v in component.iteritems():
           
if v is None or isinstance(v, (bool, str)):
                t
.append(TR([str(k), str(v), ' ']))
           
else:
                t
.append(TR([str(k), repr(v), str(dir(v))]))
   
return t

Thanks to both of you ! :)
Reply all
Reply to author
Forward
0 new messages