本文整理汇总了Python中Cheetah.Template.Template.text方法的典型用法代码示例。如果您正苦于以下问题:Python Template.text方法的具体用法?Python Template.text怎么用?Python Template.text使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cheetah.Template.Template
的用法示例。
在下文中一共展示了Template.text方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: multipartTestPage
# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import text [as 别名]
def multipartTestPage(self):
omras_page = Template(file="./templates/omras-template.html")
omras_page.title = "Sonic Annotator Webapplication"
#content = main content within an omras page
content = Template(file="./templates/main-content.html")
content.title = "OMRAS2 Music Analysis and Feature Extraction Service"
#see if we have audio, hence if we need the id block...
if cherrypy.session.has_key('audio_file') :
#file_id_block = list of files uploaded so far
filelist = list(cherrypy.session['audio_file'])
file_id_block = Template(file="./templates/fileID-block.html")
file_id_block.section_title = "File Identification"
file_id_block.javascript_data = self.jsDataGenerator(filelist)
file_id_block.file_list = list(cherrypy.session['audio_file'])
content.file_id_block = str(file_id_block)
omras_page.on_load_script = """ window.location.hash="upload_file" """
else:
content.file_id_block = ''
omras_page.on_load_script = ''
vamp_transforms = self.sonic.getTransforms()
content.text = vamp_transforms.items()
content.transforms = vamp_transforms
content.sessionID = self.server.getSessionID()
omras_page.content = str(content)
count = cherrypy.session.get('count', 0) + 1
cherrypy.session['count'] = count
return str(omras_page)
示例2: show_error
# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import text [as 别名]
def show_error(req, error, text = ""):
t = Template(file=tmpl_prefix + "error.tmpl")
t.workdir = workdir
t.title = "Error"
t.error = error
t.text = text
req.write(str(t))
示例3: ToGo
# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import text [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)
示例4: ToGoStop
# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import text [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)
示例5: saTestPage
# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import text [as 别名]
def saTestPage(self):
trs = self.sonic.getTransforms()
# print trs.items()
result = Template(file="./templates/index2.html")
result.text = trs.items()
result.transforms = trs
result.sessionID = self.server.getSessionID()
server = self.config.server
count = cherrypy.session.get('count', 0) + 1
cherrypy.session['count'] = count
t = cherrypy.session.clean_thread
s = cherrypy.session
# currentCB = cherrypy.session.clean_thread.callback
# cherrypy.session.clean_thread.callback = self.newCallback
# result.session_data = str(dir(t)) + " \n" + str(dir(t.callback))
result.session_data = '>>'+str(type(cherrypy.session))
# print dir(cherrypy.session.clean_thread.callback)
# print cherrypy.session.timeout
# print cherrypy.session.clean_freq
# print hasattr(cherrypy.session,'cache')
#we are in a RamSession Class: s
print 'clean thread', s.clean_thread
print 'callback', s.clean_thread.callback
# self.originalCallback = s.clean_thread.callback
# cherrypy.session.clean_thread.callback = self.newCallback
# print 'reassigned callback', s.clean_thread.callback
#restart the Monitor (cleanup) thread
# s.clean_thread.graceful()
#make sure the thread is started
# s['make_start_thread'] = 1
#change the callback to ours...
return str(result)
示例6: Reset
# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import text [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())
示例7: SaveNPL
# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import text [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)
示例8: UpdateSettings
# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import text [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)
示例9: NPL
# 需要导入模块: from Cheetah.Template import Template [as 别名]
# 或者: from Cheetah.Template.Template import text [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()