Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
| "(?:[^"\\]|\\.)*?(?:"|$) # "string"
))
| ([(,]\s*[A-Za-z_]\w*\s*=) # named argument (group 2)
| ([A-Za-z_]\w*(?:\s*\.\s*[A-Za-z_]\w*)*) # identifier chain (group 3)
| (\#.*$) # comment (group 4)
""", re.VERBOSE)
ident_re = re.compile(r'[A-Za-z_]\w*')
end1_re = re.compile(r"(?:[^\\]|\\.)*?'''")
end2_re = re.compile(r'(?:[^\\]|\\.)*?"""')
ident_html = Html('<span title="%s" class="ident">%s</span>')
keyword_html = Html('<strong>%s</strong>')
comment_html = Html('<span class="comment">%s</span>')
str_html = Html('<span class="string">%s</span>')
syntax_error_html = Html('<span class="syntax-error">%s</span>')
def parse_line(line):
pos = 0
stop = len(line)
while pos < stop:
match = python_re.search(line, pos)
if match is None: break
start, end = match.span()
yield 'other', pos, start, line[pos:start]
i = match.lastindex
if i == 1: yield 'string', start, end, match.group()
elif i == 2: yield 'other', start, end, match.group()
elif i == 3:
pos = start
for x in re.split('(\W+)', match.group()):
| "(?:[^"\\]|\\.)*?(?:"|$) # "string"
))
| ([(,]\s*[A-Za-z_]\w*\s*=) # named argument (group 2)
| ([A-Za-z_]\w*(?:\s*\.\s*[A-Za-z_]\w*)*) # identifier chain (group 3)
| (\#.*$) # comment (group 4)
""", re.VERBOSE)
ident_re = re.compile(r'[A-Za-z_]\w*')
end1_re = re.compile(r"(?:[^\\]|\\.)*?'''")
end2_re = re.compile(r'(?:[^\\]|\\.)*?"""')
ident_html = Html('<span title="%s" class="ident">%s</span>')
keyword_html = Html('<strong>%s</strong>')
comment_html = Html('<span class="comment">%s</span>')
str_html = Html('<span class="string">%s</span>')
syntax_error_html = Html('<span class="syntax-error">%s</span>')
def parse_line(line):
pos = 0
stop = len(line)
while pos < stop:
match = python_re.search(line, pos)
if match is None: break
start, end = match.span()
yield 'other', pos, start, line[pos:start]
i = match.lastindex
if i == 1: yield 'string', start, end, match.group()
elif i == 2: yield 'other', start, end, match.group()
elif i == 3:
pos = start
for x in re.split('(\W+)', match.group()):
def tag(composite):
result = [ Html('\n') ]
if composite.show_headers:
for i, field in enumerate(composite.fields):
if isinstance(field, Submit): label = Html(' ')
else: label = field._get_label(colon=False)
result.append(Html('') % label)
result.append(Html('\n'))
for i, field in enumerate(composite.fields):
result.append(Html('') % field.tag)
result.append(Html('\n<table><tbody><tr><th>%s</th></tr><tr><td>%s</td></tr></tbody></table>\n'))
return htmljoin(result)
def __unicode__(composite):
def __add__(self, x):
return Html(unicode.__add__(self, quote(x, True)))
def __radd__(self, x):
def postprocess(content, stylesheets, component_stylesheets, scripts):
assert isinstance(content, basestring)
if isinstance(content, (Html, StrHtml)): pass
elif isinstance(content, str): content = StrHtml(content)
elif isinstance(content, unicode): content = Html(content)
if not stylesheets: stylesheets = options.STD_STYLESHEETS
base_css = css_links(stylesheets)
if base_css: base_css += StrHtml('\n')
component_css = css_links(component_stylesheets)
if component_css: component_css += StrHtml('\n')
scripts = script_links(scripts)
if scripts: scripts += StrHtml('\n')
doctype = ''
try:
match = element_re.search(content)
if match is None or match.group(2).lower() not in header_tags:
doctype = StrHtml(options.STD_DOCTYPE)
'''(?:[^\\]|\\.)*?(?:'''|\Z) # '''triple-quoted string'''
| \"""(?:[^\\]|\\.)*?(?:\"""|\Z) # \"""triple-quoted string\"""
| '(?:[^'\\]|\\.)*?(?:'|$) # 'string'
| "(?:[^"\\]|\\.)*?(?:"|$) # "string"
))
| ([(,]\s*[A-Za-z_]\w*\s*=) # named argument (group 2)
| ([A-Za-z_]\w*(?:\s*\.\s*[A-Za-z_]\w*)*) # identifier chain (group 3)
| (\#.*$) # comment (group 4)
""", re.VERBOSE)
ident_re = re.compile(r'[A-Za-z_]\w*')
end1_re = re.compile(r"(?:[^\\]|\\.)*?'''")
end2_re = re.compile(r'(?:[^\\]|\\.)*?"""')
ident_html = Html('<span title="%s" class="ident">%s</span>')
keyword_html = Html('<strong>%s</strong>')
comment_html = Html('<span class="comment">%s</span>')
str_html = Html('<span class="string">%s</span>')
syntax_error_html = Html('<span class="syntax-error">%s</span>')
def parse_line(line):
pos = 0
stop = len(line)
while pos < stop:
match = python_re.search(line, pos)
if match is None: break
start, end = match.span()
yield 'other', pos, start, line[pos:start]
i = match.lastindex
if i == 1: yield 'string', start, end, match.group()
elif i == 2: yield 'other', start, end, match.group()
def _get_label(field, colon=True, required=True):
if not field._label: return ''
if not (required and field.required): required_html = ''
else: required_html = Html('<sup class="required">*</sup>')
colon_html = Html('<span class="colon">:</span>') if colon else ''
return Html('<label for="%s">%s%s%s</label>') % (
field.attrs['id'], field._label, required_html, colon_html)
def _set_label(field, label):
def tag(composite):
result = [ Html('\n') ]
if composite.show_headers:
for i, field in enumerate(composite.fields):
if isinstance(field, Submit): label = Html(' ')
else: label = field._get_label(colon=False)
result.append(Html('') % label)
result.append(Html('\n'))
for i, field in enumerate(composite.fields):
result.append(Html('') % field.tag)
result.append(Html('\n<table><tbody><tr><th>%s</th></tr><tr><td>%s</td></tr></tbody></table>\n'))
return htmljoin(result)
def __unicode__(composite):
def html(*args, **kwargs):
return _template(Html, '.html', *args, **kwargs)
content_type = headers.get('Content-Type')
if content_type:
media_type, type_params = cgi.parse_header(content_type)
charset = type_params.get('charset', 'iso-8859-1')
else:
if media_type is None: media_type = getattr(result, 'media_type', None)
if media_type is None:
if isinstance(content, (Html, StrHtml)): media_type = 'text/html'
else: media_type = 'text/plain'
if charset is None: charset = getattr(result, 'charset', 'UTF-8')
content_type = '%s; charset=%s' % (media_type, charset)
headers['Content-Type'] = content_type
if hasattr(content, 'read') \
or media_type != 'text/html' \
or isinstance(content, (Html, StrHtml)): pass
elif isinstance(content, unicode): content = Html(content)
elif isinstance(content, str): content = StrHtml(content)
else: assert False # pragma: no cover
return content, headers