本文整理汇总了Python中pystache.loader.Loader类的典型用法代码示例。如果您正苦于以下问题:Python Loader类的具体用法?Python Loader怎么用?Python Loader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Loader类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_read
def test_read(self):
"""
Test read().
"""
reader = Loader()
path = self._get_path("ascii.mustache")
actual = reader.read(path)
self.assertString(actual, u"ascii: abc")
开发者ID:chuanzhang,项目名称:pystache,代码行数:9,代码来源:test_loader.py
示例2: test_read
def test_read(self):
"""
Test read().
"""
loader = Loader()
path = self._get_path('ascii.mustache')
actual = loader.read(path)
self.assertString(actual, 'ascii: abc')
开发者ID:phihag,项目名称:py3stache,代码行数:9,代码来源:test_loader.py
示例3: test_unicode__basic__input_unicode
def test_unicode__basic__input_unicode(self):
"""
Test unicode(): default arguments with unicode input.
"""
loader = Loader()
actual = loader.str("foo")
self.assertString(actual, "foo")
开发者ID:phihag,项目名称:py3stache,代码行数:9,代码来源:test_loader.py
示例4: test_unicode__basic__input_str
def test_unicode__basic__input_str(self):
"""
Test unicode(): default arguments with str input.
"""
reader = Loader()
actual = reader.unicode("foo")
self.assertString(actual, u"foo")
开发者ID:clach04,项目名称:pystache,代码行数:9,代码来源:test_loader.py
示例5: test_read__encoding__argument
def test_read__encoding__argument(self):
"""
Test read(): encoding argument respected.
"""
reader = Loader()
path = self._get_path("non_ascii.mustache")
self.assertRaises(UnicodeDecodeError, reader.read, path)
actual = reader.read(path, encoding="utf-8")
self.assertString(actual, u"non-ascii: é")
开发者ID:chuanzhang,项目名称:pystache,代码行数:12,代码来源:test_loader.py
示例6: get
def get(self):
pass_phrase = self.authenticate_request()
if pass_phrase:
if self.check_setup():
loader = Loader(extension='html', search_dirs=['view', 'view/setup'])
renderer = Renderer(file_extension='html',
search_dirs=['view/partials', 'view/setup'])
template = loader.load_name('setup')
html = renderer.render(template, {"pass": pass_phrase})
self.write(html)
else:
self.write("setup already completed.")
开发者ID:Web5design,项目名称:autopilot,代码行数:12,代码来源:setup.py
示例7: test_read__encoding__argument
def test_read__encoding__argument(self):
"""
Test read(): encoding argument respected.
"""
loader = Loader()
path = self._get_path('non_ascii.mustache')
self.assertRaises(UnicodeDecodeError, loader.read, path)
actual = loader.read(path, encoding='utf-8')
self.assertString(actual, 'non-ascii: é')
开发者ID:phihag,项目名称:py3stache,代码行数:12,代码来源:test_loader.py
示例8: test_unicode__encoding_argument
def test_unicode__encoding_argument(self):
"""
Test unicode(): encoding argument.
"""
reader = Loader()
non_ascii = u"abcdé".encode("utf-8")
self.assertRaises(UnicodeDecodeError, reader.unicode, non_ascii)
actual = reader.unicode(non_ascii, encoding="utf-8")
self.assertString(actual, u"abcdé")
开发者ID:chuanzhang,项目名称:pystache,代码行数:13,代码来源:test_loader.py
示例9: test_unicode__encoding_argument
def test_unicode__encoding_argument(self):
"""
Test unicode(): encoding argument.
"""
loader = Loader()
non_ascii = 'abcdé'.encode('utf-8')
self.assertRaises(UnicodeDecodeError, loader.str, non_ascii)
actual = loader.str(non_ascii, encoding='utf-8')
self.assertString(actual, 'abcdé')
开发者ID:phihag,项目名称:py3stache,代码行数:13,代码来源:test_loader.py
示例10: test_read__file_encoding__attribute
def test_read__file_encoding__attribute(self):
"""
Test read(): file_encoding attribute respected.
"""
loader = Loader()
path = self._get_path('non_ascii.mustache')
self.assertRaises(UnicodeDecodeError, loader.read, path)
loader.file_encoding = 'utf-8'
actual = loader.read(path)
self.assertString(actual, 'non-ascii: é')
开发者ID:phihag,项目名称:py3stache,代码行数:13,代码来源:test_loader.py
示例11: get
def get(self, article_name):
article_name = article_name.lower()
if article_name in BaseController.articles:
article = BaseController.articles[article_name]
# if content has not modified since last request
# send a 304 not modified status
modified_header_key = "If-Modified-Since"
if modified_header_key in self.request.headers:
if (self.request.headers["If-Modified-Since"] ==
article['modified_date']):
self.set_status(304)
return
if (BaseController.settings['enable_caching'] and
article_name in BaseController.cached_articles):
html = BaseController.cached_articles[article_name]
else:
view_model = {
"article": article,
"site_name": BaseController.settings['site_name']
}
self.attach_meta_data(view_model)
loader = Loader(file_encoding='utf8',
extension='html',
search_dirs=['view', ])
renderer = Renderer(file_encoding='utf8',
file_extension='html',
search_dirs=['view/partials'])
template = loader.load_name('article')
html = renderer.render(template, view_model)
# cache the html
BaseController.cached_articles[article_name] = html
# set http caching headers
if "http_caching_max_age" in BaseController.settings:
max_age = BaseController.settings["http_caching_max_age"]
else:
max_age = 60
self.set_header("Cache-control", "max-age=%s" % max_age)
self.set_header("Last-Modified", article['modified_date'])
self.write(html)
else:
raise tornado.web.HTTPError(404)
开发者ID:Web5design,项目名称:autopilot,代码行数:50,代码来源:article.py
示例12: test_unicode__basic__input_unicode_subclass
def test_unicode__basic__input_unicode_subclass(self):
"""
Test unicode(): default arguments with unicode-subclass input.
"""
class UnicodeSubclass(str):
pass
s = UnicodeSubclass("foo")
loader = Loader()
actual = loader.str(s)
self.assertString(actual, "foo")
开发者ID:phihag,项目名称:py3stache,代码行数:14,代码来源:test_loader.py
示例13: generate_page
def generate_page(self, articles):
view_model = {
"articles": articles,
"site_name": BaseController.settings["site_name"]
}
self.attach_meta_data(view_model)
loader = Loader(file_encoding='utf8', extension='html',
search_dirs=['view', ])
renderer = Renderer(file_encoding='utf8', file_extension='html',
search_dirs=['view/partials'])
template = loader.load_name('list')
html = renderer.render(template, view_model)
return html
开发者ID:Web5design,项目名称:autopilot,代码行数:14,代码来源:list.py
示例14: test_unicode__to_unicode__attribute
def test_unicode__to_unicode__attribute(self):
"""
Test unicode(): encoding attribute.
"""
loader = Loader()
non_ascii = 'abcdé'.encode('utf-8')
self.assertRaises(UnicodeDecodeError, loader.str, non_ascii)
def to_unicode(s, encoding=None):
if encoding is None:
encoding = 'utf-8'
return str(s, encoding)
loader.to_unicode = to_unicode
self.assertString(loader.str(non_ascii), "abcdé")
开发者ID:phihag,项目名称:py3stache,代码行数:17,代码来源:test_loader.py
示例15: test_unicode__to_unicode__attribute
def test_unicode__to_unicode__attribute(self):
"""
Test unicode(): encoding attribute.
"""
reader = Loader()
non_ascii = u'abcdé'.encode('utf-8')
self.assertRaises(UnicodeDecodeError, reader.unicode, non_ascii)
def to_unicode(s, encoding=None):
if encoding is None:
encoding = 'utf-8'
return unicode(s, encoding)
reader.to_unicode = to_unicode
self.assertString(reader.unicode(non_ascii), u"abcdé")
开发者ID:clach04,项目名称:pystache,代码行数:18,代码来源:test_loader.py
示例16: index
def index():
loader = Loader()
template = loader.load_name('index')
response = requests.get('http://www.unboxedconsulting.com/people/carl-whittaker')
status = response.status_code
if status == 200:
content = response.content
soup = BeautifulSoup(content)
image = 'http://www.unboxedconsulting.com' + soup.select('a.front img')[0]['src']
else:
image = ''
return pystache.render(
template,
{
'has_caricature': status == 200,
'image': image
}
)
开发者ID:kevincarrogan,项目名称:carlcaricature,代码行数:21,代码来源:app.py
示例17: test_init__to_unicode__default
def test_init__to_unicode__default(self):
loader = Loader()
self.assertRaises(TypeError, loader.to_unicode, u"abc")
decode_errors = defaults.DECODE_ERRORS
string_encoding = defaults.STRING_ENCODING
nonascii = "abcdé"
try:
defaults.DECODE_ERRORS = "strict"
defaults.STRING_ENCODING = "ascii"
loader = Loader()
self.assertRaises(UnicodeDecodeError, loader.to_unicode, nonascii)
defaults.DECODE_ERRORS = "ignore"
loader = Loader()
self.assertString(loader.to_unicode(nonascii), u"abcd")
defaults.STRING_ENCODING = "utf-8"
loader = Loader()
self.assertString(loader.to_unicode(nonascii), u"abcdé")
finally:
defaults.DECODE_ERRORS = decode_errors
defaults.STRING_ENCODING = string_encoding
开发者ID:chuanzhang,项目名称:pystache,代码行数:26,代码来源:test_loader.py
示例18: get
def get(self):
if (BaseController.settings['enable_caching'] and
BaseController.cached_home):
html = BaseController.cached_home
self.write(html)
else:
published_articles = []
for article in BaseController.articles.values():
if article['date'] is not None:
published_articles.append(article)
articles = sorted(published_articles,
key=operator.itemgetter("date"),
reverse=True)
max_articles_count = BaseController.settings["homepage_max_articles"]
show_archive = False
if len(articles) > max_articles_count:
show_archive = True
articles = articles[0:max_articles_count]
view_model = {
"articles": articles,
"showArchive": show_archive,
"site_name": BaseController.settings["site_name"]
}
self.attach_meta_data(view_model)
loader = Loader(file_encoding='utf8', extension='html',
search_dirs=['view', ])
renderer = Renderer(file_encoding='utf8', file_extension='html',
search_dirs=['view/partials'])
template = loader.load_name('home')
html = renderer.render(template, view_model)
# cache the home page
BaseController.cached_home = html
self.write(html)
开发者ID:Web5design,项目名称:autopilot,代码行数:39,代码来源:home.py
示例19: sleep
else:
print "Droplet named `biuVPN` exists"
print droplet.name, droplet.id, droplet.ip_address, droplet.status, \
droplet.created_at
droplet_id = droplet.id
ip_address = droplet.ip_address
while not ip_address:
print "Waiting Digital Ocean creating droplet ..."
droplet.load()
ip_address = droplet.ip_address
sleep(5)
# Generate Ansible configuration files
print "Generating Ansible configuration files"
loader = Loader(extension="mustache", search_dirs=os.getcwd())
renderer = Renderer()
template = loader.load_name(os.getcwd() + "/" + "ansible_hosts")
result = renderer.render(template, {"ip_address": ip_address})
with open("ansible_hosts", 'w') as file_handler:
file_handler.write(result)
template = loader.load_name(os.getcwd() + "/" + "biuVPN.yml")
result = renderer.render(template, {"ip_address": ip_address})
with open("biuVPN.yml", 'w') as file_handler:
file_handler.write(result)
开发者ID:leechannl,项目名称:biuVPN,代码行数:30,代码来源:createDroplet.py
示例20: Flask
import os
import pystache
import gevent
import gevent.monkey
import redis
from gevent.pywsgi import WSGIServer
gevent.monkey.patch_all()
from pystache.loader import Loader
from flask import Flask, Response, request
app = Flask(__name__)
loader = Loader()
templates = {
'comic': loader.load_name('comic')
}
@app.route('/')
def index():
if request.headers.get('accept') == 'text/event-stream':
r = redis.Redis()
pubsub = r.pubsub()
pubsub.subscribe(['comic'])
def images():
for msg in pubsub.listen():
if msg['type'] == 'message':
yield 'event: comic\n'
开发者ID:kevincarrogan,项目名称:comic-book,代码行数:31,代码来源:app.py
注:本文中的pystache.loader.Loader类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论