本文整理汇总了Python中py.xml.html.html函数的典型用法代码示例。如果您正苦于以下问题:Python html函数的具体用法?Python html怎么用?Python html使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了html函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _generate_html
def _generate_html(pages):
"""Generate html for given pages.
:param pages: list of `Page.class`
:return: path to tempdir.
:rtype: string.
"""
tempdir = tempfile.mkdtemp()
doc = html.html(
html.head(
# python don't allow keyword args with hypens
html.meta(content="text/html; charset=utf-8", **{"http-equiv": "Content-Type"}),
_get_tile(html, pages)
),
html.body(
html.div(_generate_body(html, pages, tempdir), id='article'),
)
)
with open(os.path.join(tempdir, 'histmag.html'), 'wb') as out_file:
logger.debug(
'Saving generated html to {file}'.format(file=os.path.join(tempdir, 'histmag.html'))
)
out_file.write(doc.unicode(indent=2).encode('utf8'))
return tempdir
示例2: make_html_report
def make_html_report(path, report):
def tabelize(value):
try:
rows = []
for key in value.keys():
rows.append(html.tr(html.td(html.pre(key)), html.td(tabelize(value[key]))))
return html.table(rows)
except AttributeError:
if type(value) == type([]):
return html.table(map(tabelize, value))
else:
return html.pre(value)
body_els = []
keys = report.keys()
keys.sort()
links = []
for key in keys:
links.append(html.li(html.a(key, href="#" + key)))
body_els.append(html.ul(links))
for key in keys:
body_els.append(html.a(html.h1(key), id=key))
body_els.append(tabelize(report[key]))
with open(path, 'w') as f:
doc = html.html(html.head(html.style('table, td {border: 1px solid;}')), html.body(body_els))
f.write(str(doc))
示例3: make_report
def make_report(self, time, summary_results, subsuite_results):
self.time = time
self.summary_results = summary_results
self.subsuite_results = subsuite_results
return html.html(
self.make_head(),
self.make_body()
)
示例4: startDocument
def startDocument(self):
h = html.html()
self.head = head = html.head()
self.title = title = html.title(self.title)
self._push(h)
h.append(head)
h.append(title)
self.body = body = html.body()
self._push(body)
示例5: simple_list_project
def simple_list_project(self):
request = self.request
name = self.context.name
# we only serve absolute links so we don't care about the route's slash
abort_if_invalid_projectname(request, name)
stage = self.context.stage
if stage.get_projectname(name) is None:
# we return 200 instead of !=200 so that pip/easy_install don't
# ask for the full simple page although we know it doesn't exist
# XXX change that when pip-6.0 is released?
abort(request, 200, "no such project %r" % name)
projectname = self.context.projectname
try:
result = stage.get_releaselinks(projectname)
except stage.UpstreamError as e:
threadlog.error(e.msg)
abort(request, 502, e.msg)
links = []
for link in result:
relpath = link.entrypath
href = "/" + relpath
href = URL(request.path_info).relpath(href)
if link.eggfragment:
href += "#egg=%s" % link.eggfragment
elif link.hash_spec:
href += "#" + link.hash_spec
links.extend([
"/".join(relpath.split("/", 2)[:2]) + " ",
html.a(link.basename, href=href),
html.br(), "\n",
])
title = "%s: links for %s" % (stage.name, projectname)
if stage.has_pypi_base(projectname):
refresh_title = "Refresh" if stage.ixconfig["type"] == "mirror" else \
"Refresh PyPI links"
refresh_url = request.route_url(
"/{user}/{index}/+simple/{name}/refresh",
user=self.context.username, index=self.context.index,
name=projectname)
refresh_form = [
html.form(
html.input(
type="submit", value=refresh_title, name="refresh"),
action=refresh_url,
method="post"),
"\n"]
else:
refresh_form = []
return Response(html.html(
html.head(
html.title(title)),
html.body(
html.h1(title), "\n",
refresh_form,
links)).unicode(indent=2))
示例6: simple_html_body
def simple_html_body(title, bodytags):
return html.html(
html.head(
html.title(title)
),
html.body(
html.h1(title),
*bodytags
)
)
示例7: simple_list_project
def simple_list_project(self):
request = self.request
name = self.context.name
# we only serve absolute links so we don't care about the route's slash
abort_if_invalid_projectname(request, name)
stage = self.context.stage
projectname = stage.get_projectname(name)
if projectname is None:
abort(request, 200, "no such project %r" % projectname)
if name != projectname:
redirect("/%s/+simple/%s/" % (stage.name, projectname))
try:
result = stage.get_releaselinks(projectname)
except stage.UpstreamError as e:
threadlog.error(e.msg)
abort(request, 502, e.msg)
links = []
for link in result:
relpath = link.entrypath
href = "/" + relpath
href = URL(request.path).relpath(href)
if link.eggfragment:
href += "#egg=%s" % link.eggfragment
elif link.md5:
href += "#md5=%s" % link.md5
links.extend([
"/".join(relpath.split("/", 2)[:2]) + " ",
html.a(link.basename, href=href),
html.br(), "\n",
])
title = "%s: links for %s" % (stage.name, projectname)
if stage.has_pypi_base(projectname):
refresh_title = "Refresh" if stage.ixconfig["type"] == "mirror" else \
"Refresh PyPI links"
refresh_url = request.route_url(
"/{user}/{index}/+simple/{name}/refresh",
user=self.context.username, index=self.context.index,
name=projectname)
refresh_form = [
html.form(
html.input(
type="submit", value=refresh_title, name="refresh"),
action=refresh_url,
method="post"),
"\n"]
else:
refresh_form = []
return Response(html.html(
html.head(
html.title(title)),
html.body(
html.h1(title), "\n",
refresh_form,
links)).unicode(indent=2))
示例8: simple_html_body
def simple_html_body(title, bodytags, extrahead=""):
return html.html(
html.head(
html.title(title),
extrahead,
),
html.body(
html.h1(title), "\n",
bodytags
)
)
示例9: create_unknown_html
def create_unknown_html(path):
h = html.html(
html.head(
html.title('Can not display page'),
style,
),
html.body(
html.p('The data URL (%s) does not contain Python code.' % (path,))
),
)
return h.unicode()
示例10: __init__
def __init__(self, title=None):
self.body = html.body()
self.head = html.head()
self.doc = html.html(self.head, self.body)
if title is not None:
self.head.append(
html.meta(name="title", content=title))
self.head.append(
html.link(rel="Stylesheet", type="text/css", href="MochiKit-1.1/examples/sortable_tables/sortable_tables.css"))
self.head.append(
html.script(rel="JavaScript", type="text/javascript", src="MochiKit-1.1/lib/MochiKit/MochiKit.js"))
self.head.append(
html.script(rel="JavaScript", type="text/javascript", src="MochiKit-1.1/examples/sortable_tables/sortable_tables.js"))
示例11: pytest_sessionfinish
def pytest_sessionfinish(self, session, exitstatus):
self._make_report_dir()
logfile = py.std.codecs.open(self.logfile, 'w', encoding='utf-8')
suite_stop_time = time.time()
suite_time_delta = suite_stop_time - self.suite_start_time
numtests = self.passed + self.failed
generated = datetime.datetime.now()
doc = html.html(
html.head(
html.meta(charset='utf-8'),
html.title('Test Report'),
html.link(rel='stylesheet', href='style.css'),
html.script(src='jquery.js'),
html.script(src='main.js')),
html.body(
html.p('Report generated on %s at %s ' % (
generated.strftime('%d-%b-%Y'),
generated.strftime('%H:%M:%S'),
)),
html.div([html.p(
html.span('%i tests' % numtests, class_='all clickable'),
' ran in %i seconds.' % suite_time_delta,
html.br(),
html.span('%i passed' % self.passed, class_='passed clickable'), ', ',
html.span('%i skipped' % self.skipped, class_='skipped clickable'), ', ',
html.span('%i failed' % self.failed, class_='failed clickable'), ', ',
html.span('%i errors' % self.errors, class_='error clickable'), '.',
html.br(), ),
html.span('Hide all errors', class_='clickable hide_all_errors'), ', ',
html.span('Show all errors', class_='clickable show_all_errors'),
], id='summary-wrapper'),
html.div(id='summary-space'),
html.table([
html.thead(html.tr([
html.th('Result', class_='sortable', col='result'),
html.th('Class', class_='sortable', col='class'),
html.th('Name', class_='sortable', col='name'),
html.th('Duration', class_='sortable numeric', col='duration'),
# html.th('Output')]), id='results-table-head'),
html.th('Links')]), id='results-table-head'),
html.tbody(*self.test_logs, id='results-table-body')], id='results-table')))
logfile.write(
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">' + doc.unicode(
indent=2))
logfile.close()
self.process_screenshot_files()
self.process_debug_event_files()
self.process_performance_files()
示例12: __init__
def __init__(self, encoding, tokenizer=None):
self.encoding = encoding
self.html = root = html.html()
self.head = head = self.create_head()
root.append(head)
self.body = body = self.create_body()
root.append(body)
self.table, self.tbody = table, tbody = self.create_table()
body.append(table)
if tokenizer is None:
tokenizer = Tokenizer(PythonSchema)
self.tokenizer = tokenizer
示例13: create_dir_html
def create_dir_html(path, href_prefix=''):
h = html.html(
html.head(
html.title('directory listing of %s' % (path,)),
style,
),
)
body = html.body(
html.h1('directory listing of %s' % (path,)),
)
h.append(body)
table = html.table()
body.append(table)
tbody = html.tbody()
table.append(tbody)
items = list(path.listdir())
items.sort(key=lambda p: p.basename)
items.sort(key=lambda p: not p.check(dir=True))
for fpath in items:
tr = html.tr()
tbody.append(tr)
td1 = html.td(fpath.check(dir=True) and 'D' or 'F', class_='type')
tr.append(td1)
href = fpath.basename
if href_prefix:
href = '%s%s' % (href_prefix, href)
if fpath.check(dir=True):
href += '/'
td2 = html.td(html.a(fpath.basename, href=href), class_='name')
tr.append(td2)
td3 = html.td(time.strftime('%Y-%m-%d %H:%M:%S',
time.gmtime(fpath.mtime())), class_='mtime')
tr.append(td3)
if fpath.check(dir=True):
size = ''
unit = ''
else:
size = fpath.size()
unit = 'B'
for u in ['kB', 'MB', 'GB', 'TB']:
if size > 1024:
size = round(size / 1024.0, 2)
unit = u
td4 = html.td('%s %s' % (size, unit), class_='size')
tr.append(td4)
return unicode(h)
示例14: findlinks_view
def findlinks_view(context, request):
title = "%s: all package links without root/pypi" % (context.stage.name)
projectnames = set()
for stage, names in context.stage.op_sro("list_projectnames_perstage"):
if stage.ixconfig["type"] == "mirror":
continue
projectnames.update(names)
all_links = []
basenames = set()
for projectname in sorted(projectnames):
for stage, res in context.stage.op_sro_check_pypi_whitelist(
"get_releaselinks_perstage", projectname=projectname):
if stage.ixconfig["type"] == "mirror":
continue
for link in res:
if link.eggfragment:
key = link.eggfragment
else:
key = link.basename
if key not in basenames:
basenames.add(key)
all_links.append(link)
links = []
for link in sorted(all_links, key=attrgetter('basename')):
href = url_for_entrypath(request, link.entrypath)
entry = link.entry
if entry.eggfragment:
href += "#egg=%s" % entry.eggfragment
elif entry.md5:
href += "#md5=%s" % entry.md5
links.extend([
"/".join(link.entrypath.split("/", 2)[:2]) + " ",
html.a(link.basename, href=href),
html.br(), "\n"])
if not links:
links = [html.p('No releases.')]
return Response(html.html(
html.head(
html.title(title)),
html.body(
html.h1(title), "\n",
links)).unicode(indent=2))
示例15: generate_html
def generate_html(self):
generated = datetime.utcnow()
with open(os.path.join(base_path, "main.js")) as main_f:
doc = html.html(
self.head,
html.body(
html.script(raw(main_f.read())),
html.p('Report generated on %s at %s' % (
generated.strftime('%d-%b-%Y'),
generated.strftime('%H:%M:%S'))),
html.h2('Environment'),
html.table(
[html.tr(html.td(k), html.td(v)) for k, v in sorted(self.env.items()) if v],
id='environment'),
html.h2('Summary'),
html.p('%i tests ran in %.1f seconds.' % (sum(self.test_count.itervalues()),
(self.suite_times["end"] -
self.suite_times["start"]) / 1000.),
html.br(),
html.span('%i passed' % self.test_count["PASS"], class_='pass'), ', ',
html.span('%i skipped' % self.test_count["SKIP"], class_='skip'), ', ',
html.span('%i failed' % self.test_count["UNEXPECTED_FAIL"], class_='fail'), ', ',
html.span('%i errors' % self.test_count["UNEXPECTED_ERROR"], class_='error'), '.',
html.br(),
html.span('%i expected failures' % self.test_count["EXPECTED_FAIL"],
class_='expected_fail'), ', ',
html.span('%i unexpected passes' % self.test_count["UNEXPECTED_PASS"],
class_='unexpected_pass'), '.'),
html.h2('Results'),
html.table([html.thead(
html.tr([
html.th('Result', class_='sortable', col='result'),
html.th('Test', class_='sortable', col='name'),
html.th('Duration', class_='sortable numeric', col='duration'),
html.th('Links')]), id='results-table-head'),
html.tbody(self.result_rows, id='results-table-body')], id='results-table')))
return u"<!DOCTYPE html>\n" + doc.unicode(indent=2)