本文整理汇总了Python中Cheetah.Template.Template.url方法的典型用法代码示例。如果您正苦于以下问题:Python Template.url方法的具体用法?Python Template.url怎么用?Python Template.url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cheetah.Template.Template
的用法示例。
在下文中一共展示了Template.url方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ToGo
# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import url [as 别名]
def ToGo(self, handler, query):
subcname = query['Container'][0]
cname = subcname.split('/')[0]
for name, data in config.getShares():
if cname == name:
if 'tivo_mak' in data:
tivo_mak = data['tivo_mak']
else:
tivo_mak = ""
if 'togo_path' in data:
togo_path = data['togo_path']
else:
togo_path = ""
if tivo_mak != "" and togo_path != "":
parse_url = urlparse(str(query['Url'][0]))
theurl = 'http://' + parse_url[1].split(':')[0] + parse_url[2] + "?" + parse_url[4]
password = tivo_mak #TiVo MAK
tivoIP = query['TiVo'][0]
name = unquote(parse_url[2])[10:300].split('.')
name.insert(-1," - " + unquote(parse_url[4]).split("id=")[1] + ".")
outfile = os.path.join(togo_path, "".join(name))
status[theurl] = {'running':True, 'error':'', 'rate':'', 'finished':False}
thread.start_new_thread(Admin.get_tivo_file, (self, theurl, password, tivoIP, outfile))
handler.send_response(200)
handler.end_headers()
t = Template(file=os.path.join(SCRIPTDIR,'templates', 'redirect.tmpl'))
t.container = cname
t.time = '3'
t.url = '/'+ query['Redirect'][0]
t.text = '<h3>Transfer Initiated.</h3> <br>You selected transfer has been initiated.'+\
'<br> The <a href="/'+ query['Redirect'][0] +'"> ToGo</a> page will reload in 3 seconds.'
handler.wfile.write(t)
else:
handler.send_response(200)
handler.end_headers()
t = Template(file=os.path.join(SCRIPTDIR,'templates', 'redirect.tmpl'))
t.container = cname
t.time = '10'
t.url = '/'+ query['Redirect'][0]
t.text = '<h3>Missing Data.</h3> <br>You must set both "tivo_mak" and "togo_path" before using this function.'+\
'<br> The <a href="/'+ query['Redirect'][0] +'"> ToGo</a> page will reload in 10 seconds.'
handler.wfile.write(t)
示例2: ToGoStop
# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import url [as 别名]
def ToGoStop(self, handler, query):
parse_url = urlparse(str(query['Url'][0]))
theurl = 'http://' + parse_url[1].split(':')[0] + parse_url[2] + "?" + parse_url[4]
status[theurl]['running'] = False
subcname = query['Container'][0]
cname = subcname.split('/')[0]
handler.send_response(200)
handler.end_headers()
t = Template(file=os.path.join(SCRIPTDIR,'templates', 'redirect.tmpl'))
t.container = cname
t.time = '3'
t.url = '/'+ query['Redirect'][0]
t.text = '<h3>Transfer Stopped.</h3> <br>Your transfer has been stopped.'+\
'<br> The <a href="/'+ query['Redirect'][0] +'"> ToGo</a> page will reload in 3 seconds.'
handler.wfile.write(t)
示例3: render_email_for_commitor
# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import url [as 别名]
def render_email_for_commitor(commit_id, commit_info):
author = commit_info["author"]
token = utils.md5_encryption(author, commit_id, config.server["cvproxy"])
para_dict = {
"author": author,
"commit_id": commit_id,
"token": token}
log.debug("check parameters: %s" % para_dict)
url_base = config.server["cvproxy"]
params = urllib.urlencode(para_dict)
url_suffix = "currentrequest?%s" % params
url = "/".join([url_base, url_suffix])
# Cheetah template engine:
templ_path = config.server["templates"]
template = Template(file = os.path.join(templ_path, "review_request.tmpl"))
template.url = url
template.commit_id = commit_id
return str(template)
示例4: Reset
# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import url [as 别名]
def Reset(self, handler, query):
config.reset()
handler.server.reset()
if 'last_page' in query:
last_page = query['last_page'][0]
else:
last_page = 'Admin'
subcname = query['Container'][0]
cname = subcname.split('/')[0]
handler.send_response(200)
handler.end_headers()
t = Template(file=os.path.join(SCRIPTDIR,'templates', 'redirect.tmpl'))
t.container = cname
t.time = '3'
t.url = '/TiVoConnect?Command='+ last_page +'&Container=' + cname
t.text = '<h3>The pyTivo Server has been soft reset.</h3> <br>pyTivo has reloaded the pyTivo.conf'+\
'file and all changed should now be in effect. <br> The'+ \
'<a href="/TiVoConnect?Command='+ last_page +'&Container='+ cname +'"> previous</a> page will reload in 3 seconds.'
handler.wfile.write(t)
debug.debug_write(__name__, debug.fn_attr(), ['The pyTivo Server has been soft reset.'])
debug.print_conf(__name__, debug.fn_attr())
示例5: SaveNPL
# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import url [as 别名]
def SaveNPL(self, handler, query):
config = ConfigParser.ConfigParser()
config.read(config_file_path)
if 'tivo_mak' in query:
config.set(query['Container'][0], 'tivo_mak', query['tivo_mak'][0])
if 'togo_path' in query:
config.set(query['Container'][0], 'togo_path', query['togo_path'][0])
f = open(config_file_path, "w")
config.write(f)
f.close()
subcname = query['Container'][0]
cname = subcname.split('/')[0]
handler.send_response(200)
handler.end_headers()
t = Template(file=os.path.join(SCRIPTDIR,'templates', 'redirect.tmpl'))
t.container = cname
t.time = '2'
t.url = '/TiVoConnect?last_page=NPL&Command=Reset&Container=' + cname
t.text = '<h3>Your Settings have been saved.</h3> <br>You settings have been saved to the pyTivo.conf file.'+\
'pyTivo will now do a <b>Soft Reset</b> to allow these changes to take effect.'+\
'<br> The <a href="/TiVoConnect?last_page=NPL&Command=Reset&Container='+ cname +'"> Reset</a> will occur in 2 seconds.'
handler.wfile.write(t)
示例6: UpdateSettings
# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import url [as 别名]
def UpdateSettings(self, handler, query):
config = ConfigParser.ConfigParser()
config.read(config_file_path)
for key in query:
if key.startswith('Server.'):
section, option = key.split('.')
if option == "new__setting":
new_setting = query[key][0]
continue
if option == "new__value":
new_value = query[key][0]
continue
if query[key][0] == " ":
config.remove_option(section, option)
else:
config.set(section, option, query[key][0])
if not(new_setting == ' ' and new_value == ' '):
config.set('Server', new_setting, new_value)
sections = query['Section_Map'][0].split(']')
sections.pop() #last item is junk
for section in sections:
ID, name = section.split('|')
if query[ID][0] == "Delete_Me":
config.remove_section(name)
continue
if query[ID][0] != name:
config.remove_section(name)
config.add_section(query[ID][0])
for key in query:
if key.startswith(ID + '.'):
junk, option = key.split('.')
if option == "new__setting":
new_setting = query[key][0]
continue
if option == "new__value":
new_value = query[key][0]
continue
if query[key][0] == " ":
config.remove_option(query[ID][0], option)
else:
config.set(query[ID][0], option, query[key][0])
if not(new_setting == ' ' and new_value == ' '):
config.set(query[ID][0], new_setting, new_value)
if query['new_Section'][0] != " ":
config.add_section(query['new_Section'][0])
f = open(config_file_path, "w")
config.write(f)
f.close()
subcname = query['Container'][0]
cname = subcname.split('/')[0]
handler.send_response(200)
handler.end_headers()
t = Template(file=os.path.join(SCRIPTDIR,'templates', 'redirect.tmpl'))
t.container = cname
t.time = '10'
t.url = '/TiVoConnect?Command=Admin&Container=' + cname
t.text = '<h3>Your Settings have been saved.</h3> <br>You settings have been saved to the pyTivo.conf file.'+\
'However you will need to do a <b>Soft Reset</b> before these changes will take effect.'+\
'<br> The <a href="/TiVoConnect?Command=Admin&Container='+ cname +'"> Admin</a> page will reload in 10 seconds.'
handler.wfile.write(t)
示例7: NPL
# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import url [as 别名]
def NPL(self, handler, query):
shows_per_page = 50 #Change this to alter the number of shows returned per page
subcname = query['Container'][0]
cname = subcname.split('/')[0]
folder = ''
AnchorItem = ''
AnchorOffset= ''
for name, data in config.getShares():
if cname == name:
if 'tivo_mak' in data:
tivo_mak = data['tivo_mak']
else:
tivo_mak = ""
if 'togo_path' in data:
togo_path = data['togo_path']
else:
togo_path = ""
if 'TiVo' in query:
tivoIP = query['TiVo'][0]
theurl = 'https://'+ tivoIP +'/TiVoConnect?Command=QueryContainer&ItemCount='+ str(shows_per_page) +'&Container=/NowPlaying'
if 'Folder' in query:
folder += str(query['Folder'][0])
theurl += '/' + folder
if 'AnchorItem' in query:
AnchorItem += str(query['AnchorItem'][0])
theurl += '&AnchorItem=' + quote(AnchorItem)
if 'AnchorOffset' in query:
AnchorOffset += str(query['AnchorOffset'][0])
theurl += '&AnchorOffset=' + AnchorOffset
password = tivo_mak #TiVo MAK
r=urllib2.Request(theurl)
auth_handler = urllib2.HTTPDigestAuthHandler()
auth_handler.add_password('TiVo DVR', tivoIP, 'tivo', password)
opener = urllib2.build_opener(auth_handler)
urllib2.install_opener(opener)
if theurl in tivo_cache: #check to see if we have accessed this page before
if tivo_cache[theurl]['thepage'] == '' or (time.time() - tivo_cache[theurl]['thepage_time']) >= 60: #if page is empty or old then retreive it
try:
handle = urllib2.urlopen(r)
except IOError, e:
handler.send_response(200)
handler.end_headers()
t = Template(file=os.path.join(SCRIPTDIR,'templates', 'redirect.tmpl'))
t.container = cname
t.time = '20'
t.url = '/TiVoConnect?Command=NPL&Container=' + cname
t.text = '<h3>Unable to Connect to TiVo.</h3> <br>pyTivo was unable to connect to the TiVo at ' + tivoIP +\
'<br>This most likely caused by an incorrect Media Access Key. Please return to the ToGo page and double check your Media Access Key.' +\
'<br> The <a href="/TiVoConnect?Command=NPL&Container='+ cname + '"> ToGo</a> page will reload in 20 seconds.'
handler.wfile.write(t)
return
tivo_cache[theurl]['thepage'] = handle.read()
tivo_cache[theurl]['thepage_time'] = time.time()
else: #not in cache
try:
handle = urllib2.urlopen(r)
except IOError, e:
handler.send_response(200)
handler.end_headers()
t = Template(file=os.path.join(SCRIPTDIR,'templates', 'redirect.tmpl'))
t.container = cname
t.time = '20'
t.url = '/TiVoConnect?Command=NPL&Container=' + cname
t.text = '<h3>Unable to Connect to TiVo.</h3> <br>pyTivo was unable to connect to the TiVo at ' + tivoIP +\
'<br>This most likely caused by an incorrect Media Access Key. Please return to the ToGo page and double check your Media Access Key.' +\
'<br> The <a href="/TiVoConnect?Command=NPL&Container='+ cname + '"> ToGo</a> page will reload in 20 seconds.'
handler.wfile.write(t)
return
tivo_cache[theurl] = {}
tivo_cache[theurl]['thepage'] = handle.read()
tivo_cache[theurl]['thepage_time'] = time.time()
示例8: Template
# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import url [as 别名]
'''
Created on Aug 7, 2012
@author: Mingze
'''
from Cheetah.Template import Template
templateDef = """
<HTML>
<HEAD><TITLE>$title</TITLE></HEAD>
<BODY>
$contents
##This is the single line
#* This is the multiple lines
*#
</BODY>
</HTML>"""
nameSpace = {"title": "Hello World Example", "contents": "Hello World!"}
t = Template(templateDef, searchList=[nameSpace])
t2 = Template(file = "../templates/review_request.tmpl")
t2.url = "http://10.197.84.110:8011"
t2.commit_id = "10086"
if __name__ == "__main__" :
print t2