本文整理汇总了Python中lxml.html.builder.E.link方法的典型用法代码示例。如果您正苦于以下问题:Python E.link方法的具体用法?Python E.link怎么用?Python E.link使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lxml.html.builder.E
的用法示例。
在下文中一共展示了E.link方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: google_fonts
# 需要导入模块: from lxml.html.builder import E [as 别名]
# 或者: from lxml.html.builder.E import link [as 别名]
def google_fonts(font_names, standalone=False):
GOOGLE_API_KEY = "AIzaSyCXe6WAu7i4CYL9ee-RFNZirObwT4zJyqI"
url = "https://www.googleapis.com/webfonts/v1/webfonts"
https_proxy = os.environ.get("https_proxy")
if https_proxy is not None:
proxy_support = urllib2.ProxyHandler({"https": https_proxy})
opener = urllib2.build_opener(proxy_support)
urllib2.install_opener(opener)
info = json.loads(urllib2.urlopen(url + "?key=" + GOOGLE_API_KEY).read())
if standalone:
css = ""
css_template = \
"""
@font-face {{
font-family: {name!r};
font-style: {style};
font-weight: {weight};
src: url({file!r});
}}
"""
for font_name in font_names:
for font_info in info["items"]:
if font_info["family"] == font_name:
variants = font_info["variants"]
files = font_info["files"]
for variant in variants:
subinfo("downloading {0}".format(font_name + " " + variant))
ttf_bytes = urllib.urlopen(files[variant]).read()
ttf_path = Path("fonts") / (font_name + " " + variant + ".ttf")
ttf_file = (ARTDOC / ttf_path).open("wb")
ttf_file.write(ttf_bytes)
ttf_file.close()
style = "normal" if "italic" not in variant else "italic"
weight = re.match("[0-9]*", variant).group() or "400"
css += css_template.format(name=font_name,
style=style,
weight=weight,
file=str(Path("..") / ttf_path))
break
(ARTDOC / "css" / "fonts.css").open("wb").write(css)
return [HTML.link(rel="stylesheet", href=".artdoc/css/fonts.css")]
else:
families = []
for font_name in font_names:
for font_info in info["items"]:
if font_info["family"] == font_name:
family = font_name.replace(" ", "+") + ":"
variants = font_info["variants"]
family += ",".join(variants)
families.append(family)
break
family = "|".join(families) + "&subset=latin,latin-ext"
url = "http://fonts.googleapis.com/css?family=" + family
return [HTML.link(rel="stylesheet", href=url)]
示例2: font_awesome
# 需要导入模块: from lxml.html.builder import E [as 别名]
# 或者: from lxml.html.builder.E import link [as 别名]
def font_awesome(url="http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css",
standalone_url="http://fortawesome.github.io/Font-Awesome/assets/font-awesome-4.3.0.zip",
standalone=False):
if standalone:
zip_file = tempfile.NamedTemporaryFile(suffix=".zip", delete=False)
zip_file.write(urllib.urlopen(standalone_url).read())
zip_filename = zip_file.name
zip_file.close()
zipfile.ZipFile(zip_filename).extractall(str(ARTDOC))
os.remove(zip_filename)
return [HTML.link(rel="stylesheet", href=".artdoc/font-awesome-4.3.0/css/font-awesome.min.css")]
else:
return [HTML.link(rel="stylesheet", href=url)]
示例3: _build_html_stylesheets
# 需要导入模块: from lxml.html.builder import E [as 别名]
# 或者: from lxml.html.builder.E import link [as 别名]
def _build_html_stylesheets(self):
for url in self.stylesheets:
self.elements.head.append(
E.link(rel='stylesheet', type='text/css', href=url))
示例4: _build_html_head_links
# 需要导入模块: from lxml.html.builder import E [as 别名]
# 或者: from lxml.html.builder.E import link [as 别名]
def _build_html_head_links(self):
'''Builds the link elements.'''
head = self.elements.head
for key, value in self.links.items():
head.append(E.link(rel=key, href=value))
示例5: artdoc
# 需要导入模块: from lxml.html.builder import E [as 别名]
# 或者: from lxml.html.builder.E import link [as 别名]
def artdoc():
return [
HTML.link(rel="stylesheet", href=".artdoc/css/style.css"),
HTML.script(src=".artdoc/js/main.js")
]