Merge pull request #1662 from BuhtigithuB/improve/pep8-html-py
Enhance html.py PEP8
This commit is contained in:
@@ -20,7 +20,8 @@ import urllib
|
||||
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, text_type, long
|
||||
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, long
|
||||
from gluon.utils import local_html_escape
|
||||
import marshal
|
||||
|
||||
@@ -109,6 +110,7 @@ __all__ = [
|
||||
|
||||
DEFAULT_PASSWORD_DISPLAY = '*' * 8
|
||||
|
||||
|
||||
def xmlescape(data, quote=True):
|
||||
"""
|
||||
Returns an escaped string of the provided data
|
||||
@@ -124,10 +126,9 @@ def xmlescape(data, quote=True):
|
||||
|
||||
if not(isinstance(data, (text_type, bytes))):
|
||||
# i.e., integers
|
||||
data=str(data)
|
||||
data = str(data)
|
||||
data = to_bytes(data, 'utf8', 'xmlcharrefreplace')
|
||||
|
||||
|
||||
# ... and do the escaping
|
||||
data = local_html_escape(data, quote)
|
||||
return data
|
||||
@@ -671,6 +672,7 @@ def XML_pickle(data):
|
||||
return XML_unpickle, (marshal.dumps(str(data)),)
|
||||
copyreg.pickle(XML, XML_pickle, XML_unpickle)
|
||||
|
||||
|
||||
@implements_bool
|
||||
class DIV(XmlComponent):
|
||||
"""
|
||||
@@ -1309,8 +1311,10 @@ class HTML(DIV):
|
||||
tag = b'html'
|
||||
|
||||
strict = b'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">\n'
|
||||
transitional = b'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">\n'
|
||||
frameset = b'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">\n'
|
||||
transitional = \
|
||||
b'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">\n'
|
||||
frameset = \
|
||||
b'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">\n'
|
||||
html5 = b'<!DOCTYPE HTML>\n'
|
||||
|
||||
def xml(self):
|
||||
@@ -1861,7 +1865,7 @@ class INPUT(DIV):
|
||||
except:
|
||||
import traceback
|
||||
print(traceback.format_exc())
|
||||
msg = "Validation error, field:%s %s" % (name,validator)
|
||||
msg = "Validation error, field:%s %s" % (name, validator)
|
||||
raise Exception(msg)
|
||||
if errors is not None:
|
||||
self.vars[name] = value
|
||||
@@ -1911,7 +1915,7 @@ class INPUT(DIV):
|
||||
name = self.attributes.get('_name', None)
|
||||
if name and hasattr(self, 'errors') \
|
||||
and self.errors.get(name, None) \
|
||||
and self['hideerror'] != True:
|
||||
and self['hideerror'] is not True:
|
||||
self['_class'] = (self['_class'] and self['_class'] + ' ' or '') + 'invalidinput'
|
||||
return DIV.xml(self) + DIV(
|
||||
DIV(
|
||||
@@ -1979,7 +1983,6 @@ class OPTGROUP(DIV):
|
||||
|
||||
|
||||
class SELECT(INPUT):
|
||||
|
||||
"""
|
||||
Examples:
|
||||
|
||||
@@ -2014,7 +2017,7 @@ class SELECT(INPUT):
|
||||
if value is not None:
|
||||
if not self['_multiple']:
|
||||
for c in options: # my patch
|
||||
if ((value is not None) and (str(c['_value']) == str(value))):
|
||||
if (value is not None) and (str(c['_value']) == str(value)):
|
||||
c['_selected'] = 'selected'
|
||||
else:
|
||||
c['_selected'] = None
|
||||
@@ -2024,7 +2027,7 @@ class SELECT(INPUT):
|
||||
else:
|
||||
values = [str(value)]
|
||||
for c in options: # my patch
|
||||
if ((value is not None) and (str(c['_value']) in values)):
|
||||
if (value is not None) and (str(c['_value']) in values):
|
||||
c['_selected'] = 'selected'
|
||||
else:
|
||||
c['_selected'] = None
|
||||
@@ -2390,7 +2393,6 @@ class FORM(DIV):
|
||||
|
||||
|
||||
class BEAUTIFY(DIV):
|
||||
|
||||
"""
|
||||
Turns any list, dictionary, etc into decent looking html.
|
||||
|
||||
@@ -2547,7 +2549,7 @@ class MENU(DIV):
|
||||
li['_class'] = li['_class'] + ' ' + self['li_active']
|
||||
else:
|
||||
li['_class'] = self['li_active']
|
||||
if len(item) <= 4 or item[4] == True:
|
||||
if len(item) <= 4 or item[4] is True:
|
||||
ul.append(li)
|
||||
return ul
|
||||
|
||||
@@ -2561,7 +2563,7 @@ class MENU(DIV):
|
||||
# ex: ('', False, A('title', _href=URL(...), _title="title"))
|
||||
# ex: (A('title', _href=URL(...), _title="title"), False, None)
|
||||
custom_items.append(item)
|
||||
elif len(item) <= 4 or item[4] == True:
|
||||
elif len(item) <= 4 or item[4] is True:
|
||||
select.append(OPTION(CAT(prefix, item[0]),
|
||||
_value=item[2], _selected=item[1]))
|
||||
if len(item) > 3 and len(item[3]):
|
||||
@@ -2703,7 +2705,8 @@ class web2pyHTMLParser(HTMLParser):
|
||||
self.parent = self.parent.parent
|
||||
except:
|
||||
raise RuntimeError("unable to balance tag %s" % tagname)
|
||||
if parent_tagname[:len(tagname)] == tagname: break
|
||||
if parent_tagname[:len(tagname)] == tagname:
|
||||
break
|
||||
|
||||
|
||||
def markdown_serializer(text, tag=None, attr=None):
|
||||
|
||||
Reference in New Issue
Block a user