本文整理汇总了Python中yattag.Doc类的典型用法代码示例。如果您正苦于以下问题:Python Doc类的具体用法?Python Doc怎么用?Python Doc使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Doc类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: as_xml
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
示例2: submit
def submit(self, bund, files=[]):
hdfs = PyWebHdfsClient(host=os.environ["WEBHDFS_HOST"], port='14000', user_name='oozie')
for f in files:
hdfs.create_file("{}/{}".format(bund.path, f.name), f.read())
doc, tag, text = Doc().tagtext()
with tag("configuration"):
with tag("property"):
with tag("name"):
text("user.name")
with tag("value"):
text("oozie")
with tag("property"):
with tag("name"):
text("oozie.bundle.application.path")
with tag("value"):
text("/"+bund.path + "/" + bund.name)
configuration = doc.getvalue()
response = post("{0}/oozie/v1/jobs".format(self.url), data=configuration, headers={'Content-Type': 'application/xml'})
if response.status_code > 399:
print response.headers["oozie-error-message"]
print response.status_code
print response.content
示例3: _repr_html_
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()
示例4: now_playing
def now_playing(request, data):
sk = data['sk']
session = Session.load(sk)
if not session:
print "Invalid session"
return "NOPE"
track = data['track']
artist = data['artist']
album = data['album']
albumArtist = data['albumArtist']
print "NOW PLAYING- User: %s, Artist: %s, Track: %s, Album: %s" \
% (session.user.name, artist, track, album)
doc, tag, text = Doc().tagtext()
with tag('lfm', status="ok"):
with tag('nowplaying'):
with tag('track', corrected="0"):
text(track)
with tag('artist', corrected="0"):
text(artist)
with tag('album', corrected="0"):
text(album)
with tag('albumArtist', corrected="0"):
text(albumArtist)
with tag('ignoredMessage', code="0"):
text('')
return '<?xml version="1.0" encoding="utf-8"?>\n' + yattag.indent(doc.getvalue())
示例5: show_xml
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'
)
示例6: saveRelease
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"))
示例7: media_player
def media_player(request, media_src=''):
doc, tag, text = Doc().tagtext()
types = {'video':'V', 'audio':'A'}
requested_type = media_src.split('/')[0]
media_servers = MediaServer.objects.filter(media_type=types[requested_type])
image_src = ''
next_path = ''
if len(media_src.split('/')) >= 2:
requested_server = media_src.split('/')[1]
else:
requested_server = ''
for server in media_servers:
if server.name == requested_server:
media_src = server.server_url + media_src[len(requested_type + '/' + requested_server):]
parent_dir = server.directory_path + os.path.split(media_src)[0][len(server.server_url):]
plist = sorted(os.listdir(parent_dir))
media_path = server.directory_path + media_src[len(server.server_url):]
media_base = os.path.basename(media_path)
for item in os.listdir(parent_dir):
if os.path.splitext(item)[1].lower() in ['.jpg','.png']:
image_src = os.path.join(os.path.split(media_src)[0],item)
if len(plist)-1 > plist.index(media_base):
next_path = urlpath(server, os.path.join(parent_dir, plist[plist.index(media_base)+1]))
display_directory(server.directory_path, server, doc)
ml = media_src.split('/')
context = { 'medialisting':doc.getvalue(),
'mediasource':media_src,
'mediatype':requested_type,
'imagesource':image_src,
'heading':os.path.splitext(ml[len(ml)-1])[0],
'nextmedia': next_path,
}
return render(request, 'media_player/media_player.html', context)
示例8: getSession
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())
示例9: handle_list
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: environment_begin_end
def environment_begin_end(env, label=None, number=None, optional=None):
if env == "document":
return '<html><meta charset="UTF-8">' + mathjax_snipped, "</html>\n"
doc, tag, text = Doc().tagtext()
stop_sign = "!!!chahpieXeiDu3zeer3Ki"
if env == "itemize" or env == "enumerate":
with tag(list_envs[env]):
text(stop_sign)
else:
with tag("div", klass="env_" + mk_safe_css_ident(env)):
if label:
doc.attr(id="label_" + mk_safe_css_ident(label))
if env in named_envs:
with tag("span", klass="env__name"):
text(named_envs[env])
text(" ")
if number:
with tag("span", klass="env__number"):
text(number)
text(" ")
if optional:
with tag("span", klass="env__opt_text"):
text(optional)
text(stop_sign)
ret = doc.getvalue()
index = ret.index(stop_sign)
begin = ret[:index] + "\n"
end = ret[index + len(stop_sign) :] + "\n"
return (begin, end)
示例11: handle_proof
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>"
示例12: __init__
def __init__(self, projectname = None):
if projectname is None: # Used for just an empty html page with the same style and template
self.doc, self.tag, self.text = Doc().tagtext()
self.this_is_a_log_html_page = True
else:
Htmlpage.htmlpages[projectname] = self
self.doc, self.tag, self.text = Doc().tagtext()
示例13: handle_h
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()
示例14: test_list_jobs
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'])
示例15: process_dump_file
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())