Skip to content

Commit

Permalink
fix py3.5 xmlescape with bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
ilvalle committed Sep 9, 2016
1 parent b84b47d commit 2ec0c0b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
6 changes: 3 additions & 3 deletions gluon/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import base64
from gluon import sanitizer, decoder
import itertools
from gluon._compat import reduce, pickle, copyreg, HTMLParser, name2codepoint, iteritems, unichr, unicodeT, urllib_quote, to_bytes, to_native, to_unicode, basestring, urlencode, implements_bool
from gluon._compat import reduce, pickle, copyreg, HTMLParser, name2codepoint, iteritems, unichr, unicodeT, urllib_quote, to_bytes, to_native, to_unicode, basestring, urlencode, implements_bool, text_type
from gluon.utils import local_html_escape
import marshal

Expand Down Expand Up @@ -122,7 +122,7 @@ def xmlescape(data, quote=True):
if hasattr(data, 'xml') and callable(data.xml):
return to_bytes(data.xml())

if not(isinstance(data, basestring)):
if not(isinstance(data, (text_type, bytes))):
# i.e., integers
data=str(data)
data = to_bytes(data, 'utf8', 'xmlcharrefreplace')
Expand Down Expand Up @@ -1040,7 +1040,7 @@ def elements(self, *args, **kargs):
hello
>>> a.elements('a[u:v=$]')[0].xml()
'<a id="1-1" u:v="$">hello</a>'
>>> a=FORM( INPUT(_type='text'), SELECT(range(1)), TEXTAREA() )
>>> a=FORM( INPUT(_type='text'), SELECT(list(range(1))), TEXTAREA() )
>>> for c in a.elements('input, select, textarea'): c['_disabled'] = 'disabled'
>>> a.xml()
'<form action="#" enctype="multipart/form-data" method="post"><input disabled="disabled" type="text" /><select disabled="disabled"><option value="0">0</option></select><textarea cols="40" disabled="disabled" rows="10"></textarea></form>'
Expand Down
1 change: 1 addition & 0 deletions gluon/tests/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ def test_DIV(self):

# test .get('attrib')
self.assertEqual(DIV('<p>Test</p>', _class="class_test").get('_class'), 'class_test')
self.assertEqual(DIV(b'a').xml(), b'<div>a</div>')

def test_CAT(self):
# Empty CAT()
Expand Down

0 comments on commit 2ec0c0b

Please sign in to comment.