本文整理汇总了Python中template.Template.set_defaults方法的典型用法代码示例。如果您正苦于以下问题:Python Template.set_defaults方法的具体用法?Python Template.set_defaults怎么用?Python Template.set_defaults使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类template.Template
的用法示例。
在下文中一共展示了Template.set_defaults方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CGI
# 需要导入模块: from template import Template [as 别名]
# 或者: from template.Template import set_defaults [as 别名]
class CGI(basecgi.CGI):
root = config.root_path
sep = config.query_separator
appli = config.application
gateway_cgi = config.gateway
thread_cgi = config.thread_cgi
admin_cgi = config.admin_cgi
message = None
filter = None
str_filter = ''
tag = None
str_tag = ''
def __init__(self,
stdin=sys.stdin,
stdout=sys.stdout,
stderr=sys.stderr,
environ=os.environ):
basecgi.CGI.__init__(self,
stdin=stdin,
stdout=stdout,
stderr=stderr,
environ=environ)
if "HTTP_ACCEPT_LANGUAGE" in self.environ:
al = self.environ["HTTP_ACCEPT_LANGUAGE"]
else:
al = ""
self.message = search_message(al)
addr = self.environ.get("REMOTE_ADDR", "")
self.remoteaddr = addr
self.isadmin = config.re_admin.search(addr)
self.isfriend = config.re_friend.search(addr)
self.isvisitor = config.re_visitor.search(addr)
self.obj_template = Template()
self.template = self.obj_template.display
var = {
'cgi': self,
'environ': self.environ,
'ua': self.environ.get('HTTP_USER_AGENT', ''),
'message': self.message,
'lang': self.message['lang'],
'config': config,
'appli': self.appli,
'gateway_cgi': self.gateway_cgi,
'thread_cgi': self.thread_cgi,
'admin_cgi': self.admin_cgi,
'root_path': config.root_path,
'types': config.types,
'isadmin': self.isadmin,
'isfriend': self.isfriend,
'isvisitor': self.isvisitor,
'localtime': self.localtime,
'str_encode': self.str_encode,
'file_decode': self.file_decode,
'escape': self.escape,
'escape_simple': lambda s: cgi.escape(s, True),
'escape_space': self.escape_space,
'escape_js': self.escape_js,
'make_list_item': self.make_list_item,
'gateway_link': self.gateway_link,
'dummyquery': dummyquery,
}
self.obj_template.set_defaults(var)
def path_info(self):
"""Parse PATH_INFO.
If PATH_INFO is not defined, use QUERY_STRING.
x.cgi?foo&bar=y -> path="foo".
"""
m = re.search(r"([^&;=]*)(&|$)", self.environ.get("QUERY_STRING", ""))
if self.environ.get("PATH_INFO", "") != "":
path = self.environ["PATH_INFO"]
if path.startswith("/"):
path = path[1:]
elif m is not None:
path = m.group(1)
else:
path = ""
path = self.escape(self.str_decode(path))
return path
def str_encode(self, query):
return str_encode(query)
def str_decode(self, query):
return str_decode(query)
def file_encode(self, type, query):
return file_encode(type, query)
def file_decode(self, query):
return file_decode(query)
def escape(self, msg):
msg = msg.replace("&", "&")
msg = re.sub(r"&(#\d+|#[Xx][0-9A-Fa-f]+|[A-Za-z0-9]+);",
r"&\1;",
msg)
#.........这里部分代码省略.........
示例2: CGI
# 需要导入模块: from template import Template [as 别名]
# 或者: from template.Template import set_defaults [as 别名]
class CGI(basecgi.CGI):
root = config.root_path
sep = config.query_separator
appli = config.application
gateway_cgi = config.gateway
thread_cgi = config.thread_cgi
admin_cgi = config.admin_cgi
mobile_cgi = config.mobile_cgi
message = None
filter = None
str_filter = ""
tag = None
str_tag = ""
def __init__(self, stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr, environ=os.environ):
basecgi.CGI.__init__(self, stdin=stdin, stdout=stdout, stderr=stderr, environ=environ)
if "HTTP_ACCEPT_LANGUAGE" in self.environ:
al = self.environ["HTTP_ACCEPT_LANGUAGE"]
else:
al = ""
self.message = search_message(al)
addr = self.environ.get("REMOTE_ADDR", "")
self.isadmin = config.re_admin.search(addr)
self.isfriend = config.re_friend.search(addr)
self.isvisitor = config.re_visitor.search(addr)
self.obj_template = Template()
self.template = self.obj_template.display
var = {
"cgi": self,
"environ": self.environ,
"ua": self.environ.get("HTTP_USER_AGENT", ""),
"message": self.message,
"lang": self.message["lang"],
"config": config,
"appli": self.appli,
"gateway_cgi": self.gateway_cgi,
"thread_cgi": self.thread_cgi,
"admin_cgi": self.admin_cgi,
"mobile_cgi": self.mobile_cgi,
"root_path": config.root_path,
"archive_uri": config.archive_uri,
"types": config.types,
"isadmin": self.isadmin,
"isfriend": self.isfriend,
"isvisitor": self.isvisitor,
"localtime": self.localtime,
"str_encode": self.str_encode,
"file_decode": self.file_decode,
"escape": self.escape,
"escape_simple": lambda s: cgi.escape(s, True),
"escape_space": self.escape_space,
"escape_js": self.escape_js,
"make_list_item": self.make_list_item,
"gateway_link": self.gateway_link,
}
self.obj_template.set_defaults(var)
def path_info(self):
"""Parse PATH_INFO.
If PATH_INFO is not defined, use QUERY_STRING.
x.cgi?foo&bar=y -> path="foo".
"""
m = re.search(r"([^&;=]*)(&|$)", self.environ.get("QUERY_STRING", ""))
if self.environ.get("PATH_INFO", "") != "":
path = self.environ["PATH_INFO"]
if path.startswith("/"):
path = path[1:]
elif m is not None:
path = m.group(1)
else:
path = ""
path = self.escape(self.str_decode(path))
return path
def str_encode(self, query):
return str_encode(query)
def str_decode(self, query):
return str_decode(query)
def file_encode(self, type, query):
return file_encode(type, query)
def file_decode(self, query):
return file_decode(query)
def escape(self, msg):
msg = msg.replace("&", "&")
msg = re.sub(r"&(#\d+|#[Xx][0-9A-Fa-f]+|[A-Za-z0-9]+);", r"&\1;", msg)
msg = msg.replace("<", "<")
msg = msg.replace(">", ">")
msg = msg.replace("\r", "")
msg = msg.replace("\n", "<br>")
return msg
def gateway_link(self, cginame, command):
var = {"cginame": cginame, "command": command, "description": self.message.get("desc_" + command, "")}
return self.template("gateway_link", var)
#.........这里部分代码省略.........