本文整理汇总了Python中py.xml.raw函数的典型用法代码示例。如果您正苦于以下问题:Python raw函数的具体用法?Python raw怎么用?Python raw使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了raw函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: append_log_html
def append_log_html(self, report, additional_html):
log = html.div(class_='log')
if report.longrepr:
for line in str(report.longrepr).splitlines():
if not PY3:
line = line.decode('utf-8')
separator = line.startswith('_ ' * 10)
if separator:
log.append(line[:80])
else:
exception = line.startswith("E ")
if exception:
log.append(html.span(raw(escape(line)),
class_='error'))
else:
log.append(raw(escape(line)))
log.append(html.br())
for header, content in report.sections:
log.append(' {0} '.format(header).center(80, '-'))
log.append(html.br())
log.append(content)
if len(log) == 0:
log = html.div(class_='empty log')
log.append('No log output captured.')
additional_html.append(log)
示例2: append_log_html
def append_log_html(self, report, additional_html):
log = html.div(class_='log')
if report.longrepr:
for line in report.longreprtext.splitlines():
separator = line.startswith('_ ' * 10)
if separator:
log.append(line[:80])
else:
exception = line.startswith("E ")
if exception:
log.append(html.span(raw(escape(line)),
class_='error'))
else:
log.append(raw(escape(line)))
log.append(html.br())
for section in report.sections:
header, content = map(escape, section)
log.append(' {0} '.format(header).center(80, '-'))
log.append(html.br())
if ANSI:
converter = Ansi2HTMLConverter(inline=False, escaped=False)
content = converter.convert(content, full=False)
log.append(raw(content))
if len(log) == 0:
log = html.div(class_='empty log')
log.append('No log output captured.')
additional_html.append(log)
示例3: _appendrow
def _appendrow(self, result, report):
time = getattr(report, 'duration', 0.0)
additional_html = []
links_html = []
for extra in getattr(report, 'extra', []):
href = None
if extra.get('format') == extras.FORMAT_IMAGE:
href = '#'
image = 'data:image/png;base64,%s' % extra.get('content')
additional_html.append(html.div(
html.a(html.img(src=image), href="#"),
class_='image'))
elif extra.get('format') == extras.FORMAT_HTML:
additional_html.append(extra.get('content'))
elif extra.get('format') == extras.FORMAT_JSON:
href = data_uri(json.dumps(extra.get('content')),
mime_type='application/json')
elif extra.get('format') == extras.FORMAT_TEXT:
href = data_uri(extra.get('content'))
elif extra.get('format') == extras.FORMAT_URL:
href = extra.get('content')
if href is not None:
links_html.append(html.a(
extra.get('name'),
class_=extra.get('format'),
href=href,
target='_blank'))
links_html.append(' ')
if 'Passed' not in result:
if report.longrepr:
log = html.div(class_='log')
for line in str(report.longrepr).splitlines():
if not PY3:
line = line.decode('utf-8')
separator = line.startswith('_ ' * 10)
if separator:
log.append(line[:80])
else:
exception = line.startswith("E ")
if exception:
log.append(html.span(raw(escape(line)),
class_='error'))
else:
log.append(raw(escape(line)))
log.append(html.br())
additional_html.append(log)
self.test_logs.append(html.tr([
html.td(result, class_='col-result'),
html.td(report.nodeid, class_='col-name'),
html.td('%.2f' % time, class_='col-duration'),
html.td(links_html, class_='col-links'),
html.td(additional_html, class_='extra')],
class_=result.lower() + ' results-table-row'))
示例4: make_result_html
def make_result_html(self, data):
tc_time = (data["time"] - self.start_times.pop(data["test"])) / 1000.
additional_html = []
debug = data.get("extra", {})
links_html = []
status = status_name = data["status"]
expected = data.get("expected", status)
if status != expected:
status_name = "UNEXPECTED_" + status
elif status != "PASS":
status_name = "EXPECTED_" + status
self.test_count[status_name] += 1
if status in ['SKIP', 'FAIL', 'ERROR']:
if debug.get('screenshot'):
screenshot = 'data:image/png;base64,%s' % debug['screenshot']
additional_html.append(html.div(
html.a(html.img(src=screenshot), href="#"),
class_='screenshot'))
for name, content in debug.items():
if 'screenshot' in name:
href = '#'
else:
# use base64 to avoid that some browser (such as Firefox, Opera)
# treats '#' as the start of another link if the data URL contains.
# use 'charset=utf-8' to show special characters like Chinese.
href = 'data:text/plain;charset=utf-8;base64,%s' % base64.b64encode(content.encode('utf-8'))
links_html.append(html.a(
name.title(),
class_=name,
href=href,
target='_blank'))
links_html.append(' ')
log = html.div(class_='log')
output = data.get('stack', '').splitlines()
output.extend(data.get('message', '').splitlines())
for line in output:
separator = line.startswith(' ' * 10)
if separator:
log.append(line[:80])
else:
if line.lower().find("error") != -1 or line.lower().find("exception") != -1:
log.append(html.span(raw(cgi.escape(line)), class_='error'))
else:
log.append(raw(cgi.escape(line)))
log.append(html.br())
additional_html.append(log)
self.result_rows.append(
html.tr([html.td(status_name, class_='col-result'),
html.td(data['test'], class_='col-name'),
html.td('%.2f' % tc_time, class_='col-duration'),
html.td(links_html, class_='col-links'),
html.td(additional_html, class_='debug')],
class_=status_name.lower() + ' results-table-row'))
示例5: _appendrow
def _appendrow(self, result, report):
time = getattr(report, 'duration', 0.0)
additional_html = []
links_html = []
if 'Passed' not in result:
for extra in getattr(report, 'extra', []):
href = None
if type(extra) is Image:
href = '#'
image = 'data:image/png;base64,%s' % extra.content
additional_html.append(html.div(
html.a(html.img(src=image), href="#"),
class_='image'))
elif type(extra) is HTML:
additional_html.append(extra.content)
elif type(extra) is Text:
href = 'data:text/plain;charset=utf-8;base64,%s' % \
b64encode(extra.content)
elif type(extra) is URL:
href = extra.content
if href is not None:
links_html.append(html.a(
extra.name,
class_=extra.__class__.__name__.lower(),
href=href,
target='_blank'))
links_html.append(' ')
if report.longrepr:
log = html.div(class_='log')
for line in str(report.longrepr).splitlines():
line = line.decode('utf-8')
separator = line.startswith('_ ' * 10)
if separator:
log.append(line[:80])
else:
exception = line.startswith("E ")
if exception:
log.append(html.span(raw(cgi.escape(line)),
class_='error'))
else:
log.append(raw(cgi.escape(line)))
log.append(html.br())
additional_html.append(log)
self.test_logs.append(html.tr([
html.td(result, class_='col-result'),
html.td(report.nodeid, class_='col-name'),
html.td('%.2f' % time, class_='col-duration'),
html.td(links_html, class_='col-links'),
html.td(additional_html, class_='extra')],
class_=result.lower() + ' results-table-row'))
示例6: _extract_html
def _extract_html(test, class_name, duration=0, text='', result='passed', debug=None):
cls_name = class_name
tc_name = unicode(test)
tc_time = duration
additional_html = []
debug = debug or {}
links_html = []
if result in ['skipped', 'failure', 'expected failure', 'error']:
if debug.get('screenshot'):
screenshot = 'data:image/png;base64,%s' % debug['screenshot']
additional_html.append(html.div(
html.a(html.img(src=screenshot), href="#"),
class_='screenshot'))
for name, content in debug.items():
try:
if 'screenshot' in name:
href = '#'
else:
# use base64 to avoid that some browser (such as Firefox, Opera)
# treats '#' as the start of another link if the data URL contains.
# use 'charset=utf-8' to show special characters like Chinese.
href = 'data:text/plain;charset=utf-8;base64,%s' % base64.b64encode(content)
links_html.append(html.a(
name.title(),
class_=name,
href=href,
target='_blank'))
links_html.append(' ')
except:
pass
log = html.div(class_='log')
for line in text.splitlines():
separator = line.startswith(' ' * 10)
if separator:
log.append(line[:80])
else:
if line.lower().find("error") != -1 or line.lower().find("exception") != -1:
log.append(html.span(raw(cgi.escape(line)), class_='error'))
else:
log.append(raw(cgi.escape(line)))
log.append(html.br())
additional_html.append(log)
test_logs.append(html.tr([
html.td(result.title(), class_='col-result'),
html.td(cls_name, class_='col-class'),
html.td(tc_name, class_='col-name'),
html.td(tc_time, class_='col-duration'),
html.td(links_html, class_='col-links'),
html.td(additional_html, class_='debug')],
class_=result.lower() + ' results-table-row'))
示例7: _extract_html
def _extract_html(test, class_name, duration=0, text="", result="passed", debug=None):
cls_name = class_name
tc_name = unicode(test)
tc_time = duration
additional_html = []
debug = debug or {}
links_html = []
if result in ["skipped", "failure", "expected failure", "error"]:
if debug.get("screenshot"):
screenshot = "data:image/png;base64,%s" % debug["screenshot"]
additional_html.append(html.div(html.a(html.img(src=screenshot), href="#"), class_="screenshot"))
for name, content in debug.items():
try:
if "screenshot" in name:
href = "#"
else:
# use base64 to avoid that some browser (such as Firefox, Opera)
# treats '#' as the start of another link if the data URL contains.
# use 'charset=utf-8' to show special characters like Chinese.
href = "data:text/plain;charset=utf-8;base64,%s" % base64.b64encode(content)
links_html.append(html.a(name.title(), class_=name, href=href, target="_blank"))
links_html.append(" ")
except:
pass
log = html.div(class_="log")
for line in text.splitlines():
separator = line.startswith(" " * 10)
if separator:
log.append(line[:80])
else:
if line.lower().find("error") != -1 or line.lower().find("exception") != -1:
log.append(html.span(raw(cgi.escape(line)), class_="error"))
else:
log.append(raw(cgi.escape(line)))
log.append(html.br())
additional_html.append(log)
test_logs.append(
html.tr(
[
html.td(result.title(), class_="col-result"),
html.td(cls_name, class_="col-class"),
html.td(tc_name, class_="col-name"),
html.td(tc_time, class_="col-duration"),
html.td(links_html, class_="col-links"),
html.td(additional_html, class_="debug"),
],
class_=result.lower() + " results-table-row",
)
)
示例8: 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
)
示例9: make_body
def make_body(self):
body_parts = [html.div(
html.script(raw(pkg_resources.resource_string(
rcname, os.path.sep.join(['resources', 'htmlreport',
'jquery.js']))),
type='text/javascript'),
html.script(raw(pkg_resources.resource_string(
rcname, os.path.sep.join(['resources', 'htmlreport',
'main.js']))),
type='text/javascript'),
html.h1("FirefoxOS Certification Suite Report"),
html.p("Run at %s" % self.time.strftime("%Y-%m-%d %H:%M:%S"))
)]
if self.logs:
device_profile_object = None
with open(self.logs[-1]) as f:
device_profile_object = json.load(f)['result']['contact']
device_profile = [html.h2('Device Information')]
device_table = html.table()
for key in device_profile_object:
device_table.append(
html.tr(
html.td(key),
html.td(device_profile_object[key])
)
)
#device_profile.append(html.p("%s, %s"% (key, device_profile_object[key])))
device_profile.append(device_table)
body_parts.extend(device_profile);
if self.summary_results.has_errors:
body_parts.append(html.h2("Errors During Run"))
body_parts.append(self.make_errors_table(self.summary_results.errors))
body_parts.append(html.h2("Test Results"))
body_parts.append(self.make_result_table())
if self.logs:
ulbody = [];
for log_path in self.logs:
details_log = ''
with open(log_path, 'r') as f:
details_log = f.read()
href = 'data:text/plain;charset=utf-8;base64,%s' % base64.b64encode(details_log)
ulbody.append(html.li(html.a(os.path.basename(log_path), href=href, target='_blank')))
device_profile_object = None
body_parts.append(html.h2("Details log information"))
body_parts.append(html.ul(ulbody))
return html.body(body_parts)
示例10: add_row
def add_row(self, lineno, text):
if text == ['']:
text = [raw(' ')]
else:
text = prepare_line(text, self.tokenizer, self.encoding)
self.tbody.append(html.tr(html.td(str(lineno), class_='lineno'),
html.td(class_='code', *text)))
示例11: startDocument
def startDocument(self):
super(PageHandler, self).startDocument()
self.head.append(html.link(type='text/css', rel='stylesheet',
href='style.css'))
title = self.title[0]
breadcrumb = ''.join([unicode(el) for el in self.breadcrumb(title)])
self.body.append(html.div(raw(breadcrumb), class_='breadcrumb'))
示例12: _append_stacktrace_section
def _append_stacktrace_section(log, report):
log.append(html.h3('Stacktrace'))
stacktrace_p = html.p(class_='stacktrace')
for line in str(report.longrepr).splitlines():
separator = line.startswith('_ ' * 10)
if separator:
stacktrace_p.append(line[:80])
else:
exception = line.startswith("E ")
if exception:
stacktrace_p.append(html.span(raw(escape(line)),
class_='error'))
else:
stacktrace_p.append(raw(escape(line)))
stacktrace_p.append(html.br())
log.append(stacktrace_p)
示例13: append_extra_html
def append_extra_html(self, extra, additional_html, links_html):
href = None
if extra.get('format') == extras.FORMAT_IMAGE:
href = '#'
image = 'data:image/png;base64,{0}'.format(
extra.get('content'))
additional_html.append(html.div(
html.a(html.img(src=image), href="#"),
class_='image'))
elif extra.get('format') == extras.FORMAT_HTML:
additional_html.append(html.div(raw(extra.get('content'))))
elif extra.get('format') == extras.FORMAT_JSON:
href = data_uri(json.dumps(extra.get('content')),
mime_type='application/json')
elif extra.get('format') == extras.FORMAT_TEXT:
href = data_uri(extra.get('content'))
elif extra.get('format') == extras.FORMAT_URL:
href = extra.get('content')
if href is not None:
links_html.append(html.a(
extra.get('name'),
class_=extra.get('format'),
href=href,
target='_blank'))
links_html.append(' ')
示例14: _appendrow
def _appendrow(self, result, report):
names = mangle_testnames(report.nodeid.split("::"))
testclass = (names[:-1])
if self.prefix:
testclass.insert(0, self.prefix)
testclass = ".".join(testclass)
testmethod = names[-1]
time = getattr(report, 'duration', 0.0)
additional_html = []
if not 'Passed' in result:
if report.longrepr:
log = html.div(class_='log')
for line in str(report.longrepr).splitlines():
line = line.decode('utf8')
separator = line.startswith('_ ' * 10)
if separator:
log.append(line[:80])
else:
exception = line.startswith("E ")
if exception:
log.append(html.span(raw(cgi.escape(line)),
class_='error'))
else:
log.append(raw(cgi.escape(line)))
log.append(html.br())
if not os.path.exists(self.screenshot_path):
os.makedirs(self.screenshot_path)
self.append_screenshot(testmethod, log)
additional_html.append(log)
output = self._write_captured_output(report)
info = output.split(" ")
links_html = []
for i in range(0, len(info)):
if ("http" in info[i] and "browserstack.com" in info[i]):
links_html.append(html.a("link", href=info[i], target='_blank'))
links_html.append(' ')
self.test_logs.append(html.tr([
html.td(result, class_='col-result'),
html.td(testclass, class_='col-class'),
html.td(testmethod, class_='col-name'),
html.td(round(time), class_='col-duration'),
html.td(links_html, class_='col-links'),
html.td(additional_html, class_='debug')],
class_=result.lower() + ' results-table-row'))
示例15: 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())))