本文整理汇总了Python中web.safeunicode函数的典型用法代码示例。如果您正苦于以下问题:Python safeunicode函数的具体用法?Python safeunicode怎么用?Python safeunicode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了safeunicode函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __call__
def __call__(self, handler):
# temp hack to handle languages and users during upstream-to-www migration
if web.ctx.path.startswith("/l/"):
raise web.seeother("/languages/" + web.ctx.path[len("/l/"):])
if web.ctx.path.startswith("/user/"):
if not web.ctx.site.get(web.ctx.path):
raise web.seeother("/people/" + web.ctx.path[len("/user/"):])
real_path, readable_path = get_readable_path(web.ctx.site, web.ctx.path, self.patterns, encoding=web.ctx.encoding)
#@@ web.ctx.path is either quoted or unquoted depends on whether the application is running
#@@ using builtin-server or lighttpd. Thats probably a bug in web.py.
#@@ take care of that case here till that is fixed.
# @@ Also, the redirection must be done only for GET requests.
if readable_path != web.ctx.path and readable_path != urllib.quote(web.utf8(web.ctx.path)) and web.ctx.method == "GET":
raise web.redirect(web.safeunicode(readable_path) + web.safeunicode(web.ctx.query))
web.ctx.readable_path = readable_path
web.ctx.path = real_path
web.ctx.fullpath = web.ctx.path + web.ctx.query
out = handler()
V2_TYPES = ['works', 'books', 'people', 'authors',
'publishers', 'languages', 'account']
if out and any(web.ctx.path.startswith('/%s/' % _type) for _type in V2_TYPES):
out.v2 = True
return out
开发者ID:internetarchive,项目名称:openlibrary,代码行数:27,代码来源:readableurls.py
示例2: get_readable_path
def get_readable_path(site, path, patterns, encoding=None):
"""Returns real_path and readable_path from the given path.
The patterns is a list of (path_regex, type, property_name, default_value)
tuples.
"""
def match(path):
for pat, type, property, default_title in patterns:
m = web.re_compile('^' + pat).match(path)
if m:
prefix = m.group()
extra = web.lstrips(path, prefix)
tokens = extra.split("/", 2)
# `extra` starts with "/". So first token is always empty.
middle = web.listget(tokens, 1, "")
suffix = web.listget(tokens, 2, "")
if suffix:
suffix = "/" + suffix
return type, property, default_title, prefix, middle, suffix
return None, None, None, None, None, None
type, property, default_title, prefix, middle, suffix = match(path)
if type is None:
path = web.safeunicode(path)
return (path, path)
if encoding is not None \
or path.endswith(".json") or path.endswith(".yml") or path.endswith(".rdf"):
key, ext = os.path.splitext(path)
thing = _get_object(site, key)
if thing:
path = thing.key + ext
path = web.safeunicode(path)
return (path, path)
thing = _get_object(site, prefix)
# get_object may handle redirections.
if thing:
prefix = thing.key
if thing and thing.type.key == type:
title = thing.get(property) or default_title
middle = '/' + h.urlsafe(title.strip())
else:
middle = ""
prefix = web.safeunicode(prefix)
middle = web.safeunicode(middle)
suffix = web.safeunicode(suffix)
return (prefix + suffix, prefix + middle + suffix)
开发者ID:cpeel,项目名称:openlibrary,代码行数:56,代码来源:readableurls.py
示例3: cat
def cat(*args):
buf = ""
for i in args:
full_path = web.safeunicode(i)
if os.path.isfile(full_path):
f = file(full_path)
buf = "%s%s" % (buf, f.read().strip())
f.close()
return web.safeunicode(buf)
开发者ID:milkmeat,项目名称:zbox_wiki,代码行数:10,代码来源:utils.py
示例4: __call__
def __call__(self, handler):
real_path, readable_path = self.get_readable_path(web.ctx.path, encoding=web.ctx.encoding)
#@@ web.ctx.path is either quoted or unquoted depends on whether the application is running
#@@ using builtin-server or lighttpd. Thats probably a bug in web.py.
#@@ take care of that case here till that is fixed.
# @@ Also, the redirection must be done only for GET requests.
if readable_path != web.ctx.path and readable_path != urllib.quote(web.utf8(web.ctx.path)) and web.ctx.method == "GET":
raise web.seeother(web.safeunicode(readable_path) + web.safeunicode(web.ctx.query))
web.ctx.readable_path = readable_path
web.ctx.path = real_path
web.ctx.fullpath = web.ctx.path + web.ctx.query
return handler()
开发者ID:sribanta,项目名称:openlibrary,代码行数:14,代码来源:processors.py
示例5: cat
def cat(*args):
buf = ""
for i in args:
full_path = web.safeunicode(i)
if os.path.isfile(full_path):
f = file(full_path)
buf += f.read().strip()
f.close()
try:
buf = web.safeunicode(buf)
except UnicodeDecodeError:
msg = "expected %s file(s) in unicode, got un-know encoding" % ", ".join(args)
sys.stderr.write("\n" + msg + "\n")
buf = u""
return buf
开发者ID:qqhhww,项目名称:zbox_wiki,代码行数:17,代码来源:utils.py
示例6: row
def row(r):
if isinstance(r, basestring):
level = 0
label = ""
title = web.safeunicode(r)
pagenum = ""
elif 'value' in r:
level = 0
label = ""
title = web.safeunicode(r['value'])
pagenum = ""
else:
level = safeint(r.get('level', '0'), 0)
label = r.get('label', '')
title = r.get('title', '')
pagenum = r.get('pagenum', '')
r = web.storage(level=level, label=label, title=title, pagenum=pagenum)
return r
开发者ID:balinjdl,项目名称:openlibrary,代码行数:19,代码来源:merge_authors.py
示例7: row
def row(r):
if isinstance(r, basestring):
level = 0
label = ""
title = web.safeunicode(r)
pagenum = ""
elif "value" in r:
level = 0
label = ""
title = web.safeunicode(r["value"])
pagenum = ""
elif isinstance(r, dict):
level = safeint(r.get("level", "0"), 0)
label = r.get("label", "")
title = r.get("title", "")
pagenum = r.get("pagenum", "")
else:
return {}
return dict(level=level, label=label, title=title, pagenum=pagenum)
开发者ID:nibrahim,项目名称:openlibrary,代码行数:20,代码来源:ol_infobase.py
示例8: row
def row(r):
if isinstance(r, six.string_types):
level = 0
label = ""
title = web.safeunicode(r)
pagenum = ""
elif 'value' in r:
level = 0
label = ""
title = web.safeunicode(r['value'])
pagenum = ""
elif isinstance(r, dict):
level = safeint(r.get('level', '0'), 0)
label = r.get('label', '')
title = r.get('title', '')
pagenum = r.get('pagenum', '')
else:
return {}
return dict(level=level, label=label, title=title, pagenum=pagenum)
开发者ID:hornc,项目名称:openlibrary-1,代码行数:20,代码来源:ol_infobase.py
示例9: _format
def _format(self, d):
if isinstance(d, dict):
return dict((k, self._format(v)) for k, v in d.iteritems())
elif isinstance(d, list):
return [self._format(v) for v in d]
elif isinstance(d, common.Text):
return {'type': '/type/text', 'value': web.safeunicode(d)}
elif isinstance(d, Thing):
return d._dictrepr()
elif isinstance(d, datetime.datetime):
return {'type': '/type/datetime', 'value': d.isoformat()}
else:
return d
开发者ID:reklaklislaw,项目名称:infogami,代码行数:13,代码来源:client.py
示例10: __call__
def __call__(self, handler):
# temp hack to handle languages and users during upstream-to-www migration
if web.ctx.path.startswith("/l/"):
raise web.seeother("/languages/" + web.ctx.path[len("/l/"):])
if web.ctx.path.startswith("/user/"):
if not web.ctx.site.get(web.ctx.path):
raise web.seeother("/people/" + web.ctx.path[len("/user/"):])
real_path, readable_path = self.get_readable_path(web.ctx.path, encoding=web.ctx.encoding)
#@@ web.ctx.path is either quoted or unquoted depends on whether the application is running
#@@ using builtin-server or lighttpd. Thats probably a bug in web.py.
#@@ take care of that case here till that is fixed.
# @@ Also, the redirection must be done only for GET requests.
if readable_path != web.ctx.path and readable_path != urllib.quote(web.utf8(web.ctx.path)) and web.ctx.method == "GET":
raise web.redirect(web.safeunicode(readable_path) + web.safeunicode(web.ctx.query))
web.ctx.readable_path = readable_path
web.ctx.path = real_path
web.ctx.fullpath = web.ctx.path + web.ctx.query
return handler()
开发者ID:artmedlar,项目名称:openlibrary,代码行数:22,代码来源:processors.py
示例11: process_data
def process_data(self, d, type, old_data=None):
for k, v in d.items():
if v is None or v == [] or web.safeunicode(v).strip() == '':
del d[k]
else:
if old_data and old_data.get(k) == v:
continue
p = self.get_property(type, k)
if p:
d[k] = self.process_value(v, p)
else:
d[k] = v
if type:
d['type'] = common.Reference(type.key)
return d
开发者ID:termim,项目名称:infogami,代码行数:16,代码来源:writequery.py
示例12: datify
def datify(dtime=None, format=u"%x %H:%M", convert_to_utc=False, lang=None):
if dtime is None:
return ""
if not type(dtime) in (datetime.datetime, datetime.date):
dtime = parser.parse(dtime)
if convert_to_utc:
dtime = dtime.replace(tzinfo=TZ_LOCAL).astimezone(tz=TZ_UTC)
return dtime.strftime(format)
elif (lang or web.ctx.lang) == "ru":
return pytils.dt.ru_strftime(
web.safeunicode(format),
inflected=True,
date=dtime,
)
else:
return dtime.strftime(format)
开发者ID:w0rm,项目名称:pre-stonegarden-dev,代码行数:16,代码来源:template.py
示例13: run
def run(cmd):
args = shlex.split(cmd)
try:
p_obj = subprocess.Popen(args, stdout = subprocess.PIPE, shell = True)
# resp = p_obj.stdout.read().strip("\n")
resp = p_obj.stdout.read()
except TypeError:
resp = None
if not resp:
# resp = os.popen(cmd).read().strip().split('\n')
resp = os.popen(cmd).read().strip()
resp = web.rstrips(resp, "\n")
resp = web.safeunicode(resp)
return resp
开发者ID:milkmeat,项目名称:zbox_wiki,代码行数:18,代码来源:utils.py
示例14: __init__
def __init__(self):
super(Foo, self).__init__()
x, y, w, h = 100, 100, 900, 600
self.setGeometry(x, y, w, h)
self.source = QtGui.QTextEdit(self)
# self.preview = QtWebKit.QWebView(self)
self.preview = QtGui.QTextEdit(self)
self.preview.setReadOnly(True)
self.preview.setFrameShape(QtGui.QFrame.NoFrame)
qd = QtGui.QTextDocument()
qd.setDefaultStyleSheet(DEFAULT_STYLE)
self.preview.setDocument(qd)
self.splitter = QtGui.QSplitter(QtCore.Qt.Horizontal)
self.splitter.addWidget(self.source)
self.splitter.addWidget(self.preview)
# widget = self.splitter.widget(0)
# policy = widget.sizePolicy()
# policy.setHorizontalStretch(1)
# policy.setVerticalStretch(1)
# widget.setSizePolicy(policy)
self.hbox = QtGui.QHBoxLayout(self)
self.hbox.setContentsMargins(0, 0, 0, 0)
self.hbox.setSpacing(0)
self.hbox.addWidget(self.splitter)
self.setLayout(self.hbox)
self.font = QtGui.QFont("Monaco", 12)
self.setFont(self.font)
self.source.textChanged.connect(self.source_text_changed)
self.source.setText(web.safeunicode(buf))
开发者ID:Chiheb-Nexus,项目名称:Qt-Python-Binding-Examples,代码行数:43,代码来源:markdown_editor.py
示例15: convertSQLQueryRecords
def convertSQLQueryRecords(qr=[]):
"""Convert SQL record value to avoid incorrect unicode handle in Jinja2.
>>> db = web.DB(None, {})
>>> qr = db.query('SELECT * FROM msgs')
>>> convertSQLQueryRecords(qr)
>>> qr = db.select('msgs')
>>> convertSQLQueryRecords(qr)
"""
rcds = []
for record in qr:
for k in record:
try:
record[k] = web.safeunicode(record.get(k))
except UnicodeDecodeError:
record[k] = '<<< DECODE FAILED >>>'
rcds += [record]
return rcds
开发者ID:shyaken,项目名称:cp.eaemcb,代码行数:19,代码来源:iredutils.py
示例16: __init__
def __init__(self):
super(Demo, self).__init__()
x, y, w, h = 500, 200, 300, 400
self.setGeometry(x, y, w, h)
# support basic rich text
text1 = "Hello, <a href='http://www.pyside.org/'>PySide</a>"
label1 = QtGui.QLabel(text1, self)
x, y = 20, 20
label1.move(x, y)
label1.linkActivated.connect(self._label1_linkActivated)
label1.setFrameStyle(QtGui.QFrame.Panel | QtGui.QFrame.Sunken)
label2 = QtGui.QLabel(self)
x, y = 20, 55
label2.move(x, y)
text2 = u'\u4e2d\u6587'
label2.setText(text2)
label2.setFrameStyle(QtGui.QFrame.Panel)
print label1.text(), type(label1.text()), label1.text() == text1
print label2.text(), type(label2.text()), label2.text() == web.safeunicode(text2)
开发者ID:Chiheb-Nexus,项目名称:Qt-Python-Binding-Examples,代码行数:24,代码来源:label.py
示例17: get_multi
def get_multi(self, keys):
keys = [web.safestr(k) for k in keys]
d = self._client.get_multi(keys)
return dict((web.safeunicode(k), self.decompress(v)) for k, v in d.items())
开发者ID:hornc,项目名称:openlibrary-1,代码行数:4,代码来源:olmemcache.py
示例18: format
def format(text):
text = web.safeunicode(text)
md = markdown.Markdown(source=text)
md.postprocessors.append(wikilinks())
return web.safestr(md.convert())
开发者ID:anandology,项目名称:webpy.org2,代码行数:6,代码来源:build.py
示例19: get_readable_path
def get_readable_path(self, path, get_object=None, encoding=None):
""" Returns (real_url, readable_url) for the given url.
>>> fakes = {}
>>> fakes['/b/OL1M'] = web.storage(title='fake', name='fake', type=web.storage(key='/type/edition'))
>>> fakes['/a/OL1A'] = web.storage(title='fake', name='fake', type=web.storage(key='/type/author'))
>>> def fake_get_object(key): return fakes[key]
...
>>> get_readable_path = ReadableUrlProcessor().get_readable_path
>>> get_readable_path('/b/OL1M', get_object=fake_get_object)
(u'/b/OL1M', u'/b/OL1M/fake')
>>> get_readable_path('/b/OL1M/foo', get_object=fake_get_object)
(u'/b/OL1M', u'/b/OL1M/fake')
>>> get_readable_path('/b/OL1M/fake', get_object=fake_get_object)
(u'/b/OL1M', u'/b/OL1M/fake')
>>> get_readable_path('/b/OL1M/foo/cover', get_object=fake_get_object)
(u'/b/OL1M/cover', u'/b/OL1M/fake/cover')
>>> get_readable_path('/a/OL1A/foo/cover', get_object=fake_get_object)
(u'/a/OL1A/cover', u'/a/OL1A/fake/cover')
When requested for .json nothing should be changed.
>>> get_readable_path('/b/OL1M.json')
(u'/b/OL1M.json', u'/b/OL1M.json')
For deleted pages, the readable_path must be same as the real path.
>>> fakes['/a/OL2A'] = web.storage(title='fake', name='fake', type=web.storage(key='/type/delete'))
>>> get_readable_path('/a/OL2A', get_object=fake_get_object)
(u'/a/OL2A', u'/a/OL2A')
>>> get_readable_path('/a/OL2A/foo', get_object=fake_get_object)
(u'/a/OL2A', u'/a/OL2A')
"""
def match(path):
for pat, type, property, default_title in self.patterns:
if web.re_compile('^' + pat).match(path):
return type, property, default_title
return None, None, None
type, property, default_title = match(path)
if type is None:
path = web.safeunicode(path)
return (path, path)
if encoding is not None \
or path.endswith(".json") or path.endswith(".yml") or path.endswith(".rdf"):
key, ext = os.path.splitext(path)
get_object = get_object or self.get_object
thing = get_object(key)
if thing:
path = thing.key + ext
path = web.safeunicode(path)
return (path, path)
prefix, middle, suffix = self._split(path)
get_object = get_object or self.get_object
thing = get_object(prefix)
# get_object may handle redirections.
if thing:
prefix = thing.key
if thing and thing.type.key == type:
title = thing.get(property) or default_title
middle = '/' + _safepath(title.strip())
else:
middle = ""
prefix = web.safeunicode(prefix)
middle = web.safeunicode(middle)
suffix = web.safeunicode(suffix)
return (prefix + suffix, prefix + middle + suffix)
开发者ID:artmedlar,项目名称:openlibrary,代码行数:77,代码来源:processors.py
示例20: _format
def _format(text, safe_mode=False):
text = web.safeunicode(text)
md = get_markdown(text, safe_mode=safe_mode)
html = web.safestr(md.convert())
return html, md.macros
开发者ID:internetarchive,项目名称:infogami,代码行数:5,代码来源:view.py
注:本文中的web.safeunicode函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论