本文整理汇总了Python中yattag.Doc.asis方法的典型用法代码示例。如果您正苦于以下问题:Python Doc.asis方法的具体用法?Python Doc.asis怎么用?Python Doc.asis使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yattag.Doc
的用法示例。
在下文中一共展示了Doc.asis方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: to_html
# 需要导入模块: from yattag import Doc [as 别名]
# 或者: from yattag.Doc import asis [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()
示例2: handle_enumerateable
# 需要导入模块: from yattag import Doc [as 别名]
# 或者: from yattag.Doc import asis [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 asis [as 别名]
def as_junit_xml(self):
"""
Return Junit-format XML fragment.
"""
xml, tag, text = XML().tagtext()
with tag('testsuite',
name=self.name,
hostname=self.hostname,
time=(self.stop - self.start),
tests=len(self._testcases),
timestamp=datetime.fromtimestamp(self.start).isoformat(),
errors=self.errored,
failures=self.failed,
skipped=self.skipped,
):
if self._id is not None:
xml.attr(id=self._id)
with tag('properties'):
for key, value in self._properties.iteritems():
xml.stag('property', name=key, value=str(value))
for testcase in self._testcases:
if testcase.status is None:
with tag('error'):
text('Unknown outcome of this step.')
else:
xml.asis(testcase.as_junit_xml())
return xml.getvalue()
示例4: as_xml
# 需要导入模块: from yattag import Doc [as 别名]
# 或者: from yattag.Doc import asis [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: saveRelease
# 需要导入模块: from yattag import Doc [as 别名]
# 或者: from yattag.Doc import asis [as 别名]
def saveRelease(self, release):
"""
Create an XML file of release metadata that Dalet will be happy with
:param release: Processed release metadata from MusicBrainz
"""
output_dir = self.release_meta_dir
doc, tag, text = Doc().tagtext()
doc.asis('<?xml version="1.0" encoding="UTF-8"?>')
with tag('Titles'):
with tag('GlossaryValue'):
with tag('GlossaryType'):
text('Release')
with tag('Key1'):
text(release.mbID)
with tag('ItemCode'):
text(release.mbID)
with tag('KEXPReviewRich'):
text(release.review)
formatted_data = indent(doc.getvalue())
output_file = path.join(output_dir, 'r' + release.mbID + ".xml")
with open(output_file, "wb") as f:
f.write(formatted_data.encode("UTF-8"))
示例6: html_from_tree
# 需要导入模块: from yattag import Doc [as 别名]
# 或者: from yattag.Doc import asis [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())
示例7: to_html
# 需要导入模块: from yattag import Doc [as 别名]
# 或者: from yattag.Doc import asis [as 别名]
def to_html(self, metadata, style=None):
"""Method for producing and html string of selected metadata.
Parameters
----------
metadata : str
metadata key
style : str, optional
css style of metadata tag
Returns
-------
str
html string containing the metadata
>>> source = '---metadata authors = ["S. Zaghi","J. Doe"] ---endmetadata'
>>> meta = Metadata(source)
>>> meta.to_html(metadata='authors')
'<span class="metadata">S. Zaghi and J. Doe</span>'
"""
doc = Doc()
if metadata == 'logo':
self.put_logo(doc=doc,style=style)
else:
with doc.tag('span',klass='metadata'):
if style:
doc.attr(style=style)
doc.asis(self.get_value(metadata))
return doc.getvalue()
示例8: show_xml
# 需要导入模块: from yattag import Doc [as 别名]
# 或者: from yattag.Doc import asis [as 别名]
def show_xml():
pages = [ f for f in os.listdir(CACHEDIR) if os.path.isdir(os.path.join(CACHEDIR,f)) ]
doc, tag, text = Doc().tagtext()
doc.asis('<?xml version="1.0" encoding="utf-8" ?>')
# xml tags
with tag('sac_uo'):
for p in pages:
item = get_data_from_page('%s/latest' % p)
if item:
with tag('item'):
with tag('id'):
text(item['id'])
with tag('nom'):
text(item['nom'])
with tag('resp'):
text(item['resp']) # mini hack
with tag('iddep'):
text(item['iddep'])
with tag('dep'):
text(item['dep'])
with tag('centers'):
text(item['centers'])
return indent(
doc.getvalue(),
indentation = ' ' * 4,
newline = '\r\n'
)
示例9: handle_list
# 需要导入模块: from yattag import Doc [as 别名]
# 或者: from yattag.Doc import asis [as 别名]
def handle_list(self, tag: QqTag, type):
doc, html, text = Doc().tagtext()
with html(type):
for item in tag("item"):
with html("li"):
doc.asis(self.format(item))
return doc.getvalue()
示例10: __to_html
# 需要导入模块: from yattag import Doc [as 别名]
# 或者: from yattag.Doc import asis [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
示例11: to_html
# 需要导入模块: from yattag import Doc [as 别名]
# 或者: from yattag.Doc import asis [as 别名]
def to_html(self, config):
"""Generate a html stream of the whole presentation.
Parameters
----------
config : MatisseConfig
MaTiSSe configuration
"""
doc, tag, text = Doc().tagtext()
doc.asis('<!DOCTYPE html>')
with tag('html'):
# doc.attr(title=self.metadata['title'].value)
self.__put_html_tag_head(doc=doc, tag=tag, text=text, config=config)
with tag('body', onload="resetCountdown(" + str(self.metadata['max_time'].value) + ");"):
doc.attr(klass='impress-not-supported')
with tag('div', id='impress'):
# numbering: [local_chap, local_sec, local_subsec, local_slide]
current = [0, 0, 0, 0]
for chapter in self.chapters:
current[0] += 1
current[1] = 0
current[2] = 0
current[3] = 0
self.metadata['chaptertitle'].update_value(value=chapter.title)
self.metadata['chapternumber'].update_value(value=chapter.number)
for section in chapter.sections:
current[1] += 1
current[2] = 0
current[3] = 0
self.metadata['sectiontitle'].update_value(value=section.title)
self.metadata['sectionnumber'].update_value(value=section.number)
for subsection in section.subsections:
current[2] += 1
current[3] = 0
self.metadata['subsectiontitle'].update_value(value=subsection.title)
self.metadata['subsectionnumber'].update_value(value=subsection.number)
for slide in subsection.slides:
current[3] += 1
self.metadata['slidetitle'].update_value(value=slide.title)
self.metadata['slidenumber'].update_value(value=slide.number)
with doc.tag('div'):
chapter.put_html_attributes(doc=doc)
section.put_html_attributes(doc=doc)
subsection.put_html_attributes(doc=doc)
slide.put_html_attributes(doc=doc)
self.__put_html_slide_decorators(tag=tag, doc=doc, decorator='header', current=current, overtheme=slide.overtheme)
# with doc.tag('div'):
# doc.attr(style='clear: both;')
self.__put_html_slide_decorators(tag=tag, doc=doc, decorator='sidebar', position='L', current=current, overtheme=slide.overtheme)
slide.to_html(doc=doc, parser=self.parser, metadata=self.metadata, theme=self.theme, current=current)
self.__put_html_slide_decorators(tag=tag, doc=doc, decorator='sidebar', position='R', current=current, overtheme=slide.overtheme)
# with doc.tag('div'):
# doc.attr(style='clear: both;')
self.__put_html_slide_decorators(tag=tag, doc=doc, decorator='footer', current=current, overtheme=slide.overtheme)
self.__put_html_tags_scripts(doc=doc, tag=tag, config=config)
# source = re.sub(r"<li>(?P<item>.*)</li>", r"<li><span>\g<item></span></li>", source)
html = indent(doc.getvalue())
return html
示例12: handle_paragraph
# 需要导入模块: from yattag import Doc [as 别名]
# 或者: from yattag.Doc import asis [as 别名]
def handle_paragraph(self, tag: QqTag):
"""
:param tag:
:return:
"""
doc, html, text = Doc().tagtext()
with html("span", klass="paragraph"):
doc.asis(self.format(tag, blanks_to_pars=False).strip() + ".")
return "<p>" + doc.getvalue()+" "
示例13: as_xml
# 需要导入模块: from yattag import Doc [as 别名]
# 或者: from yattag.Doc import asis [as 别名]
def as_xml(self):
doc, tag, text = Doc().tagtext()
doc.asis("<?xml version='1.0' encoding='UTF-8'?>")
with tag('bundle-app', name=self.name, xmlns="uri:oozie:bundle:0.1"):
for coordinator in self.coordinators:
with tag("coordinator", name=coordinator.name):
with tag("app-path"):
text("/"+coordinator.path + "/" + coordinator.name)
return indent(doc.getvalue())
示例14: record_listens
# 需要导入模块: from yattag import Doc [as 别名]
# 或者: from yattag.Doc import asis [as 别名]
def record_listens(request, data):
""" Submit the listen in the lastfm format to be inserted in db.
Accepts listens for both track.updateNowPlaying and track.scrobble methods.
"""
output_format = data.get('format', 'xml')
try:
sk, api_key = data['sk'], data['api_key']
except KeyError:
raise InvalidAPIUsage(CompatError.INVALID_PARAMETERS, output_format=output_format) # Invalid parameters
session = Session.load(sk)
if not session:
if not Token.is_valid_api_key(api_key):
raise InvalidAPIUsage(CompatError.INVALID_API_KEY, output_format=output_format) # Invalid API_KEY
raise InvalidAPIUsage(CompatError.INVALID_SESSION_KEY, output_format=output_format) # Invalid Session KEY
lookup = defaultdict(dict)
for key, value in data.items():
if key in ["sk", "token", "api_key", "method", "api_sig"]:
continue
matches = re.match('(.*)\[(\d+)\]', key)
if matches:
key = matches.group(1)
number = matches.group(2)
else:
number = 0
lookup[number][key] = value
if request.form['method'].lower() == 'track.updatenowplaying':
for i, listen in lookup.items():
if 'timestamp' not in listen:
listen['timestamp'] = calendar.timegm(datetime.now().utctimetuple())
# Convert to native payload then submit 'em after validation.
listen_type, native_payload = _to_native_api(lookup, data['method'], output_format)
for listen in native_payload:
validate_listen(listen, listen_type)
user = db_user.get(session.user_id)
augmented_listens = insert_payload(native_payload, user, listen_type=listen_type)
# With corrections than the original submitted listen.
doc, tag, text = Doc().tagtext()
with tag('lfm', status='ok'):
if listen_type == 'playing_now':
doc.asis(create_response_for_single_listen(list(lookup.values())[0], augmented_listens[0], listen_type))
else:
accepted_listens = len(lookup.values())
# Currently LB accepts all the listens and ignores none
with tag('scrobbles', accepted=accepted_listens, ignored='0'):
for original_listen, augmented_listen in zip(list(lookup.values()), augmented_listens):
doc.asis(create_response_for_single_listen(original_listen, augmented_listen, listen_type))
return format_response('<?xml version="1.0" encoding="utf-8"?>\n' + yattag.indent(doc.getvalue()),
output_format)
示例15: MakeHTMLHivePlot
# 需要导入模块: from yattag import Doc [as 别名]
# 或者: from yattag.Doc import asis [as 别名]
def MakeHTMLHivePlot():
doc, tag, text = Doc().tagtext()
doc.asis('<!DOCTYPE html>')
with tag('html'):
with open ('C:/Users/s/Documents/GitHub/d3BMCR/HiveTemplate1.html','r') as scpt:
doc.asis(scpt.read())
a=doc.getvalue()
with open (pathPlusName,'w') as f:
f.write(a)
webbrowser.open(pathPlusName)