was a yatl bug in len(XML(''))
now fixed in yatl
On Saturday, 15 June 2019 00:56:45 UTC-7, 黄祥 wrote:
>
> *work in web2py*
> def json_row_as_list():
> if not request.env.request_method == 'GET': raise HTTP(403)
> import json
> table_name = request.args(0)
> id = request.args(1)
> if id.isdigit() and int(id) > 0:
> query = (db[table_name]['id'] == id)
> else:
> query = (db[table_name]['id'] > 0)
> rows = db(query).select()
> json_list = json.dumps(rows.as_list(), default = str, sort_keys = True
> )
> return dict(data = XML(json_list) )
>
> *in web3py return an error when using XML() helper, but when not using
> XML() helper it works fine in web3py*
> *code*
> from yatl.helpers import XML
> @action('api/json_row_as_list/<table_name>/<id>', method = 'GET')
> @action.uses(db)
> def json_row_as_list(table_name, id):
> import json
> if id.isdigit() and int(id) > 0:
> query = (db[table_name]['id'] == id)
> else:
> query = (db[table_name]['id'] > 0)
> row = db(query).select()
> json_list = json.dumps(row.as_list(), default = str, sort_keys = True)
> return dict(data = XML(json_list) )
>
> *result*
> ERROR:root:Traceback (most recent call last):
> File "/Users/sugizo/learn/python/web3py/web3py/core.py", line 416, in
> wrapper
> ret = dumps(ret)
> File "/Users/sugizo/learn/python/web3py/web3py/core.py", line 157, in
> dumps
> return json.dumps(obj, default=objectify, sort_keys=sort_keys, indent=
> indent)
> File
> "/Users/sugizo/miniconda3/envs/python3_test/lib/python3.7/json/__init__.py"
> , line 238, in dumps
> **kw).encode(obj)
> File
> "/Users/sugizo/miniconda3/envs/python3_test/lib/python3.7/json/encoder.py"
> , line 201, in encode
> chunks = list(chunks)
> File
> "/Users/sugizo/miniconda3/envs/python3_test/lib/python3.7/json/encoder.py"
> , line 431, in _iterencode
> yield from _iterencode_dict(o, _current_indent_level)
> File
> "/Users/sugizo/miniconda3/envs/python3_test/lib/python3.7/json/encoder.py"
> , line 405, in _iterencode_dict
> yield from chunks
> File
> "/Users/sugizo/miniconda3/envs/python3_test/lib/python3.7/json/encoder.py"
> , line 438, in _iterencode
> o = _default(o)
> File "/Users/sugizo/learn/python/web3py/web3py/core.py", line 146, in
> objectify
> return list(obj)
> File
> "/Users/sugizo/miniconda3/envs/python3_test/lib/python3.7/site-packages/yatl/helpers.py"
> , line 226, in __len__
> return len(str(self))
> File
> "/Users/sugizo/miniconda3/envs/python3_test/lib/python3.7/site-packages/yatl/helpers.py"
> , line 226, in __len__
> return len(str(self))
> File
> "/Users/sugizo/miniconda3/envs/python3_test/lib/python3.7/site-packages/yatl/helpers.py"
> , line 226, in __len__
> return len(str(self))
> [Previous line repeated 482 more times]
> RecursionError: maximum recursion depth exceeded while calling a Python
> object
>
> *code*
> from yatl.helpers import XML
> @action('api/json_row_as_list/<table_name>/<id>', method = 'GET')
> @action.uses(db)
> def json_row_as_list(table_name, id):
> import json
> if id.isdigit() and int(id) > 0:
> query = (db[table_name]['id'] == id)
> else:
> query = (db[table_name]['id'] > 0)
> row = db(query).select()
> json_list = json.dumps(row<span style="color: #660;" class="s
>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/web2py/bc03d136-fb59-4222-b93b-11b2d336d940%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.