本文整理匯總了Python中aspen.testing.client.Client._website方法的典型用法代碼示例。如果您正苦於以下問題:Python Client._website方法的具體用法?Python Client._website怎麽用?Python Client._website使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類aspen.testing.client.Client
的用法示例。
在下文中一共展示了Client._website方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: compile_assets
# 需要導入模塊: from aspen.testing.client import Client [as 別名]
# 或者: from aspen.testing.client.Client import _website [as 別名]
def compile_assets(website):
client = Client(website.www_root, website.project_root)
client._website = website
for spt in find_files(website.www_root+'/assets/', '*.spt'):
filepath = spt[:-4] # /path/to/www/assets/foo.css
urlpath = spt[spt.rfind('/assets/'):-4] # /assets/foo.css
try:
# Remove any existing compiled asset, so we can access the dynamic
# one instead (Aspen prefers foo.css over foo.css.spt).
os.unlink(filepath)
except:
pass
content = client.GET(urlpath).body
tmpfd, tmpfpath = mkstemp(dir='.')
os.write(tmpfd, content)
os.close(tmpfd)
os.rename(tmpfpath, filepath)
示例2: compile_assets
# 需要導入模塊: from aspen.testing.client import Client [as 別名]
# 或者: from aspen.testing.client.Client import _website [as 別名]
def compile_assets(website):
client = Client(website.www_root, website.project_root)
client._website = website
for spt in find_files(website.www_root+'/assets/', '*.spt'):
filepath = spt[:-4] # /path/to/www/assets/foo.css
urlpath = spt[spt.rfind('/assets/'):-4] # /assets/foo.css
try:
# Remove any existing compiled asset, so we can access the dynamic
# one instead (Aspen prefers foo.css over foo.css.spt).
os.unlink(filepath)
except:
pass
headers = {}
if website.base_url:
url = urlparse.urlparse(website.base_url)
headers[b'HTTP_X_FORWARDED_PROTO'] = str(url.scheme)
headers[b'HTTP_HOST'] = str(url.netloc)
content = client.GET(urlpath, **headers).body
tmpfd, tmpfpath = mkstemp(dir='.')
os.write(tmpfd, content.encode('utf8'))
os.close(tmpfd)
os.rename(tmpfpath, filepath)
atexit.register(lambda: clean_assets(website.www_root))
示例3: client
# 需要導入模塊: from aspen.testing.client import Client [as 別名]
# 或者: from aspen.testing.client.Client import _website [as 別名]
def client():
client = Client(www_root='www', project_root='.')
client._website = website
yield client