本文整理汇总了Python中yattag.Doc.getvalue方法的典型用法代码示例。如果您正苦于以下问题:Python Doc.getvalue方法的具体用法?Python Doc.getvalue怎么用?Python Doc.getvalue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yattag.Doc
的用法示例。
在下文中一共展示了Doc.getvalue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle_h
# 需要导入模块: from yattag import Doc [as 别名]
# 或者: from yattag.Doc import getvalue [as 别名]
def handle_h(self, tag: QqTag) -> str:
"""
Uses tags: h1, h2, h3, h4, label, number
Example:
\h1 This is first header
\h2 This is the second header \label{sec:second}
:param tag:
:return:
"""
doc, html, text = Doc().tagtext()
with html(tag.name):
doc.attr(id=self.tag_id(tag))
if tag.find("number"):
with html("span", klass="section__number"):
with html("a", href="#"+self.tag_id(tag), klass="section__number"):
text(tag._number.value)
text(self.format(tag, blanks_to_pars=False))
ret = doc.getvalue()
if tag.next() and isinstance(tag.next(), str):
ret += "<p>"
return doc.getvalue()
示例2: handle_enumerateable
# 需要导入模块: from yattag import Doc [as 别名]
# 或者: from yattag.Doc import getvalue [as 别名]
def handle_enumerateable(self, tag):
"""
Uses tags: label, number, name
Add tags used manually from enumerateable_envs
:param tag:
:return:
"""
doc, html, text = Doc().tagtext()
name = tag.name
env_localname = self.localize(self.enumerateable_envs[name])
with html("div", klass="env env__" + name):
if tag.find("label"):
doc.attr(id=self.label2id(tag._label.value))
number = tag.get("number", "")
with html("span", klass="env-title env-title__" + name):
if tag.find("label"):
with html("a", klass="env-title env-title__" + name, href="#" + self.label2id(tag._label.value)):
text(join_nonempty(env_localname, number) + ".")
else:
text(join_nonempty(env_localname, number) + ".")
doc.asis(" " + self.format(tag, blanks_to_pars= True))
return "<p>"+doc.getvalue()+"</p>\n<p>"
示例3: as_junit_xml
# 需要导入模块: from yattag import Doc [as 别名]
# 或者: from yattag.Doc import getvalue [as 别名]
def as_junit_xml(self):
xml, tag, text = XML().tagtext()
with tag('testcase',
name=self.name,
time=(self.stop - self.start)):
if self.classname is not None:
xml.attr(classname=self.classname)
if self.assertions is not None:
xml.attr(assertions=self.assertions)
with tag('properties'):
for key, value in self._properties.iteritems():
xml.stag('property', name=key, value=str(value))
if self.status == 'error':
with tag('error', message=self._msg):
text(self._msg)
elif self.status == 'failure':
with tag('failure', message=self._msg):
text(self._msg)
elif self.status == 'skipped':
xml.stag('skipped', message=self._msg)
if self.stdout is None:
xml.stag('system-out')
else:
with tag('system-out'):
text(str(self.stdout))
if self.stderr is None:
xml.stag('system-err')
else:
with tag('system-err'):
text(str(self.stderr))
return xml.getvalue()
示例4: as_xml
# 需要导入模块: from yattag import Doc [as 别名]
# 或者: from yattag.Doc import getvalue [as 别名]
def as_xml(self):
doc, tag, text = Doc().tagtext()
doc.asis("<?xml version='1.0' encoding='UTF-8'?>")
with tag('workflow-app', ('xmlns:sla', 'uri:oozie:sla:0.2'), name=self.name, xmlns="uri:oozie:workflow:0.5"):
doc.stag('start', to=self.actions[0].name)
for index, action in enumerate(self.actions):
with tag("action", name=action.name):
doc.asis(action.as_xml(indent))
if index + 1 < len(self.actions):
next_action = self.actions[index+1]
doc.stag("ok", to=next_action.name)
else:
doc.stag("ok", to="end")
doc.stag("error", to="notify")
with tag("action", name="notify"):
with tag("email", xmlns="uri:oozie:email-action:0.1"):
with tag("to"):
text(self.email)
with tag("subject"):
text("WF ${wf:name()} failed at ${wf:lastErrorNode()}")
with tag("body"):
text("http://hue.data.shopify.com/oozie/list_oozie_workflow/${wf:id()}")
doc.stag("ok", to="kill")
doc.stag("error", to="kill")
with tag("kill", name="kill"):
with tag("message"):
text("${wf:lastErrorNode()} - ${wf:id()}")
doc.stag('end', name="end")
return indent(doc.getvalue())
示例5: test_list_jobs
# 需要导入模块: from yattag import Doc [as 别名]
# 或者: from yattag.Doc import getvalue [as 别名]
def test_list_jobs(self):
project_name = 'test_project'
jobs = [
{'name': 'job 1', 'id': '1', 'project': project_name, 'description': 'job 1 description'}]
doc, tag, text = Doc().tagtext()
with tag('jobs', count=len(jobs)):
for job in jobs:
with tag('job'):
with tag('name'):
text(job['name'])
with tag('project'):
text(job['project'])
with tag('description'):
text(job['description'])
responses.add(responses.GET,
'http://rundeck.host/api/11/jobs?project=test_project',
match_querystring=True,
body=self.rundeck_success(doc.getvalue()),
content_type='text/xml', status=200)
project_jobs = self.rundeck_api.list_jobs(project_name)
self.assertEquals(len(project_jobs), len(jobs))
self.assertEquals(project_jobs[0]['name'], jobs[0]['name'])
示例6: process_dump_file
# 需要导入模块: from yattag import Doc [as 别名]
# 或者: from yattag.Doc import getvalue [as 别名]
def process_dump_file(self, p):
add_event = 0
main_doc, main_tag, main_text = Doc().tagtext()
for line in iter(p.stdout.readline, b''):
# Compares first with timestamp regex. Timestamp regex indicates a new packet
m = reg_timestamp.match(line.decode())
if m:
# add_event indicates if there is a processed event already
if add_event == 1:
events.append(event)
self.add_event_to_html(event, main_doc, main_tag, main_text)
add_event = 1
event = Event(m.group('timestamp'), m.group('protocol'))
m = reg_ip_1.search(line.decode())
if m:
event.id = m.group('id')
event.t_protocol = m.group('transport_protocol')
event.length = m.group('length')
else:
m = reg_ip_2.search(line.decode())
if m:
event.src = m.group('src')
event.src_port = m.group('src_port')
event.dst = m.group('dst')
event.dst_port = m.group('dst_port')
m = reg_length.search(line.decode())
# If TCP data is not 0, the packet gets further processing
if m and m.group('length') != 0:
length = int(m.group('length'))
self.process_host(event, length)
# If there is a port unreachable error, event gets discarded
m = reg_port_error.search(line.decode())
if m:
add_event = 0
return indent(main_doc.getvalue())
示例7: as_xml
# 需要导入模块: from yattag import Doc [as 别名]
# 或者: from yattag.Doc import getvalue [as 别名]
def as_xml(self, indentation=False):
doc, tag, text = Doc().tagtext()
with tag('shell', xmlns="uri:oozie:shell-action:0.2"):
#do we actually need these even if we dont use them?
with tag('job-tracker'):
text(os.environ["JOBTRACKER"])
with tag('name-node'):
text(os.environ["NAMENODE"])
with tag('exec'):
text(self.command)
for argument in self.arguments:
with tag('argument'):
text(argument)
for env in self.environment_vars:
with tag('env-var'):
text(env)
for archive in self.archives:
with tag('archive'):
text(archive)
for f in self.files:
with tag('file'):
text(f)
xml = doc.getvalue()
if indentation:
return indent(xml)
else:
return xml
示例8: handle_proof
# 需要导入模块: from yattag import Doc [as 别名]
# 或者: from yattag.Doc import getvalue [as 别名]
def handle_proof(self, tag: QqTag) -> str:
"""
Uses tags: proof, label, outline, of
Examples:
\proof
Here is the proof
\proof \of theorem \ref{thm:1}
Now we pass to proof of theorem \ref{thm:1}
:param tag:
:return: HTML of proof
"""
doc, html, text = Doc().tagtext()
with html("div", klass="env env__proof"):
if tag.find("label"):
doc.attr(id=self.label2id(tag._label.value))
with html("span", klass="env-title env-title__proof"):
if tag.exists("outline"):
proofline = 'Proof outline'
else:
proofline = 'Proof'
doc.asis(join_nonempty(self.localize(proofline),
self.format(tag.find("of"), blanks_to_pars=False)).rstrip()+".")
doc.asis(rstrip_p(" " + self.format(tag, blanks_to_pars=True)))
doc.asis("<span class='end-of-proof'>∎</span>")
return doc.getvalue()+"\n<p>"
示例9: _repr_html_
# 需要导入模块: from yattag import Doc [as 别名]
# 或者: from yattag.Doc import getvalue [as 别名]
def _repr_html_(self):
doc, tag, txt = Doc().tagtext()
with tag("div", klass="tree-node tree-leaf"):
self._label_html(doc)
with tag("span", klass="tree-text"):
txt(self.text)
return doc.getvalue()
示例10: serve_pre
# 需要导入模块: from yattag import Doc [as 别名]
# 或者: from yattag.Doc import getvalue [as 别名]
def serve_pre(content):
doc, tag, text = Doc().tagtext()
with tag('html'):
with tag('head'):
with tag('script', src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"):
pass
with tag('script', src="http://code.jquery.com/jquery-migrate-3.0.0.js"):
pass
with tag('script', src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"):
pass
with tag('script'):
doc.asis(
'''
$('.zone').on('mouseover mouseout', function(e) {
$(this).toggleClass('hovering', e.type === 'mouseover');
e.stopPropagation();
});
'''
)
with tag('style'):
doc.asis(
'''
.zone.hovering {color: orange; font-weight: bold; background-color: gray; cursor: pointer;};
.zone {color: black};
'''
)
with tag('body'):
with tag('pre'):
doc.asis(content)
return doc.getvalue()
示例11: getSession
# 需要导入模块: from yattag import Doc [as 别名]
# 或者: from yattag.Doc import getvalue [as 别名]
def getSession(request, data):
token = Token.load(data['token'])
if not token:
print "Invalid token"
return "NOPE"
if not token.user:
print "Token not validated"
return "NOPE"
print "GRANTING SESSION for token %s" % token.token
token.consume()
session = Session.create(token.user)
doc, tag, text = Doc().tagtext()
with tag('lfm', status="ok"):
with tag('session'):
with tag('name'):
text(session.user.name)
with tag('key'):
text(session.id)
with tag('subscriber'):
text('0')
return '<?xml version="1.0" encoding="utf-8"?>\n' + yattag.indent(doc.getvalue())
示例12: html_from_tree
# 需要导入模块: from yattag import Doc [as 别名]
# 或者: from yattag.Doc import getvalue [as 别名]
def html_from_tree(tree):
"""Generate indented HTML from VOTL Object tree.
Params:
tree (Object): A VOTL Object containing the tree, from which HTML will
be generated.
Returns: String containing a pretty-formatted HTML document.
"""
doc, tag, text = Doc().tagtext()
doc.asis("<!DOCTYPE html>")
first = tree.children[0]
if first.object_type == "header":
title = first.first_line
else:
title = "Untitled"
with tag("html"):
with tag("head"):
with tag("title"):
text(title)
doc.stag("meta", charset="utf-8")
with tag("body"):
_recurse_tags(tree, doc, tag, text)
return indent(doc.getvalue())
示例13: to_html
# 需要导入模块: from yattag import Doc [as 别名]
# 或者: from yattag.Doc import getvalue [as 别名]
def to_html(self, match, toc_depth=None, max_time=None, current=None):
"""Convert logo metadata to html stream.
Parameters
----------
match: re.match object
max_time: str
max time for presentation
Returns
-------
str:
html stream
"""
if 'toc' in self.name:
return self.toc_to_html(match=match, current=current, depth=int(toc_depth))
if 'logo' in self.name:
return self.logo_to_html(match)
elif 'timer' in self.name:
return self.timer_to_html(match=match, max_time=max_time)
elif 'custom' in self.name:
return self.custom_to_html(match)
else:
doc = Doc()
with doc.tag('span', klass='metadata'):
style = None
if match.group('style'):
style = str(match.group('style'))
if style:
doc.attr(style=style)
if isinstance(self.value, list):
doc.asis(', '.join(self.value))
else:
doc.asis(str(self.value))
return doc.getvalue()
示例14: __to_html
# 需要导入模块: from yattag import Doc [as 别名]
# 或者: from yattag.Doc import getvalue [as 别名]
def __to_html(self, pmid, title, abstract, output_dir):
"""Generate HTML file for Anndoc
Write a HTML file required for Anndoc, formatted according to TagTog's
standards that can be viewed at the link below.
https://github.com/jmcejuela/tagtog-doc/wiki
By default, the MEDLINE identifier will be used as the title, unless
something else is specified.
Args:
title (str): Title of the paper
abstract (str): Abstract contents of the paper
output_file (Optional[str]): Path to the output file. Defaults to
none.
"""
from yattag import Doc
from yattag import indent
from os.path import join
doc, tag, text = Doc().tagtext()
# Compute hashId (TODO find out what hashing is used, currently random)
hashId = self.__random_hashId(pmid)
# Use Yattag to generate HTML syntax
doc.asis('<!DOCTYPE html>')
with tag('html',
('data-origid', pmid),
('data-anndoc-version', "2.0"),
('lang', ""), ('xml:lang', ""),
('xmlns', "http://www.w3.org/1999/xhtml"),
klass='anndoc',
id=hashId):
with tag('head'):
doc.stag('meta', charset='UTF-8')
doc.stag('meta', name='generator', content='org.rostlab.relna')
with tag('title'):
text(hashId)
with tag('body'):
with tag('article'):
with tag('section', ('data-type', 'title')):
with tag('h2', id='s1h1'):
text(title)
with tag('section', ('data-type', 'abstract')):
with tag('h3', id='s2h1'):
text("Abstract")
with tag('div', klass='content'):
with tag('p', id='s2p1'):
text(abstract)
# Write to file
result = indent(doc.getvalue())
try:
with open(join(output_dir, pmid+'.html'), 'w') as fw:
fw.write(result)
except IOError as e:
print('I/O Error({0}): {1}'.format(e.errno, e.strerror))
raise
示例15: timer_to_html
# 需要导入模块: from yattag import Doc [as 别名]
# 或者: from yattag.Doc import getvalue [as 别名]
def timer_to_html(self, match, max_time):
"""Convert custom metadata to html stream.
Parameters
----------
match: re.match object
max_time: str
Returns
-------
str:
html stream
"""
doc = Doc()
with doc.tag('span', klass='timercontainer'):
style = None
if match.group('style'):
style = str(match.group('style'))
if style:
doc.attr(style=style)
with doc.tag('div', klass='countDown'):
with doc.tag('div'):
doc.attr(klass='timer')
if style:
if 'controls' in style:
with doc.tag('div', klass='timercontrols'):
with doc.tag('input', type='button'):
doc.attr(klass='btn reset', onclick='resetCountdown(' + str(max_time) + ');', value=' ⟳ ', title='reset')
with doc.tag('input', type='button'):
doc.attr(klass='btn stop', onclick='stopCountdown();', value=' ◼ ', title='pause')
with doc.tag('input', type='button'):
doc.attr(klass='btn start', onclick='startCountdown();', value=' ▶ ', title='start')
return doc.getvalue().replace('amp;', '')