本文整理汇总了Python中web.htmlquote函数的典型用法代码示例。如果您正苦于以下问题:Python htmlquote函数的具体用法?Python htmlquote怎么用?Python htmlquote使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了htmlquote函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: field_table
def field_table(self, input, rec_amazon, rec_marc):
yield "<table>"
yield """<tr>
<th>Field</th>
<th>match</th>
<th>score</th>
<th>Amazon</th>
<th>MARC</th>
</tr>"""
total = 0
for field, match, score in input:
yield "<tr>"
yield "<td>%s</td>" % field
yield "<td>%s</td>" % web.htmlquote(match)
yield "<td>%s</td>" % score
yield "<td>%s</td>" % as_html(rec_amazon.get(field, None))
if field == "authors":
authors = rec_marc.get(field, [])
yield "<td>%s</td>" % list_to_html(web.htmlquote(a["name"]) for a in authors)
else:
yield "<td>%s</td>" % as_html(rec_marc.get(field, None))
yield "</tr>"
total += score
yield "</table>"
yield "threshold %d, total: %d, " % (threshold, total)
yield (("match" if total >= threshold else "no match") + "<br>")
示例2: GET
def GET(self):
input = web.input()
birth = input.get('birth', '').strip()
death = input.get('death', '').strip()
order = input.get('order', '').strip()
if order not in ('', 'name', 'birth', 'death'):
order = ''
html = '''
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Merge author</title>
<style>
body { font-family: arial,helvetica,san-serif; }
th { text-align: left; }
</style>
</head>
<body>
'''
html += '<form method="get">\n'
html += 'Birth: <input type="text" size="7" name="birth" value="%s">\n' % web.htmlquote(birth)
html += 'Death: <input type="text" size="7" name="death" value="%s">\n' % web.htmlquote(death)
html += '<input type="submit" value="Search">\n</form>'
if birth or death:
url = 'http://openlibrary.org/query.json?type=/type/author&birth_date=%s&death_date=%s&name=' % (web.urlquote(birth), web.urlquote(death))
data = get_all(url)
html += result_table(data, birth, death, order)
return html + '</body>\n</html>'
示例3: field_table
def field_table(self, input, rec_amazon, rec_marc):
yield '<table>'
yield '''<tr>
<th>Field</th>
<th>match</th>
<th>score</th>
<th>Amazon</th>
<th>MARC</th>
</tr>'''
total = 0
for field, match, score in input:
yield '<tr>'
yield '<td>%s</td>' % field
yield '<td>%s</td>' % web.htmlquote(match)
yield '<td>%s</td>' % score
yield '<td>%s</td>' % as_html(rec_amazon.get(field, None))
# if field == 'number_of_pages':
# yield '<td>%s</td>' % (web.htmlquote(rec_marc['pagination']) if 'pagination' in rec_marc else '<i>pagination missing</i>')
if field == 'authors':
authors = rec_marc.get(field, [])
yield '<td>%s</td>' % list_to_html(web.htmlquote(a['name']) for a in authors)
else:
yield '<td>%s</td>' % as_html(rec_marc.get(field, None))
yield '</tr>'
total += score
yield '</table>'
yield 'threshold %d, total: %d, ' % (threshold, total)
yield (('match' if total >= threshold else 'no match') + '<br>')
示例4: GET
def GET(self):
web.header('Content-Type','text/html; charset=utf-8', unique=True)
input = web.input()
title = 'Tidy author'
if 'author' in input and input.author:
author = input.author
name = withKey(author)['name']
q_name = web.htmlquote(name)
title = q_name + ' - Tidy author'
else:
author = None
ret = "<html>\n<head>\n<title>%s</title>" % title
ret += '''
<style>
th { text-align: left }
td { padding: 5px; background: #eee }
</style>'''
ret += '</head><body><a name="top">'
ret += '<form name="main" method="get"><table><tr><td align="right">Author</td><td>'
if author:
ret += '<input type="text" name="author" value="%s">' % web.htmlquote(author)
else:
ret += '<input type="text" name="author">'
ret += '</td>'
ret += '<td><input type="submit" value="find"></td></tr>'
ret += '</table>'
ret += '</form>'
if author:
ret += 'Author: <a href="http://openlibrary.org%s">%s</a><br>' % (author, name)
ret += search(author, name)
ret += "</body></html>"
return ret
示例5: GET
def GET(self):
web.header('Content-Type','text/html; charset=utf-8', unique=True)
input = web.input()
lccn = None
oclc = None
isbn = None
title = 'MARC lookup'
if 'isbn' in input and input.isbn:
isbn = input.isbn
if isbn == 'random':
isbn = random_isbn()
title = 'MARC lookup: isbn=' + isbn
if 'lccn' in input and input.lccn:
lccn = input.lccn
title = 'MARC lookup: lccn=' + lccn
if 'oclc' in input and input.oclc:
oclc = input.oclc
title = 'MARC lookup: oclc=' + oclc
ret = "<html>\n<head>\n<title>%s</title>" % title
ret += '''
<style>
th { text-align: left }
td { padding: 5px; background: #eee }
</style>'''
ret += '</head><body><a name="top">'
ret += '<form name="main" method="get"><table><tr><td align="right">ISBN</td><td>'
if isbn:
ret += '<input type="text" name="isbn" value="%s">' % web.htmlquote(isbn)
else:
ret += '<input type="text" name="isbn">'
ret += ' or <a href="/random">random</a><br>'
ret += '</td></tr><tr><td align="right">LCCN</td><td>'
if lccn:
ret += '<input type="text" name="lccn" value="%s">' % web.htmlquote(lccn)
else:
ret += '<input type="text" name="lccn">'
ret += '</td></tr><tr><td align="right">OCLC</td><td>'
if oclc:
ret += '<input type="text" name="oclc" value="%s">' % web.htmlquote(oclc)
else:
ret += '<input type="text" name="oclc">'
ret += '</td></tr>'
ret += '<tr><td></td><td><input type="submit" value="find"></td></tr>'
ret += '</table>'
ret += '</form>'
if isbn:
ret += search('isbn', isbn)
elif lccn:
search('lccn', lccn)
elif oclc:
search('oclc', oclc)
ret += "</body></html>"
return ret
示例6: GET
def GET(self):
web.header("Content-Type", "text/html; charset=utf-8", unique=True)
input = web.input()
lccn = None
oclc = None
isbn = None
title = "MARC lookup"
if "isbn" in input and input.isbn:
isbn = input.isbn
if isbn == "random":
isbn = random_isbn()
title = "MARC lookup: isbn=" + isbn
if "lccn" in input and input.lccn:
lccn = input.lccn
title = "MARC lookup: lccn=" + lccn
if "oclc" in input and input.oclc:
oclc = input.oclc
title = "MARC lookup: oclc=" + oclc
print "<html>\n<head>\n<title>%s</title>" % title
print """
<style>
th { text-align: left }
td { padding: 5px; background: #eee }
</style>"""
print '</head><body><a name="top">'
print '<form name="main" method="get"><table><tr><td align="right">ISBN</td><td>'
if isbn:
print '<input type="text" name="isbn" value="%s">' % web.htmlquote(isbn)
else:
print '<input type="text" name="isbn">'
print ' or <a href="/random">random</a><br>'
print '</td></tr><tr><td align="right">LCCN</td><td>'
if lccn:
print '<input type="text" name="lccn" value="%s">' % web.htmlquote(lccn)
else:
print '<input type="text" name="lccn">'
print '</td></tr><tr><td align="right">OCLC</td><td>'
if oclc:
print '<input type="text" name="oclc" value="%s">' % web.htmlquote(oclc)
else:
print '<input type="text" name="oclc">'
print "</td></tr>",
print '<tr><td></td><td><input type="submit" value="find"></td></tr>'
print "</table>"
print "</form>"
if isbn:
search("isbn", isbn)
elif lccn:
search("lccn", lccn)
elif oclc:
search("oclc", oclc)
print "</body></html>"
示例7: render
def render(self):
out = []
for i in self.inputs:
if i.description != '':
out.append('<label for="%s">%s</label><br>\n' % (i.id, web.htmlquote(i.description)))
out.append('%s<br><br>\n' % i.render())
return ''.join(out)
示例8: get_web_safe_diff
def get_web_safe_diff(text1, text2):
lines1 = text1.splitlines(True)
lines2 = text2.splitlines(True)
diff = []
s = difflib.SequenceMatcher(a=lines1, b=lines2)
commands = s.get_opcodes()
for command, i1, i2, j1, j2 in commands:
if command == 'replace':
inline_diff = diff_inline(''.join(lines1[i1:i2]), ''.join(lines2[j1:j2]))
diff.extend(inline_diff)
elif command == 'insert':
diff.append(DiffTag('<ins>'))
diff.extend(lines2[j1:j2])
diff.append(DiffTag('</ins>'))
elif command == 'delete':
diff.append(DiffTag('<del>'))
diff.extend(lines1[i1:i2])
diff.append(DiffTag('</del>'))
escaped_diff = []
for s in diff:
if isinstance(s, DiffTag):
pass
else:
s = web.htmlquote(s)
escaped_diff.append(s)
return ''.join(escaped_diff).replace('\n', '<br>\n')
示例9: GET
def GET(self):
web.header('Content-Type','text/html; charset=utf-8', unique=True)
input = web.input()
if 'oclc' in input:
html_oclc = web.htmlquote(input.oclc)
print "<html>\n<head><title>OCLC to MARC: %s</title><body>" % html_oclc
else:
print "<html>\n<head><title>OCLC to MARC</title><body>"
print '<form method="get">'
print 'OCLC:'
if 'oclc' in input:
print '<input type="text" name="oclc" value="%s">' % html_oclc
else:
print '<input type="text" name="oclc">'
print '<input type="submit" value="Find MARC">'
print '</form>'
if 'oclc' in input:
print 'Searching for OCLC: %s<p>' % html_oclc
if input.oclc in dbm:
loc = dbm[input.oclc]
print '<ul>'
for l in loc.split(' '):
print '<li><a href="http://openlibrary.org/show-marc/%s">%s</a>' % (l, l)
print '</ul>'
else:
print html_oclc, 'not found'
示例10: better_diff
def better_diff(a, b):
out = []
a, b = html2list(a), html2list(b)
s = difflib.SequenceMatcher(None, a, b)
for e in s.get_opcodes():
if e[0] == "replace":
out.append('<span class="delete">'+ web.htmlquote(''.join(a[e[1]:e[2]])) + "</span>")
out.append('<span class="insert">'+ web.htmlquote(''.join(b[e[3]:e[4]])) + "</span>")
elif e[0] == "delete":
out.append('<span class="delete">'+ web.htmlquote(''.join(a[e[1]:e[2]])) + "</span>")
elif e[0] == "insert":
out.append('<span class="insert">'+ web.htmlquote(''.join(b[e[3]:e[4]])) + "</span>")
elif e[0] == "equal":
out.append(web.htmlquote(''.join(b[e[3]:e[4]])))
out = ''.join(out)
return re.sub(r'(\r\n|\n|\r)', '<br />\n', out)
示例11: title_search
def title_search(self, v):
q = {'type': '/type/edition', 'isbn_10': None, 'title': v}
editions = []
for e in query_iter(q):
e['title'] = v
editions.append(e)
yield 'searcing for title "' + web.htmlquote(v) + '": '
for i in self.search(editions):
yield i
示例12: isbn_search
def isbn_search(self, v):
q = {"type": "/type/edition", "isbn_10": v, "title": None, "subtitle": None}
editions = []
for e in query_iter(q):
e["isbn_10"] = v
editions.append(e)
yield "searching for ISBN " + web.htmlquote(v) + ": "
for i in self.search(editions):
yield i
示例13: search
def search(self, editions):
yield str(len(editions)) + " editions found<p>"
yield "<table>"
yield "<tr><th>Key</th><th>ISBN</th><th>title</th><th>subtitle</th></tr>"
for e in editions:
url = "http://openlibrary.org" + e["key"]
title = web.htmlquote(e["title"]) if e["title"] else "no title"
yield '<tr><td><a href="%s">%s</a></td>' % (url, e["key"])
yield "<td>%s</td><td>%s</td><td>%s</td></tr>" % (
e["isbn_10"],
title,
(web.htmlquote(e["subtitle"]) if e.get("subtitle", None) else "<i>no subtitle</i>"),
)
yield "</table><p>"
if len(editions) == 2:
yield "2 editions found, lets compare them<br>"
for i in self.compare(editions):
yield i
示例14: oclc_search
def oclc_search(self, v):
q = {'type': '/type/edition', 'oclc_numbers': v, 'title': None, 'subtitle': None, 'isbn_10': None}
editions = []
print q
for e in query_iter(q):
e['oclc_numbers'] = v
editions.append(e)
yield 'searching for OCLC ' + web.htmlquote(v) + ': '
for i in self.search(editions):
yield i
示例15: inside_solr_select
def inside_solr_select(params):
params.setdefault("wt", "json")
#solr_select = solr_select_url + '?' + '&'.join("%s=%s" % (k, unicode(v)) for k, v in params)
solr_select = solr_select_url + "?" + urllib.urlencode(params)
stats.begin("solr", url=solr_select)
try:
json_data = urlopen(solr_select).read()
except IOError, e:
logger.error("Unable to query search inside solr", exc_info=True)
return {"error": web.htmlquote(str(e))}