本文整理汇总了Python中flask.Markup.encode方法的典型用法代码示例。如果您正苦于以下问题:Python Markup.encode方法的具体用法?Python Markup.encode怎么用?Python Markup.encode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask.Markup
的用法示例。
在下文中一共展示了Markup.encode方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: slugify
# 需要导入模块: from flask import Markup [as 别名]
# 或者: from flask.Markup import encode [as 别名]
def slugify(value, substitutions=()):
'''
Normalizes string, converts to lowercase, removes non-alpha characters,
and converts spaces to hyphens.
Took from Django sources.
'''
# TODO Maybe steal again from current Django 1.5dev
value = Markup(value).striptags()
# value must be unicode per se
import unicodedata
from unidecode import unidecode
# unidecode returns str in Py2 and 3, so in Py2 we have to make
# it unicode again
value = unidecode(value)
if isinstance(value, six.binary_type):
value = value.decode('ascii')
# still unicode
value = unicodedata.normalize('NFKD', value).lower()
for src, dst in substitutions:
value = value.replace(src.lower(), dst.lower())
value = re.sub('[^\w\s-]', '', value).strip()
value = re.sub('[-\s]+', '-', value)
# we want only ASCII chars
value = value.encode('ascii', 'ignore')
# but Pelican should generally use only unicode
return value.decode('ascii')
示例2: main
# 需要导入模块: from flask import Markup [as 别名]
# 或者: from flask.Markup import encode [as 别名]
def main(args):
if len(args) == 0:
print "You need to enter a search term."
return
s = ""
for arg in args:
s+=arg
s = s.replace(" ", "+")
s = s.replace("'", r"")
response = urllib2.urlopen("https://twitter.com/search?q=" + s + "&src=typd")
page_source = response.read()
soup = BeautifulSoup(page_source)
links = soup.find_all("a", "details with-icn js-details")
username = soup.find_all("span", "username js-action-profile-name")
tweets = soup.find_all("p", "js-tweet-text")
if len(tweets) == 0:
print "No results."
return
tweet = Markup(tweets[0]).striptags()
username = Markup(username[0]).striptags()
link = links[0].get('href')
link = "https://twitter.com" + link
print username.encode("ascii", "ignore") + ": " + tweet.encode("ascii", "ignore") + " (" + link.encode("ascii", "ignore") + ")";
示例3: display_content
# 需要导入模块: from flask import Markup [as 别名]
# 或者: from flask.Markup import encode [as 别名]
def display_content(filter,sort,start,requrl):
content = "<table border='1px'><tr><th>Date</th><th>Type</th><th>Log</th><th>StackTrace</th></tr>";
for log in list(collection.find(filter).skip(int(start)).limit(MAX_ROWS).sort('Date', -1 if sort == Desc else 1)):
content += "<tr class='%s'><td>%s</td><td>%s</td><td>%s</td><td>%s</td>" % ( log['Type'],log['Date'], log['Type'],Markup.escape(log['log']), "-" if not log.has_key('stacktrace') else "<input type='button' value='stacktrace' onclick=\"alert('"+Markup.encode(' '.join(log['stacktrace'].strip().split('\n')))+"');\" />");
content += "</table>";
return html(content,sort,start,requrl);