本文整理汇总了Python中lxml.html.builder.E.a方法的典型用法代码示例。如果您正苦于以下问题:Python E.a方法的具体用法?Python E.a怎么用?Python E.a使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lxml.html.builder.E
的用法示例。
在下文中一共展示了E.a方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_footer
# 需要导入模块: from lxml.html.builder import E [as 别名]
# 或者: from lxml.html.builder.E import a [as 别名]
def add_footer(self):
self.elements.content.append(
E.footer(
E.a(self.T('Wuff Signal'),
href=self.handler.reverse_url('textshow.index')),
' ',
E.a(self.T('About'),
href=self.handler.reverse_url('textshow.about'))
)
)
示例2: _build_html_footer
# 需要导入模块: from lxml.html.builder import E [as 别名]
# 或者: from lxml.html.builder.E import a [as 别名]
def _build_html_footer(self):
'''Adds the site visual footer links'''
self.elements.footer.extend([
E.nav(
E.a(self.handler.application.settings['application_name'],
href=self.handler.reverse_url('index')),
' ',
E.a(self.T('About'),
href=self.handler.reverse_url('index.about'))
)
])
示例3: gen_anchor
# 需要导入模块: from lxml.html.builder import E [as 别名]
# 或者: from lxml.html.builder.E import a [as 别名]
def gen_anchor(self, cls, inst, name, anchor_class=None):
assert name is not None
cls_attrs = self.get_cls_attrs(cls)
href = getattr(inst, 'href', None)
if href is None: # this is not a AnyUri.Value instance.
href = inst
content = None
text = cls_attrs.text
else:
content = getattr(inst, 'content', None)
text = getattr(inst, 'text', None)
if text is None:
text = cls_attrs.text
if anchor_class is None:
anchor_class = cls_attrs.anchor_class
if text is None:
text = name
retval = E.a(text)
if href is not None:
retval.attrib['href'] = href
if anchor_class is not None:
retval.attrib['class'] = anchor_class
if content is not None:
retval.append(content)
return retval
示例4: _subvalue_to_html
# 需要导入模块: from lxml.html.builder import E [as 别名]
# 或者: from lxml.html.builder.E import a [as 别名]
def _subvalue_to_html(cls, value):
if issubclass(cls.type, AnyUri):
href = getattr(value, 'href', None)
if href is None: # this is not a AnyUri.Value instance.
href = value
text = getattr(cls.type.Attributes, 'text', None)
content = None
else:
text = getattr(value, 'text', None)
if text is None:
text = getattr(cls.type.Attributes, 'text', None)
content = getattr(value, 'content', None)
if issubclass(cls.type, ImageUri):
retval = E.img(src=href)
if text is not None:
retval.attrib['alt'] = text
# content is ignored with ImageUri.
else:
retval = E.a(href=href)
retval.text = text
if content is not None:
retval.append(content)
else:
retval = cls.type.to_string(value)
return retval
示例5: build_title_content
# 需要导入模块: from lxml.html.builder import E [as 别名]
# 或者: from lxml.html.builder.E import a [as 别名]
def build_title_content(self):
content = E.table(
E.tr(
E.th(self.T('Time')),
E.th(self.T('Message')),
E.th(self.T('Count'))
)
)
for message in self._messages:
message_dict = dict(message.data_iter)
row = E.tr(
E.td(self.handler.locale.format_date(message.datetime),
rowspan=str(len(message_dict)))
)
for key, count in sorted(message_dict.items()):
row.extend([E.td(to_hex(key)), E.td(str(count))])
content.append(row)
row = E.tr()
self.elements.content.append(content)
if self._pager_next:
self.elements.content.append(
E.a(self.T('Older'), href='?before=' + str(self._pager_next))
)
self.add_footer()
示例6: replace_youtube_videos_with_links
# 需要导入模块: from lxml.html.builder import E [as 别名]
# 或者: from lxml.html.builder.E import a [as 别名]
def replace_youtube_videos_with_links(self, doc):
"""Replace any iframe elements found with a link to the src and a
placeholder image from youtube"""
def get_yt_id(src):
"""Return the youtube video id"""
split_src = src.split("/")
if "embed" in split_src:
yt_id_index = split_src.index("embed") + 1
return split_src[yt_id_index]
iframes = doc.xpath("//iframe")
for iframe in iframes:
src = iframe.get("src")
yt_id = get_yt_id(src)
if not yt_id:
continue
else:
yt_img = "https://img.youtube.com/vi/{0}/0.jpg".format(yt_id)
yt_href = "https://youtu.be/{0}".format(yt_id)
yt_link = E.a(
E.img(
src=yt_img,
width="480",
height="360",
),
href=yt_href,
target="_blank",
)
parent = iframe.getparent()
parent.replace(iframe, yt_link)
示例7: anyuri_to_parent
# 需要导入模块: from lxml.html.builder import E [as 别名]
# 或者: from lxml.html.builder.E import a [as 别名]
def anyuri_to_parent(self, ctx, cls, inst, parent, name, **kwargs):
assert name is not None
href = getattr(inst, 'href', None)
if href is None: # this is not a AnyUri.Value instance.
href = inst
text = getattr(cls.Attributes, 'text', name)
content = None
else:
text = getattr(inst, 'text', None)
if text is None:
text = getattr(cls.Attributes, 'text', name)
content = getattr(inst, 'content', None)
if text is None:
text = name
retval = E.a(text)
if href is not None:
retval.attrib['href'] = href
if content is not None:
retval.append(content)
parent.write(retval)
示例8: _build_html_header
# 需要导入模块: from lxml.html.builder import E [as 别名]
# 或者: from lxml.html.builder.E import a [as 别名]
def _build_html_header(self):
'''Add banner and account links'''
header = self.elements.header
index_url = self.links.get(
'index', self.handler.reverse_url('index'))
header.append(E.div(
E.a(self.meta.app_name, href=index_url, id='logo-link'),
id='logo-wrapper'
))
示例9: build_content
# 需要导入模块: from lxml.html.builder import E [as 别名]
# 或者: from lxml.html.builder.E import a [as 别名]
def build_content(self):
self.elements.content.append(
E.a('Wuff Signal',
href=self.handler.reverse_url('textshow.index')))
示例10: index
# 需要导入模块: from lxml.html.builder import E [as 别名]
# 或者: from lxml.html.builder.E import a [as 别名]
def index(self):
return E.div(
E.p(E.a("Cards", href="/get_all_card")),
E.p(E.a("Sip Buddies", href="/get_all_sip_buddy")),
E.p(E.a("Extensions", href="/get_all_extension")),
)
示例11: serialize_complex_model
# 需要导入模块: from lxml.html.builder import E [as 别名]
# 或者: from lxml.html.builder.E import a [as 别名]
def serialize_complex_model(self, cls, value, locale):
sti = None
fti = cls.get_flat_type_info(cls)
is_array = False
first_child = iter(fti.values()).next()
if len(fti) == 1:
fti = first_child.get_flat_type_info(first_child)
first_child_2 = iter(fti.values()).next()
if len(fti) == 1 and first_child_2.Attributes.max_occurs > 1:
if issubclass(first_child_2, ComplexModelBase):
sti = first_child_2.get_simple_type_info(first_child_2)
is_array = True
else:
if issubclass(first_child, ComplexModelBase):
sti = first_child.get_simple_type_info(first_child)
value = value[0]
else:
raise NotImplementedError("Can only serialize single return types")
tr = {}
if self.row_class is not None:
tr['class'] = self.row_class
td = {}
if self.cell_class is not None:
td['class'] = self.cell_class
th = {}
if self.header_cell_class is not None:
th['class'] = self.header_cell_class
class_name = first_child.get_type_name()
if sti is None:
if self.field_name_attr is not None:
td[self.field_name_attr] = class_name
if is_array:
for val in value:
yield E.tr(E.td(first_child_2.to_string(val), **td), **tr)
else:
yield E.tr(E.td(first_child_2.to_string(value), **td), **tr)
else:
for k, v in sti.items():
row = E.tr(**tr)
subvalue = value
for p in v.path:
subvalue = getattr(subvalue, p, None)
if subvalue is None:
if v.type.Attributes.min_occurs == 0:
continue
else:
subvalue = ""
else:
subvalue = v.type.to_string(subvalue)
text = getattr(v.type.Attributes,'text', None)
if issubclass(v.type, ImageUri):
subvalue = E.img(src=subvalue)
if text is not None:
subvalue.attrib['alt']=text
elif issubclass(v.type, AnyUri):
if text is None:
text = subvalue
subvalue = E.a(text, href=subvalue)
if self.produce_header:
header_text = translate(v.type, locale, k)
if self.field_name_attr is None:
row.append(E.th(header_text, **th))
else:
th[self.field_name_attr] = k
row.append(E.th(header_text, **th))
if self.field_name_attr is None:
row.append(E.td(subvalue, **td))
else:
td[self.field_name_attr] = k
row.append(E.td(subvalue, **td))
yield row
示例12: _write_new_card_link
# 需要导入模块: from lxml.html.builder import E [as 别名]
# 或者: from lxml.html.builder.E import a [as 别名]
def _write_new_card_link(ctx, cls, inst, parent, name, *kwargs):
parent.write(E.a("New Card", href="/new_card"))
示例13: to_parent
# 需要导入模块: from lxml.html.builder import E [as 别名]
# 或者: from lxml.html.builder.E import a [as 别名]
def to_parent(self, ctx, cls, inst, parent, name, **kwargs):
s = self.to_unicode(cls._type_info['query'], inst.query)
q = urlencode({"q": s})
parent.write(E.a("Search %s" % inst.query,
href="{}?{}".format(inst.uri, q)))
示例14: _gen_row
# 需要导入模块: from lxml.html.builder import E [as 别名]
# 或者: from lxml.html.builder.E import a [as 别名]
def _gen_row(self, ctx, cls, inst, parent, name, from_arr=False,
array_index=None, **kwargs):
# because HtmlForm* protocols don't use the global null handler, it's
# possible for null values to reach here.
if inst is None:
return
logger.debug("Generate row for %r", cls)
with parent.element('tr'):
for k, v in self.sort_fields(cls):
attr = self.get_cls_attrs(v)
if attr.exc:
logger.debug("\tExclude table cell %r type %r for %r",
k, v, cls)
continue
try:
sub_value = getattr(inst, k, None)
except: # e.g. SQLAlchemy could throw NoSuchColumnError
sub_value = None
sub_name = attr.sub_name
if sub_name is None:
sub_name = k
if self.hier_delim is not None:
if array_index is None:
sub_name = "%s%s%s" % (name, self.hier_delim, sub_name)
else:
sub_name = "%s[%d]%s%s" % (name, array_index,
self.hier_delim, sub_name)
logger.debug("\tGenerate table cell %r type %r for %r",
sub_name, v, cls)
td_attrs = {}
if self.field_name_attr is not None:
td_attrs[self.field_name_attr] = attr.sub_name or k
if attr.hidden:
td_attrs['style'] = 'display:None'
with parent.element('td', td_attrs):
ret = self.to_parent(ctx, v, sub_value, parent,
sub_name, from_arr=from_arr,
array_index=array_index, **kwargs)
if isgenerator(ret):
try:
while True:
sv2 = (yield)
ret.send(sv2)
except Break as b:
try:
ret.throw(b)
except StopIteration:
pass
m = cls.Attributes.methods
if m is not None and len(m) > 0:
td_attrs = {}
with parent.element('td', td_attrs):
first = True
mrpc_delim = html.fromstring(" | ").text
for mn, md in self._methods(cls, inst):
if first:
first = False
else:
parent.write(mrpc_delim)
pd = { }
for k, v in self.sort_fields(cls):
if getattr(v.Attributes, 'primary_key', None):
r = self.to_unicode(v, getattr(inst, k, None))
if r is not None:
pd[k] = r
params = urlencode(pd)
mdid2key = ctx.app.interface.method_descriptor_id_to_key
href = mdid2key[id(md)].rsplit("}",1)[-1]
text = md.translate(ctx.locale,
md.in_message.get_type_name())
parent.write(E.a(text, href="%s?%s" % (href, params)))
logger.debug("Generate row for %r done.", cls)
self.extend_data_row(ctx, cls, inst, parent, name,
array_index=array_index, **kwargs)
示例15: _write_new_sip_buddy_link
# 需要导入模块: from lxml.html.builder import E [as 别名]
# 或者: from lxml.html.builder.E import a [as 别名]
def _write_new_sip_buddy_link(ctx, cls, inst, parent, name, *kwargs):
parent.write(E.a("New SipBuddy", href="/new_sip_buddy"))