本文整理汇总了Python中py.xml.html.head函数的典型用法代码示例。如果您正苦于以下问题:Python head函数的具体用法?Python head怎么用?Python head使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了head函数的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: suite_start
def suite_start(self, data):
self.suite_times["start"] = data["time"]
self.suite_name = data["source"]
with open(os.path.join(base_path, "style.css")) as f:
self.head = html.head(
html.meta(charset="utf-8"),
html.title(data["source"]),
html.style(raw(f.read())))
示例4: create_head
def create_head(self):
return html.head(
html.title('source view'),
html.style("""
body, td {
background-color: #FFF;
color: black;
font-family: monospace, Monaco;
}
table, tr {
margin: 0px;
padding: 0px;
border-width: 0px;
}
a {
color: blue;
font-weight: bold;
text-decoration: none;
}
a:hover {
color: #005;
}
.lineno {
text-align: right;
color: #555;
width: 3em;
padding-right: 1em;
border: 0px solid black;
border-right-width: 1px;
}
.code {
padding-left: 1em;
white-space: pre;
}
.comment {
color: purple;
}
.string {
color: #777;
}
.keyword {
color: blue;
}
.alt_keyword {
color: green;
}
""", type='text/css'),
)
示例5: 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)
示例6: make_head
def make_head(self):
with open(os.path.join(here, "report.css")) as f:
style = html.style(raw(f.read()))
return html.head(
html.meta(charset="utf-8"),
html.title("FirefoxOS Certification Suite Report: %s" % self.results.name),
style
)
示例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
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))
示例8: simple_html_body
def simple_html_body(title, bodytags):
return html.html(
html.head(
html.title(title)
),
html.body(
html.h1(title),
*bodytags
)
)
示例9: 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))
示例10: 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
)
)
示例11: 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()
示例12: make_head
def make_head(self):
with open(os.path.join(here, "report.css")) as f:
style = html.style(raw(f.read()))
return html.head(
html.meta(charset="utf-8"),
html.title("FirefoxOS Certification Suite Report"),
html.style(raw(pkg_resources.resource_string(
rcname, os.path.sep.join(['resources', 'htmlreport',
'style.css']))),
type='text/css'),
style
)
示例13: __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"))
示例14: 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()
示例15: 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)