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