本文整理汇总了Python中utils.safeunicode函数的典型用法代码示例。如果您正苦于以下问题:Python safeunicode函数的具体用法?Python safeunicode怎么用?Python safeunicode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了safeunicode函数的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _escape
def _escape(self, value, escape=False):
import types
if value is None:
value = ''
elif isinstance(value, types.GeneratorType):
value = self._join_output(value)
value = safeunicode(value)
if escape and self.filter:
value = self.filter(value)
return safeunicode(value)
开发者ID:dsc,项目名称:webpy,代码行数:11,代码来源:template.py
示例2: render
def render(self):
out = ''
out += self.rendernote(self.note)
out += '<table>\n'
for i in self.inputs:
html = utils.safeunicode(i.pre) + i.render() + self.rendernote(i.note) + utils.safeunicode(i.post)
if i.is_hidden():
out += ' <tr style="display: none;"><th></th><td>%s</td></tr>\n' % (html)
else:
out += ' <tr><th><label for="%s">%s</label></th><td>%s</td></tr>\n' % (i.id, net.websafe(i.description), html)
out += "</table>"
return out
开发者ID:JirkaChadima,项目名称:webpy,代码行数:13,代码来源:form.py
示例3: render
def render(self):
out = ""
out += self.rendernote(self.note)
# out += '<table>\n'
for i in self.inputs:
html = utils.safeunicode(i.pre) + i.render() + self.rendernote(i.note) + utils.safeunicode(i.post)
if i.is_hidden():
out += " %s\n" % (html)
else:
out += ' <label for="%s">%s</label>%s\n' % (i.id, net.websafe(i.description), html)
# out += "</table>"
return out
开发者ID:28554010,项目名称:sub,代码行数:13,代码来源:form.py
示例4: render
def render(self):
out = ''
out += self.rendernote(self.note)
out += '<table>\n'
for i in self.inputs:
html = utils.safeunicode(i.pre) + i.render() + self.rendernote(i.note) + utils.safeunicode(i.post)
if i.is_hidden():
out += ' <tr style="display: none;"><th></th><td>%s</td></tr>\n' % (html)
else:
# sanitation removed by KBP because I'm lazy and this isn't a real webapp anyways
#out += ' <tr><th><label for="%s">%s</label></th><td>%s</td></tr>\n' % (i.id, net.websafe(i.description), html)
out += ' <tr><th><label for="%s">%s</label></th><td>%s</td></tr>\n' % (i.id, i.description, html)
out += "</table>"
return out
开发者ID:kpich,项目名称:source-codify,代码行数:15,代码来源:form.py
示例5: load
def load(self, env):
"""Initializes ctx using env."""
ctx = web.ctx
ctx.status = '200 OK'
ctx.headers = []
ctx.output = ''
ctx.environ = ctx.env = env
ctx.host = env.get('HTTP_HOST')
ctx.protocol = env.get('HTTPS') and 'https' or 'http'
ctx.homedomain = ctx.protocol + '://' + env.get('HTTP_HOST', '[unknown]')
ctx.homepath = os.environ.get('REAL_SCRIPT_NAME', env.get('SCRIPT_NAME', ''))
ctx.home = ctx.homedomain + ctx.homepath
#@@ home is changed when the request is handled to a sub-application.
#@@ but the real home is required for doing absolute redirects.
ctx.realhome = ctx.home
ctx.ip = env.get('REMOTE_ADDR')
ctx.method = env.get('REQUEST_METHOD')
ctx.path = env.get('PATH_INFO')
# http://trac.lighttpd.net/trac/ticket/406 requires:
if env.get('SERVER_SOFTWARE', '').startswith('lighttpd/'):
ctx.path = lstrips(env.get('REQUEST_URI').split('?')[0], ctx.homepath)
if env.get('QUERY_STRING'):
ctx.query = '?' + env.get('QUERY_STRING', '')
else:
ctx.query = ''
ctx.fullpath = ctx.path + ctx.query
for k, v in ctx.iteritems():
if isinstance(v, str):
ctx[k] = safeunicode(v)
# status must always be str
ctx.status = '200 OK'
开发者ID:btbytes,项目名称:webpy,代码行数:35,代码来源:application.py
示例6: _escape
def _escape(self, value, escape=False):
if value is None:
value = ''
value = safeunicode(value)
if escape and self.filter:
value = self.filter(value)
return value
开发者ID:wangfeng3769,项目名称:remotebox,代码行数:8,代码来源:template.py
示例7: specialFilter
def specialFilter(self):
if len(self.filters) > 0:
for filter in self.filters:
rule = filter;
rule = rule.replace('(*)', '(.+)?')
if isinstance(self.content, unicode):
rule = safeunicode(rule)
else:
rule = safestr(rule)
self.content = re.compile(rule, re.I).sub("", self.content);
开发者ID:leonardleonard,项目名称:spyder,代码行数:10,代码来源:readability.py
示例8: render
def render(self):
out = ''
if self.js:
out = self.js.render()
out += self.rendernote(self.note)
out += '<table>\n<tr>'
for i in self.inputs:
html = utils.safeunicode(i.pre) + i.render() + self.rendernote(i.note) + utils.safeunicode(i.post)
if i.is_hidden():
out += ' <th></th><td>%s</td>\n' % (html)
elif i.has_no_name():
out += ' <td>%s</td>\n' % (html)
else:
out += ' <th><label for="%s">%s</label></th><td>%s</td>\n' % (i.id, net.websafe(i.description), html)
out += "</tr></table>"
return out
开发者ID:darrenkuo,项目名称:the_clustering_experiment,代码行数:19,代码来源:form.py
示例9: load
def load(self, env):
"""Initializes ctx using env."""
ctx = web.ctx
ctx.clear()
ctx.status = '200 OK'
ctx.headers = []
ctx.output = ''
ctx.environ = ctx.env = env
ctx.host = env.get('HTTP_HOST')
if env.get('wsgi.url_scheme') in ['http', 'https']:
ctx.protocol = env['wsgi.url_scheme']
elif env.get('HTTPS', '').lower() in ['on', 'true', '1']:
ctx.protocol = 'https'
else:
ctx.protocol = 'http'
ctx.homedomain = ctx.protocol + '://' + env.get('HTTP_HOST', '[unknown]')
ctx.homepath = os.environ.get('REAL_SCRIPT_NAME', env.get('SCRIPT_NAME', ''))
ctx.home = ctx.homedomain + ctx.homepath
#@@ home is changed when the request is handled to a sub-application.
#@@ but the real home is required for doing absolute redirects.
ctx.realhome = ctx.home
ctx.ip = env.get('REMOTE_ADDR')
ctx.method = env.get('REQUEST_METHOD')
ctx.path = env.get('PATH_INFO')
# http://trac.lighttpd.net/trac/ticket/406 requires:
if env.get('SERVER_SOFTWARE', '').startswith('lighttpd/'):
ctx.path = lstrips(env.get('REQUEST_URI').split('?')[0], ctx.homepath)
# Apache and CherryPy webservers unquote the url but lighttpd doesn't.
# unquote explicitly for lighttpd to make ctx.path uniform across all servers.
ctx.path = urllib.unquote(ctx.path)
if env.get('QUERY_STRING'):
ctx.query = '?' + env.get('QUERY_STRING', '')
else:
ctx.query = ''
ctx.fullpath = ctx.path + ctx.query
for k, v in ctx.iteritems():
if isinstance(v, str):
ctx[k] = safeunicode(v)
# status must always be str
ctx.status = '200 OK'
ctx.app_stack = []
开发者ID:Anoopsmohan,项目名称:Online-lisp-Interpreter,代码行数:47,代码来源:application.py
示例10: load
def load(self, env):
"""Initializes ctx using env."""
ctx = web.ctx
ctx.clear()
ctx.status = "200 OK"
ctx.headers = []
ctx.output = ""
ctx.environ = ctx.env = env
ctx.host = env.get("HTTP_HOST")
if env.get("wsgi.url_scheme") in ["http", "https"]:
ctx.protocol = env["wsgi.url_scheme"]
elif env.get("HTTPS", "").lower() in ["on", "true", "1"]:
ctx.protocol = "https"
else:
ctx.protocol = "http"
ctx.homedomain = ctx.protocol + "://" + env.get("HTTP_HOST", "[unknown]")
ctx.homepath = os.environ.get("REAL_SCRIPT_NAME", env.get("SCRIPT_NAME", ""))
ctx.home = ctx.homedomain + ctx.homepath
# @@ home is changed when the request is handled to a sub-application.
# @@ but the real home is required for doing absolute redirects.
ctx.realhome = ctx.home
ctx.ip = env.get("REMOTE_ADDR")
ctx.method = env.get("REQUEST_METHOD")
ctx.path = env.get("PATH_INFO")
# http://trac.lighttpd.net/trac/ticket/406 requires:
if env.get("SERVER_SOFTWARE", "").startswith("lighttpd/"):
ctx.path = lstrips(env.get("REQUEST_URI").split("?")[0], ctx.homepath)
# Apache and CherryPy webservers unquote the url but lighttpd doesn't.
# unquote explicitly for lighttpd to make ctx.path uniform across all servers.
ctx.path = urllib.unquote(ctx.path)
if env.get("QUERY_STRING"):
ctx.query = "?" + env.get("QUERY_STRING", "")
else:
ctx.query = ""
ctx.fullpath = ctx.path + ctx.query
for k, v in ctx.iteritems():
if isinstance(v, str):
ctx[k] = safeunicode(v)
# status must always be str
ctx.status = "200 OK"
ctx.app_stack = []
开发者ID:navaneethrameshan,项目名称:SmartFleet,代码行数:47,代码来源:application.py
示例11: getElementData
def getElementData(obj, rule, images=None, fetch_all=0):
"""
根据rule对obj的进行解析
obj可以是pq后的对象, 也可以是html页面
images将会把解析过程的image连接插入此表中
规则可以有两种模式:
1. DOM selector
1.1 选择器类似于jquery 比如你要某个a的url
>> a.attr("href")
1.2 需要一个标签内的文本内容
>> div[id="content"].text()
1.3 需要获得某个子元素中的内容
>> li.eq(1).text() #li元素组中的第2个文本内容
2. 正则模式
正则模式需要的内容使用[arg]标签,其余可以使用(*)填充
"""
if not isinstance(obj, pq):
obj = pq(obj);
old_rule = rule
rule = rule.split(".")
#避免有url链接
if len(rule) > 1 and old_rule.find("[arg]") == -1:
#第一个永远是dom选择
selectRule = rule.pop(0)
#移除 ( )
selectRule = selectRule.replace("(", "");
selectRule = selectRule.replace(")", "");
selecteddom = obj.find(selectRule);
for attr in rule:
m = attrParrent.match(attr)
if m:
action, v = m.groups()
if v:
v = v.encode("utf-8")
#去除引号
v = v.strip("\'").strip('\"');
if action == "attr" and hasattr(selecteddom, "attr") and v:
if fetch_all == 1:
values = []
dom_count = len(selecteddom)
for i in range(dom_count):
vv = selecteddom.eq(i).attr(v)
if vv:
values.append(vv)
if is_image(vv):
images.append(vv)
return values
else:
value = selecteddom.attr(v)
if selecteddom and selecteddom[0].tag == "img" and v == "src" and images is not None:
images.append(value)
return value
elif action == "eq" and hasattr(selecteddom, "eq"):
_rules = attr.split(" ")
if len(rule) > 1:
selecteddom = selecteddom.eq(int(v))
if len(_rules) > 1:
'''
假设eq后面还有子元素
eq(1) a
'''
_rules.pop(0)
_dom = " ".join(_rules)
selecteddom = selecteddom.find(_dom)
else:
return selecteddom.eq(int(v))
elif action == "text" and hasattr(selecteddom, "text"):
return safeunicode(selecteddom.text()).strip()
elif action == "html" and hasattr(selecteddom, "html"):
return safeunicode(selecteddom.html()).strip()
elif len(rule) == 1:
rule = rule.pop()
#正则模式
if rule.find('[arg]'):
content = obj.html()
content_text = obj.text()
rule = rule.replace('[arg]', '(.+)?')
rule = rule.replace('(*)', '.+?')
if isinstance(content, unicode):
rule = safeunicode(rule)
else:
rule = safestr(rule)
parrent = re.compile(rule, re.MULTILINE | re.UNICODE)
try:
result = parrent.search(content)
if result is not None:
result = safeunicode(result.group(1)).strip()
#.........这里部分代码省略.........
开发者ID:leonardleonard,项目名称:spyder,代码行数:101,代码来源:document.py
示例12: emit
def emit(self, indent, begin_indent=''):
return repr(safeunicode(self.value))
开发者ID:wangfeng3769,项目名称:remotebox,代码行数:2,代码来源:template.py
示例13: emit
def emit(self, indent):
return repr(safeunicode(self.value))
开发者ID:dsc,项目名称:webpy,代码行数:2,代码来源:template.py
示例14: __unicode__
def __unicode__(self):
return safeunicode(self.get('__body__', ''))
开发者ID:dsc,项目名称:webpy,代码行数:2,代码来源:template.py
示例15: __unicode__
def __unicode__(self):
return safeunicode(self.get("__body__", ""))
开发者ID:mzkmzk,项目名称:jit,代码行数:2,代码来源:template.py
示例16: _join
def _join(self, *items):
return u"".join([safeunicode(item) for item in items])
开发者ID:oopos,项目名称:opspy,代码行数:2,代码来源:template.py
注:本文中的utils.safeunicode函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论