本文整理汇总了Python中utils.escape函数的典型用法代码示例。如果您正苦于以下问题:Python escape函数的具体用法?Python escape怎么用?Python escape使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了escape函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: po2csv
def po2csv(po):
"""Converts a polib.POFile object to a csv string (contained in an instance
of StringIO)
"""
csv_file = StringIO()
csv_writer = csv.writer(csv_file)
for header_row in csv_header_rows:
csv_writer.writerow(header_row)
for entry in po:
msgstrs = force_plurals(entry)
fuzzy = bool2str('fuzzy' in entry.flags, empty_for_false=True)
obsolete = bool2str(entry.obsolete, empty_for_false=True)
row = [
escape(entry.msgid),
escape(entry.msgid_plural),
entry.msgctxt,
msgstrs,
fuzzy,
entry.comment,
obsolete
]
csv_writer.writerow(row)
return csv_file
开发者ID:sleepyjames,项目名称:ppb,代码行数:28,代码来源:po2csv.py
示例2: force_plurals
def force_plurals(entry):
"""A po file's plural handling is slightly weird. If there are no plurals
for a translation:
msgid "hello"
msgstr "hola"
If there are plurals however:
msgid "%(count)s house"
msgid_plural "%(count)s houses"
msgstr[0] "%(count)s casa"
msgstr[1] "%(count)s casas"
So to keep things consistent, we force non-plural translations into the
plural form for consistency, and then reading them back, we still have
enough information to convert them back into singular translations if
that's what they were meant to be.
"""
plurals = entry.msgstr_plural
if not plurals:
plurals = {u'0': escape(entry.msgstr)}
sorted_plurals = sorted(plurals.items(), key=lambda t: t[0])
return PLURAL_SEPARATOR.join(escape(v) for k, v in sorted_plurals)
开发者ID:sleepyjames,项目名称:ppb,代码行数:25,代码来源:po2csv.py
示例3: writeFavourites
def writeFavourites(file, faves):
f = sfile.file(file, 'w')
f.write('<favourites>')
for fave in faves:
try:
name = utils.escape(fave[0])
thumb = utils.escape(fave[1])
cmd = utils.escape(fave[2])
thumb = convertToHome(thumb)
name = 'name="%s" ' % name
thumb = 'thumb="%s">' % thumb
f.write('\n\t<favourite ')
f.write(name)
f.write(thumb)
f.write(cmd)
f.write('</favourite>')
except:
pass
f.write('\n</favourites>')
f.close()
import xbmcgui
try: count = int(xbmcgui.Window(10000).getProperty('Super_Favourites_Count'))
except: count = 0
xbmcgui.Window(10000).setProperty('Super_Favourites_Count', str(count+1))
开发者ID:e-motiv,项目名称:spoyser-repo,代码行数:31,代码来源:favourite.py
示例4: harvest
def harvest(text, harvesters=DEFAULT_HARVESTERS):
instances = [load_class(namespace) for namespace in harvesters]
display_text = ''
display_html = ''
entities = []
current_text = text
for instance in instances:
e = instance.harvest(current_text)
current_position = 0
for entity in e:
entities.append(entity)
current_position = entity.start_index
l = len(entity.original_text)
replacement = repeat_to_length(' ', l)
current_text = current_text[:current_position] + \
replacement + current_text[current_position + l:]
current_index = 0
for entity in entities:
display_html = display_html + escape(text[current_index:entity.start_index]) + entity.display_html
display_text = display_text + escape(text[current_index:entity.start_index]) + entity.display_text
current_index = entity.end_index
display_text = display_text + escape(text[current_index:])
display_html = display_html + escape(text[current_index:])
return {
'display_text': display_text,
'display_html': display_html,
}
开发者ID:jpennell,项目名称:harvest,代码行数:35,代码来源:harvest.py
示例5: set_label_text
def set_label_text(self, info, label_text, label_extra=None):
label_text = label_text.replace('\n', '').replace('\r', '')
if label_extra:
self.info_label.set_markup(info % (escape(label_text),
escape(label_extra)))
else:
self.info_label.set_markup(info % escape(label_text))
开发者ID:BonsaiDen,项目名称:Atarashii,代码行数:9,代码来源:gui_helpers.py
示例6: build_html_params
def build_html_params(**params):
params_list = list()
for (name, value) in params.items():
if name[0] == u'_':
name = name[1:]
params_list.append(u' {0}="{1}"'.format(
escape(name),
escape(value),
))
return u''.join(params_list)
开发者ID:balor,项目名称:hop,代码行数:10,代码来源:builder.py
示例7: build_signature_base_string
def build_signature_base_string(self, oauth_request, consumer, token):
sig = (
escape(oauth_request.get_normalized_http_method()),
escape(oauth_request.get_normalized_http_url()),
escape(oauth_request.get_normalized_parameters()),
)
key = '%s&' % escape(consumer.secret)
if token:
key += escape(token.secret)
raw = '&'.join(sig)
return key, raw
开发者ID:carlitux,项目名称:Python-OAuth-Client,代码行数:12,代码来源:signature.py
示例8: get_normalized_parameters
def get_normalized_parameters(self):
"""Return a string that contains the parameters that must be signed."""
params = self.parameters
try:
# Exclude the signature if it exists.
del params["oauth_signature"]
except:
pass
# Escape key values before sorting.
key_values = [(escape(_utf8_str(k)), escape(_utf8_str(v))) for k, v in params.items()]
# Sort lexicographically, first after key, then after value.
key_values.sort()
# Combine key value pairs into a string.
return "&".join(["%s=%s" % (k, v) for k, v in key_values])
开发者ID:carlitux,项目名称:Python-OAuth-Client,代码行数:14,代码来源:request.py
示例9: json_data
def json_data(self):
return dict(
id = self.id,
content = escape(self.content),
date_created = self.date_created,
user = self.user.json_data()
)
开发者ID:laoshanlung,项目名称:flask-demo,代码行数:7,代码来源:answer.py
示例10: get_content
def get_content(self):
"""Returns the content of the message"""
text = self.parsed_obj.get_payload()
output = ''
if isinstance(text, types.ListType) and self.parsed_obj.is_multipart():
for i in text:
if i.get_filename():
logging.error('Attachment found!!!')
output += "\nSorry but the attachment has been stripped from this message!"
continue
if (i.get_content_type() == "text/plain" or i.get_content_type() == "text/html"):
output+=(i.get_payload()) + '\n\n'
#logging.debug("Appending %s to output" % i.get_payload())
else:
output = text
#logging.error("get_content(): Output before wrap is %s" % output)
output = escape(output)
output = nl2br(output)
output1 = textwrap.wrap(output, 65)
output = ''
for i in output1:
output += i + '<br />'
#logging.error("get_content returning %s" % output)
return output
开发者ID:BinaryShinigami,项目名称:Lagune-Mail,代码行数:31,代码来源:models.py
示例11: _parse_urls
def _parse_urls(self, match):
'''Parse URLs.'''
mat = match.group(0)
# Fix a bug in the regex concerning www...com and www.-foo.com domains
# TODO fix this in the regex instead of working around it here
domain = match.group(5)
if domain[0] in '.-':
return mat
# Only allow IANA one letter domains that are actually registered
if len(domain) == 5 \
and domain[-4:].lower() in ('.com', '.org', '.net') \
and not domain.lower() in IANA_ONE_LETTER_DOMAINS:
return mat
# Check for urls without http(s)
pos = mat.find('http')
if pos != -1:
pre, url = mat[:pos], mat[pos:]
full_url = url
# Find the www and force http://
else:
pos = mat.lower().find('www')
pre, url = mat[:pos], mat[pos:]
full_url = 'http://%s' % url
self._urls.append(url)
if self._html:
return '%s%s' % (pre, self.format_url(full_url,
self._shorten_url(escape(url))))
开发者ID:BonsaiDen,项目名称:Atarashii,代码行数:35,代码来源:ttp.py
示例12: search_foods
def search_foods(query):
"""
Palauttaa hakuehtoja vastaavat elintarvikkeet + id:t.
Paluuarvona lista, jossa arvot tyyppiä [id, nimi].
"""
query = re.sub("\s+", " ", query).strip()
stored = db.get_search(query)
if stored:
return stored
url = URL_ROOT + "/foodsearch.php?name=" + escape(query)
print "url=", url
root = html.parse(url)
foods = []
rows = root.xpath("/html/body/div/table[2]/tr[1]/td[2]/ul/li/a")
for row in rows:
try:
fid = row.attrib["href"].split("=")[1].split("&")[0]
except IndexError:
logging.error("Scraping food ID failed: " + query)
continue
foods.append((fid, row.text.strip()))
db.add_search({"query": query, "results": foods})
return foods
开发者ID:epiphone,项目名称:ruokapaivakirja,代码行数:29,代码来源:fineli_scraper.py
示例13: to_header
def to_header(self, realm=""):
"""Serialize as a header for an HTTPAuth request."""
auth_header = 'OAuth realm="%s"' % realm
# Add the oauth parameters.
if self.parameters:
for k, v in self.parameters.iteritems():
if k[:6] == "oauth_":
auth_header += ', %s="%s"' % (k, escape(str(v)))
return {"Authorization": auth_header}
开发者ID:carlitux,项目名称:Python-OAuth-Client,代码行数:9,代码来源:request.py
示例14: to_tsv
def to_tsv(self):
'''
Returns the instance's column values as a tab-separated line. A newline is not included.
'''
parts = []
for name, field in self._fields:
value = field.get_db_prep_value(field.to_python(getattr(self, name)))
parts.append(escape(value, quote=False))
return '\t'.join(parts)
开发者ID:melnikov-d,项目名称:infi.clickhouse_orm,代码行数:9,代码来源:models.py
示例15: out
def out(self):
res = self.tree.to_string()
res = ut.escape(res, ut.TEX_ESCAPE)
res = " ".join(res.split())
res = res.replace(" .", ".")
res = res.replace(" ,", ",")
res = res.replace(" ;", ";")
res = res.replace(" :", ":")
res = unicode("{{{0}}}", "utf8").format(res)
return res
开发者ID:oberix,项目名称:star,代码行数:10,代码来源:des.py
示例16: render_testapp
def render_testapp(req):
try:
import pkg_resources
except ImportError:
eggs = ()
else:
eggs = list(pkg_resources.working_set)
eggs.sort(lambda a, b: cmp(a.project_name.lower(),
b.project_name.lower()))
python_eggs = []
for egg in eggs:
try:
version = egg.version
except (ValueError, AttributeError):
version = 'unknown'
python_eggs.append('<li>%s <small>[%s]</small>' % (
escape(egg.project_name),
escape(version)
))
wsgi_env = []
sorted_environ = req.environ.items()
sorted_environ.sort(key=lambda x: repr(x[0]).lower())
for key, value in sorted_environ:
wsgi_env.append('<tr><th>%s<td><code>%s</code>' % (
escape(str(key)),
' '.join(wrap(escape(repr(value))))
))
sys_path = []
for item, virtual, expanded in iter_sys_path():
class_ = []
if virtual:
class_.append('virtual')
if expanded:
class_.append('exp')
sys_path.append('<li%s>%s' % (
class_ and ' class="%s"' % ' '.join(class_) or '',
escape(item)
))
return TEMPLATE % {
'python_version': '<br>'.join(escape(sys.version).splitlines()),
'platform': escape(sys.platform),
'os': escape(os.name),
'api_version': sys.api_version,
'byteorder': sys.byteorder,
'werkzeug_version': werkzeug.__version__,
'python_eggs': '\n'.join(python_eggs),
'wsgi_env': '\n'.join(wsgi_env),
'sys_path': '\n'.join(sys_path)
}
开发者ID:Mirabis,项目名称:usntssearch,代码行数:52,代码来源:testapp.py
示例17: post_new_comment
def post_new_comment():
postid = request.forms.get('postid')
name = request.forms.get('name').decode('utf-8')
email = request.forms.get('email').decode('utf-8')
url = request.forms.get('url').decode('utf-8')
content = request.forms.get('content').decode('utf-8')
parent = request.forms.get('parentid')
check = request.forms.get('check')
if check != "123456":
post = Post.get(id=postid)
redirect("/%s" % post.slug)
post = Post.get(id=postid)
post.comm_count = post.comm_count + 1
comment = Comment.create(post=post, author=escape(name),
email=escape(email), url=escape(url),
content=escape(content), parent=parent,
published=datetime.datetime.now())
post.save()
redirect("/%s#comment-%s" % (post.slug, comment.id))
开发者ID:iTriumph,项目名称:MiniAkio,代码行数:20,代码来源:blog.py
示例18: get_body
def get_body(self, environ):
"""Get the HTML body."""
return (
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">\n'
'<title>%(code)s %(name)s</title>\n'
'<h1>%(name)s</h1>\n'
'%(description)s\n'
) % {
'code': self.code,
'name': escape(self.name),
'description': self.get_description(environ)
}
开发者ID:Mirabis,项目名称:usntssearch,代码行数:12,代码来源:exceptions.py
示例19: get_body
def get_body(self):
return (
u'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">\n'
u'<html>\n<title>%(code)s %(name)s</title>\n<body>\n'
u'<h1>%(name)s</h1>\n'
u'%(description)s\n'
u'</body></html>'
) % {
'code': self.code,
'name': escape(self.name),
'description': self.get_content()
}
开发者ID:wenjunxiao,项目名称:pblog,代码行数:12,代码来源:http.py
示例20: writeFavourites
def writeFavourites(file, faves):
kodiFile = os.path.join("special://profile", utils.FILENAME)
isKodi = xbmc.translatePath(file) == xbmc.translatePath(kodiFile)
f = sfile.file(file, "w")
f.write("<favourites>")
for fave in faves:
try:
name = utils.escape(fave[0])
thumb = utils.escape(fave[1])
cmd = utils.escape(fave[2])
if isKodi and cmd.lower().startswith("playmedia"):
cmd = removeSFOptions(cmd)
thumb = utils.convertToHome(thumb)
name = 'name="%s" ' % name
thumb = 'thumb="%s">' % thumb
f.write("\n\t<favourite ")
f.write(name)
f.write(thumb)
f.write(cmd)
f.write("</favourite>")
except:
pass
f.write("\n</favourites>")
f.close()
import xbmcgui
try:
count = int(xbmcgui.Window(10000).getProperty("Super_Favourites_Count"))
except:
count = 0
xbmcgui.Window(10000).setProperty("Super_Favourites_Count", str(count + 1))
开发者ID:NEOhidra,项目名称:spoyser-repo,代码行数:39,代码来源:favourite.py
注:本文中的utils.escape函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论