本文整理汇总了Python中MoinMoin.wikiutil.escape函数的典型用法代码示例。如果您正苦于以下问题:Python escape函数的具体用法?Python escape怎么用?Python escape使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了escape函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: revert_pages
def revert_pages(request, editor, timestamp):
_ = request.getText
editor = wikiutil.url_unquote(editor)
timestamp = int(timestamp * 1000000)
log = editlog.EditLog(request)
pages = {}
revertpages = []
for line in log.reverse():
if line.ed_time_usecs < timestamp:
break
if not request.user.may.read(line.pagename):
continue
if not line.pagename in pages:
pages[line.pagename] = 1
if repr(line.getInterwikiEditorData(request)) == editor:
revertpages.append(line.pagename)
request.write("Pages to revert:<br>%s" % "<br>".join([wikiutil.escape(p) for p in revertpages]))
for pagename in revertpages:
request.write("Begin reverting %s ...<br>" % wikiutil.escape(pagename))
msg = revert_page(request, pagename, editor)
if msg:
request.write("<p>%s: %s</p>" % (
Page.Page(request, pagename).link_to(request), msg))
request.write("Finished reverting %s.<br>" % wikiutil.escape(pagename))
示例2: html_head
def html_head(self, d):
""" Assemble html head
@param d: parameter dictionary
@rtype: unicode
@return: html head
"""
html = [
u'<meta name="viewport" content="user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, width=device-width" />',
u'<meta name="viewport" content="width=device-width, initial-scale=1.0">',
u'<title>%(title)s - %(sitename)s</title>' % {
'title': wikiutil.escape(d['title']),
'sitename': wikiutil.escape(d['sitename']),
},
self.externalScript('common'),
self.headscript(d), # Should move to separate .js file
#self.guiEditorScript(d),
self.html_stylesheets(d),
#/moin_static195/common/js/jquery-1.8.2.min.js
u'<script language="javascript" type="Text/javascript" src="/moin_static195/common/js/jquery-1.8.2.min.js"></script>',
u'<script language="javascript" type="Text/javascript" src="/moin_static195/common/bootstrap/js/bootstrap.min.js"></script>',
# u'<script language="javascript" type="Text/javascript" src="/moin_static195/common/bootstrap/js/bootstrap-dropdown.js"></script>',
u'<link rel="stylesheet" type="text/css" charset="utf-8" href="/moin_static195/common/bootstrap/css/bootstrap.css">',
self.rsslink(d),
#self.universal_edit_button(d),
]
return '\n'.join(html)
示例3: send_link_rel
def send_link_rel(request, pagename):
files = _get_files(request, pagename)
for fname in files:
url = getAttachUrl(pagename, fname, request, do='view')
request.write(u'<link rel="Appendix" title="%s" href="%s">\n' % (
wikiutil.escape(fname, 1),
wikiutil.escape(url, 1)))
示例4: renderInText
def renderInText(self):
""" Render macro in text context
The parser should decide what to do if this macro is placed in a
paragraph context.
"""
_ = self.request.getText
# Default to show page instead of an error message (too lazy to
# do an error message now).
action = self.args.get('action', 'show')
# Use translated text or action name
text = self.args.get('text', action)
text = _(text, formatted=False)
# Escape user input
action = wikiutil.escape(action, 1)
text = wikiutil.escape(text, 1)
# Create link
formatter = self.macro.formatter
page = wikiutil.quoteWikinameURL(formatter.page.page_name)
url = '%s?action=%s' % (page, action)
link = wikiutil.link_tag(self.request, url, text=text,
formatter=formatter)
return link
示例5: title
def title(self, d):
""" Assemble the title (now using breadcrumbs)
@param d: parameter dictionary
@rtype: string
@return: title html
"""
_ = self.request.getText
content = []
if d['title_link']: # having a link means we have a (linked) pagename ONLY as title, not a message title
# XXX this method is rather ugly and should be improved
curpage = ''
segments = d['page_name'].split('/') # was: title_text
for s in segments[:-1]:
curpage += s
content.append("<li>%s</li>" % Page(self.request, curpage).link_to(self.request, s))
curpage += '/'
content.append(('<li><a class="backlink" title="%(title)s" href="%(href)s">%(text)s</a></li>') % {
'title': _('Click to do a full-text search for this title'),
'href': d['title_link'],
'text': wikiutil.escape(segments[-1]),
})
else:
content.append('<li>%s</li>' % wikiutil.escape(d['title_text']))
html = '''
<ul id="pagelocation">
%s
</ul>
''' % "".join(content)
return html
示例6: renderInPage
def renderInPage(self):
""" Render macro in page context
The parser should decide what to do if this macro is placed in a
paragraph context.
"""
f = self.formatter
_ = self.request.getText
requires_input = '%s' in self.nametemplate
# TODO: better abstract this using the formatter
html = [
u'<form class="macro" method="POST" action="%s"><div>' % self.request.href(self.formatter.page.page_name),
u'<input type="hidden" name="action" value="newpage">',
u'<input type="hidden" name="parent" value="%s">' % wikiutil.escape(self.parent, 1),
u'<input type="hidden" name="template" value="%s">' % wikiutil.escape(self.template, 1),
u'<input type="hidden" name="nametemplate" value="%s">' % wikiutil.escape(self.nametemplate, 1),
]
if requires_input:
html += [
u'<input type="text" name="pagename" size="30">',
]
html += [
u'<input type="submit" value="%s">' % wikiutil.escape(self.label, 1),
u'</div></form>',
]
return self.formatter.rawHTML('\n'.join(html))
示例7: attachment_inlined
def attachment_inlined(self, url, text, **kw):
url = wikiutil.escape(url)
text = wikiutil.escape(text)
if url == text:
return '<span style="background-color:#ffff11">{{attachment:%s}}</span>' % url
else:
return '<span style="background-color:#ffff11">{{attachment:%s|%s}}</span>' % (url, text)
示例8: explore_args
def explore_args(args, kwAllowed):
"""
explore args for positional and keyword parameters
"""
if args:
args = args.split(',')
args = [arg.strip() for arg in args]
else:
args = []
kw_count = 0
kw = {} # create a dictionary for the formatter.image call
pp = [] # positional parameter
if not kwAllowed:
return pp, 0, kw, 0
for arg in args:
if '=' in arg:
key, value = arg.split('=', 1)
# avoid that urls with "=" are interpreted as keyword
if key.lower() not in kwAllowed:
if not kw_count and _is_URL(arg):
# assuming that this is the image
pp.append(wikiutil.escape(arg, quote=1))
continue
kw_count += 1
kw[str(key.lower())] = wikiutil.escape(value, quote=1)
else:
pp.append(wikiutil.escape(arg, quote=1))
return pp, len(pp), kw, len(kw)
示例9: send_viewfile
def send_viewfile(pagename, request):
_ = request.getText
filename, fpath = _access_file(pagename, request)
if not filename: return
request.write('<h2>' + _("Attachment '%(filename)s'") % {'filename': filename} + '</h2>')
type, enc = mimetypes.guess_type(filename)
if type:
if type[:5] == 'image':
timestamp = htdocs_access(request) and "?%s" % time.time() or ''
request.write('<img src="%s%s" alt="%s">' % (
getAttachUrl(pagename, filename, request, escaped=1), timestamp, wikiutil.escape(filename, 1)))
return
elif type[:4] == 'text':
# TODO: should use formatter here!
request.write("<pre>")
# Try to decode file contents. It may return junk, but we
# don't have enough information on attachments.
content = open(fpath, 'r').read()
content = wikiutil.decodeUnknownInput(content)
content = wikiutil.escape(content)
request.write(content)
request.write("</pre>")
return
request.write('<p>' + _("Unknown file type, cannot display this attachment inline.") + '</p>')
request.write('<a href="%s">%s</a>' % (
getAttachUrl(pagename, filename, request, escaped=1), wikiutil.escape(filename)))
示例10: _create_user
def _create_user(request):
collab_mode = getattr(request.cfg, 'collab_mode', False)
_ = request.getText
form = request.form
if request.method != 'POST':
return
if not wikiutil.checkTicket(request, form.get('ticket', '')):
return
if not TextCha(request).check_answer_from_form():
return _('TextCha: Wrong answer! Go back and try again...')
# Create user profile
theuser = user.User(request, auth_method="new-user")
# Require non-empty name
try:
if collab_mode:
name = wikiutil.clean_input(form.get('email', ['']))
theuser.name = name.strip()
else:
theuser.name = form['name']
except KeyError:
return _("Empty user name. Please enter a user name.")
# Don't allow creating users with invalid names
if not user.isValidName(request, theuser.name):
return _("""Invalid user name {{{'%s'}}}.
Name may contain any Unicode alpha numeric character, with optional one
space between words. Group page name is not allowed.""", wiki=True) % wikiutil.escape(theuser.name)
# Name required to be unique. Check if name belong to another user.
if user.getUserId(request, theuser.name):
return _("This user name already belongs to somebody else.")
# try to get the password and pw repeat
password = form.get('password1', '')
password2 = form.get('password2', '')
# Check if password is given and matches with password repeat
if password != password2:
return _("Passwords don't match!")
if not password:
return _("Please specify a password!")
pw_checker = request.cfg.password_checker
if pw_checker:
pw_error = pw_checker(request, theuser.name, password)
if pw_error:
return _("Password not acceptable: %s") % wikiutil.escape(pw_error)
# Encode password
try:
theuser.enc_password = user.encodePassword(request.cfg, password)
except UnicodeError, err:
# Should never happen
return "Can't encode password: %s" % wikiutil.escape(str(err))
示例11: _make_form_values
def _make_form_values(self, question, given_answer):
timestamp = time()
question_form = "%s %d%s" % (
wikiutil.escape(question, True),
timestamp,
self._compute_signature(question, timestamp)
)
given_answer_form = wikiutil.escape(given_answer, True)
return question_form, given_answer_form
示例12: handle_action
def handle_action(context, pagename, action_name='show'):
""" Actual dispatcher function for non-XMLRPC actions.
Also sets up the Page object for this request, normalizes and
redirects to canonical pagenames and checks for non-allowed
actions.
"""
_ = context.getText
cfg = context.cfg
# pagename could be empty after normalization e.g. '///' -> ''
# Use localized FrontPage if pagename is empty
if not pagename:
context.page = wikiutil.getFrontPage(context)
else:
context.page = Page(context, pagename)
if '_' in pagename and not context.page.exists():
pagename = pagename.replace('_', ' ')
page = Page(context, pagename)
if page.exists():
url = page.url(context)
return context.http_redirect(url)
msg = None
# Complain about unknown actions
if not action_name in get_names(cfg):
msg = _("Unknown action %(action_name)s.") % {
'action_name': wikiutil.escape(action_name), }
# Disallow non available actions
elif action_name[0].isupper() and not action_name in \
get_available_actions(cfg, context.page, context.user):
msg = _("You are not allowed to do %(action_name)s on this page.") % {
'action_name': wikiutil.escape(action_name), }
if not context.user.valid:
# Suggest non valid user to login
msg += " " + _("Login and try again.")
if msg:
context.theme.add_msg(msg, "error")
context.page.send_page()
# Try action
else:
from MoinMoin import action
handler = action.getHandler(context, action_name)
if handler is None:
msg = _("You are not allowed to do %(action_name)s on this page.") % {
'action_name': wikiutil.escape(action_name), }
if not context.user.valid:
# Suggest non valid user to login
msg += " " + _("Login and try again.")
context.theme.add_msg(msg, "error")
context.page.send_page()
else:
handler(context.page.page_name, context)
return context
示例13: line2dict
def line2dict(self, line):
"""Return ';;' separated 'key=val' tuples as dict."""
d = {}
items = line.split(';;')
d['name'] = wikiutil.escape(items[0])
for item in items[1:]:
keyval = item.split('=')
if len(keyval) != 2:
return {}
key, val = keyval
d[wikiutil.escape(key)] = wikiutil.escape(val)
return d
示例14: _do_move
def _do_move(pagename, request):
_ = request.getText
pagename, filename, fpath = _access_file(pagename, request)
if not request.user.may.delete(pagename):
return _('You are not allowed to move attachments from this page.')
if not filename:
return # error msg already sent in _access_file
# move file
d = {'action': action_name,
'url': request.href(pagename),
'do': 'attachment_move',
'ticket': wikiutil.createTicket(request),
'pagename': wikiutil.escape(pagename, 1),
'attachment_name': wikiutil.escape(filename, 1),
'move': _('Move'),
'cancel': _('Cancel'),
'newname_label': _("New page name"),
'attachment_label': _("New attachment name"),
}
formhtml = '''
<form action="%(url)s" method="POST">
<input type="hidden" name="action" value="%(action)s">
<input type="hidden" name="do" value="%(do)s">
<input type="hidden" name="ticket" value="%(ticket)s">
<table>
<tr>
<td class="label"><label>%(newname_label)s</label></td>
<td class="content">
<input type="text" name="newpagename" value="%(pagename)s" size="80">
</td>
</tr>
<tr>
<td class="label"><label>%(attachment_label)s</label></td>
<td class="content">
<input type="text" name="newattachmentname" value="%(attachment_name)s" size="80">
</td>
</tr>
<tr>
<td></td>
<td class="buttons">
<input type="hidden" name="oldattachmentname" value="%(attachment_name)s">
<input type="submit" name="move" value="%(move)s">
<input type="submit" name="cancel" value="%(cancel)s">
</td>
</tr>
</table>
</form>''' % d
thispage = Page(request, pagename)
request.theme.add_msg(formhtml, "dialog")
return thispage.send_page()
示例15: send_link_rel
def send_link_rel(request, pagename):
files = _get_files(request, pagename)
if len(files) > 0 and not htdocs_access(request):
scriptName = request.getScriptname()
pagename_quoted = wikiutil.quoteWikinameURL(pagename)
for file in files:
url = "%s/%s?action=%s&do=view&target=%s" % (
scriptName, pagename_quoted,
action_name, wikiutil.url_quote_plus(file))
request.write(u'<link rel="Appendix" title="%s" href="%s">\n' % (
wikiutil.escape(file), wikiutil.escape(url)))