本文整理汇总了Python中Mailman.Utils.websafe方法的典型用法代码示例。如果您正苦于以下问题:Python Utils.websafe方法的具体用法?Python Utils.websafe怎么用?Python Utils.websafe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mailman.Utils
的用法示例。
在下文中一共展示了Utils.websafe方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: topic_details
# 需要导入模块: from Mailman import Utils [as 别名]
# 或者: from Mailman.Utils import websafe [as 别名]
def topic_details(mlist, doc, user, cpuser, userlang, varhelp):
# Find out which topic the user wants to get details of
reflist = varhelp.split("/")
name = None
topicname = _("<missing>")
if len(reflist) == 1:
topicname = urllib.unquote_plus(reflist[0])
for name, pattern, description, emptyflag in mlist.topics:
if name == topicname:
break
else:
name = None
if not name:
options_page(mlist, doc, user, cpuser, userlang, _("Requested topic is not valid: %(topicname)s"))
print doc.Format()
return
table = Table(border=3, width="100%")
table.AddRow([Center(Bold(_("Topic filter details")))])
table.AddCellInfo(table.GetCurrentRowIndex(), 0, colspan=2, bgcolor=mm_cfg.WEB_SUBHEADER_COLOR)
table.AddRow([Bold(Label(_("Name:"))), Utils.websafe(name)])
table.AddRow([Bold(Label(_("Pattern (as regexp):"))), "<pre>" + Utils.websafe(pattern) + "</pre>"])
table.AddRow([Bold(Label(_("Description:"))), Utils.websafe(description)])
# Make colors look nice
for row in range(1, 4):
table.AddCellInfo(row, 0, bgcolor=mm_cfg.WEB_ADMINITEM_COLOR)
options_page(mlist, doc, user, cpuser, userlang, table.Format())
print doc.Format()
示例2: main
# 需要导入模块: from Mailman import Utils [as 别名]
# 或者: from Mailman.Utils import websafe [as 别名]
def main():
doc = Document()
doc.set_language(mm_cfg.DEFAULT_SERVER_LANGUAGE)
parts = Utils.GetPathPieces()
lenparts = parts and len(parts)
if not parts or lenparts < 1:
title = _("CGI script error")
doc.SetTitle(title)
doc.AddItem(Header(2, title))
doc.addError(_("Invalid options to CGI script."))
doc.AddItem("<hr>")
doc.AddItem(MailmanLogo())
print doc.Format()
return
# get the list and user's name
listname = parts[0].lower()
# open list
try:
mlist = MailList.MailList(listname, lock=0)
except Errors.MMListError, e:
# Avoid cross-site scripting attacks
safelistname = Utils.websafe(listname)
title = _("CGI script error")
doc.SetTitle(title)
doc.AddItem(Header(2, title))
doc.addError(_("No such list <em>%(safelistname)s</em>"))
doc.AddItem("<hr>")
doc.AddItem(MailmanLogo())
# Send this with a 404 status.
print "Status: 404 Not Found"
print doc.Format()
syslog("error", 'No such list "%s": %s\n', listname, e)
return
示例3: main
# 需要导入模块: from Mailman import Utils [as 别名]
# 或者: from Mailman.Utils import websafe [as 别名]
def main():
doc = Document()
doc.set_language(mm_cfg.DEFAULT_SERVER_LANGUAGE)
cgidata = cgi.FieldStorage()
parts = Utils.GetPathPieces()
if not parts:
# Bad URL specification
title = _('Bad URL specification')
doc.SetTitle(title)
doc.AddItem(
Header(3, Bold(FontAttr(title, color='#ff0000', size='+2'))))
doc.AddItem('<hr>')
doc.AddItem(MailmanLogo())
print doc.Format()
syslog('error', 'Bad URL specification: %s', parts)
return
listname = parts[0].lower()
try:
mlist = MailList.MailList(listname, lock=0)
except Errors.MMListError, e:
# Avoid cross-site scripting attacks
safelistname = Utils.websafe(listname)
title = _('No such list <em>%(safelistname)s</em>')
doc.SetTitle(title)
doc.AddItem(
Header(3,
Bold(FontAttr(title, color='#ff0000', size='+2'))))
doc.AddItem('<hr>')
doc.AddItem(MailmanLogo())
print doc.Format()
syslog('error', 'No such list "%s": %s\n', listname, e)
return
示例4: FormatBox
# 需要导入模块: from Mailman import Utils [as 别名]
# 或者: from Mailman.Utils import websafe [as 别名]
def FormatBox(self, name, size=20, value=''):
if isinstance(value, str):
safevalue = Utils.websafe(value)
else:
safevalue = value
return '<INPUT type="Text" name="%s" size="%d" value="%s">' % (
name, size, safevalue)
示例5: GetStandardReplacements
# 需要导入模块: from Mailman import Utils [as 别名]
# 或者: from Mailman.Utils import websafe [as 别名]
def GetStandardReplacements(self, lang=None):
dmember_len = len(self.getDigestMemberKeys())
member_len = len(self.getRegularMemberKeys())
# If only one language is enabled for this mailing list, omit the
# language choice buttons.
if len(self.GetAvailableLanguages()) == 1:
listlangs = _(Utils.GetLanguageDescr(self.preferred_language))
else:
listlangs = self.GetLangSelectBox(lang).Format()
d = {
'<mm-mailman-footer>' : self.GetMailmanFooter(),
'<mm-list-name>' : self.real_name,
'<mm-email-user>' : self._internal_name,
'<mm-list-description>' : Utils.websafe(self.description),
'<mm-list-info>' :
'<!---->' + BR.join(self.info.split(NL)) + '<!---->',
'<mm-form-end>' : self.FormatFormEnd(),
'<mm-archive>' : self.FormatArchiveAnchor(),
'</mm-archive>' : '</a>',
'<mm-list-subscription-msg>' : self.FormatSubscriptionMsg(),
'<mm-restricted-list-message>' : \
self.RestrictedListMessage(_('The current archive'),
self.archive_private),
'<mm-num-reg-users>' : `member_len`,
'<mm-num-digesters>' : `dmember_len`,
'<mm-num-members>' : (`member_len + dmember_len`),
'<mm-posting-addr>' : '%s' % self.GetListEmail(),
'<mm-request-addr>' : '%s' % self.GetRequestEmail(),
'<mm-owner>' : self.GetOwnerEmail(),
'<mm-reminder>' : self.FormatReminder(self.preferred_language),
'<mm-host>' : self.host_name,
'<mm-list-langs>' : listlangs,
}
示例6: handler
# 需要导入模块: from Mailman import Utils [as 别名]
# 或者: from Mailman.Utils import websafe [as 别名]
def handler (self, parts):
lists = []
for name, mlist in self.all_mls.iteritems():
members = mlist.getRegularMemberKeys()
subscribed = True if self.curr_user in members else False
if not mlist.advertised and not subscribed:
continue
lists.append({'script_url' : mlist.GetScriptURL('listinfo'),
'real_name' : mlist.real_name,
'description' : Utils.websafe(mlist.description),
'subscribed' : subscribed,
'owners' : ', '.join(mlist.owner),
'owner-email' : mlist.GetOwnerEmail(),
'advertised' : mlist.advertised,
})
self.kwargs_add('lists', lists)
if len(parts) > 0:
try:
self.add_req_ln_details(parts[0].strip())
except:
self.kwargs_add('vl_ln', None)
else:
self.kwargs_add('vl_ln', None)
self.render()
示例7: errcheck
# 需要导入模块: from Mailman import Utils [as 别名]
# 或者: from Mailman.Utils import websafe [as 别名]
def errcheck (self, action):
"""Performs all error checks. Returns None is all's good. Otherwise
returns a string with error message."""
if not can_create_lists(self.curr_user):
return 'You are not authorized to creates lists on this server'
if len(self.owner) <= 0:
return 'Cannot create list without a owner.'
if self.ln == '':
return 'You forgot to enter the list name'
if '@' in self.ln:
return 'List name must not include "@": %s' % self.safeln
if action == 'create' and Utils.list_exists(self.ln):
return 'List already exists: %s' % self.safe_ln
if mm_cfg.VIRTUAL_HOST_OVERVIEW and \
not mm_cfg.VIRTUAL_HOSTS.has_key(self.hn):
safehostname = Utils.websafe(self.hn)
return 'Unknown virtual host: %s' % safehostname
return None
示例8: scrub_html1
# 需要导入模块: from Mailman import Utils [as 别名]
# 或者: from Mailman.Utils import websafe [as 别名]
def scrub_html1(self, part):
# sanitize == 1
payload = Utils.websafe(part.get_payload(decode=True))
# For whitespace in the margin, change spaces into
# non-breaking spaces, and tabs into 8 of those. Then use a
# mono-space font. Still looks hideous to me, but then I'd
# just as soon discard them.
def doreplace(s):
return s.expandtabs(8).replace(' ', ' ')
lines = [doreplace(s) for s in payload.split('\n')]
payload = '<tt>\n' + BR.join(lines) + '\n</tt>\n'
part.set_payload(payload)
# We're replacing the payload with the decoded payload so this
# will just get in the way.
del part['content-transfer-encoding']
omask = os.umask(002)
try:
url = save_attachment(self.mlist, part, self.dir,
filter_html=False)
finally:
os.umask(omask)
self.msgtexts.append(unicode(_("""\
An HTML attachment was scrubbed...
URL: %(url)s
"""), self.lcset))
示例9: FormatHidden
# 需要导入模块: from Mailman import Utils [as 别名]
# 或者: from Mailman.Utils import websafe [as 别名]
def FormatHidden(name, value='display'):
if isinstance(value, str):
safevalue = Utils.websafe(value)
else:
safevalue = value
return '<INPUT type="Hidden" name="%s" value="%s">' % (
name, safevalue)
示例10: Format
# 需要导入模块: from Mailman import Utils [as 别名]
# 或者: from Mailman.Utils import websafe [as 别名]
def Format(self, indent=0):
# If I don't start a new I ignore indent
output = '<%s>%s</%s>' % (
self.tag,
Utils.websafe(Container.Format(self, indent)),
self.tag)
return output
示例11: main
# 需要导入模块: from Mailman import Utils [as 别名]
# 或者: from Mailman.Utils import websafe [as 别名]
def main():
doc = Document()
doc.set_language(mm_cfg.DEFAULT_SERVER_LANGUAGE)
parts = Utils.GetPathPieces()
if not parts:
doc.SetTitle(_("Private Archive Error"))
doc.AddItem(Header(3, _("You must specify a list.")))
print doc.Format()
return
path = os.environ.get('PATH_INFO')
tpath = true_path(path)
if tpath <> path[1:]:
msg = _('Private archive - "./" and "../" not allowed in URL.')
doc.SetTitle(msg)
doc.AddItem(Header(2, msg))
print doc.Format()
syslog('mischief', 'Private archive hostile path: %s', path)
return
# BAW: This needs to be converted to the Site module abstraction
true_filename = os.path.join(
mm_cfg.PRIVATE_ARCHIVE_FILE_DIR, tpath)
listname = parts[0].lower()
mboxfile = ''
if len(parts) > 1:
mboxfile = parts[1]
# See if it's the list's mbox file is being requested
if listname.endswith('.mbox') and mboxfile.endswith('.mbox') and \
listname[:-5] == mboxfile[:-5]:
listname = listname[:-5]
else:
mboxfile = ''
# If it's a directory, we have to append index.html in this script. We
# must also check for a gzipped file, because the text archives are
# usually stored in compressed form.
if os.path.isdir(true_filename):
true_filename = true_filename + '/index.html'
if not os.path.exists(true_filename) and \
os.path.exists(true_filename + '.gz'):
true_filename = true_filename + '.gz'
try:
mlist = MailList.MailList(listname, lock=0)
except Errors.MMListError, e:
# Avoid cross-site scripting attacks
safelistname = Utils.websafe(listname)
msg = _('No such list <em>%(safelistname)s</em>')
doc.SetTitle(_("Private Archive Error - %(msg)s"))
doc.AddItem(Header(2, msg))
# Send this with a 404 status.
print 'Status: 404 Not Found'
print doc.Format()
syslog('error', 'private: No such list "%s": %s\n', listname, e)
return
示例12: request_create
# 需要导入模块: from Mailman import Utils [as 别名]
# 或者: from Mailman.Utils import websafe [as 别名]
def request_create (self):
"""Creates a list (name taken from the CGI form value called lc_name).
Returns None if the list was created successfully. Returns a string
containing error message if list could not be created for whatever
reason."""
self._ml = MailList.MailList()
err = self.errcheck(action='create')
if err:
return err
# We've got all the data we need, so go ahead and try to create the
# list See admin.py for why we need to set up the signal handler.
try:
signal.signal(signal.SIGTERM, self.sigterm_handler)
pwhex = sha_new(self.pw).hexdigest()
# Guarantee that all newly created files have the proper permission.
# proper group ownership should be assured by the autoconf script
# enforcing that all directories have the group sticky bit set
oldmask = os.umask(002)
try:
try:
self.ml.Create(self.ln, self.owner[0], pwhex, self.langs,
self.eh, urlhost=self.hn)
finally:
os.umask(oldmask)
except Errors.EmailAddressError, e:
if e.args:
s = Utils.websafe(e.args[0])
else:
s = Utils.websafe(owner)
return 'Bad owner email address: %s' % s
except Errors.MMListAlreadyExistsError:
return 'List already exists: %s' % self.ln
except Errors.BadListNameError, e:
if e.args:
s = Utils.websafe(e.args[0])
else:
s = Utils.websafe(listname)
return 'Illegal list name: %s' % self.ln
示例13: __init__
# 需要导入模块: from Mailman import Utils [as 别名]
# 或者: from Mailman.Utils import websafe [as 别名]
def __init__(self, name, text='', rows=None, cols=None, wrap='soft',
readonly=0):
if isinstance(text, str):
safetext = Utils.websafe(text)
else:
safetext = text
self.name = name
self.text = safetext
self.rows = rows
self.cols = cols
self.wrap = wrap
self.readonly = readonly
示例14: show_pending_unsubs
# 需要导入模块: from Mailman import Utils [as 别名]
# 或者: from Mailman.Utils import websafe [as 别名]
def show_pending_unsubs(mlist, form):
# Add the pending unsubscription request section
lang = mlist.preferred_language
pendingunsubs = mlist.GetUnsubscriptionIds()
if not pendingunsubs:
return 0
table = Table(border=2)
table.AddRow([Center(Bold(_('User address/name'))),
Center(Bold(_('Your decision'))),
Center(Bold(_('Reason for refusal')))
])
# Alphabetical order by email address
byaddrs = {}
for id in pendingunsubs:
addr = mlist.GetRecord(id)
byaddrs.setdefault(addr, []).append(id)
addrs = byaddrs.keys()
addrs.sort()
num = 0
for addr, ids in byaddrs.items():
# Eliminate duplicates
for id in ids[1:]:
mlist.HandleRequest(id, mm_cfg.DISCARD)
id = ids[0]
addr = mlist.GetRecord(id)
try:
fullname = Utils.uncanonstr(mlist.getMemberName(addr), lang)
except Errors.NotAMemberError:
# They must have been unsubscribed elsewhere, so we can just
# discard this record.
mlist.HandleRequest(id, mm_cfg.DISCARD)
continue
num += 1
# While the address may be a unicode, it must be ascii
paddr = addr.encode('us-ascii', 'replace')
table.AddRow(['%s<br><em>%s</em>' % (paddr, Utils.websafe(fullname)),
RadioButtonArray(id, (_('Defer'),
_('Approve'),
_('Reject'),
_('Discard')),
values=(mm_cfg.DEFER,
mm_cfg.UNSUBSCRIBE,
mm_cfg.REJECT,
mm_cfg.DISCARD),
checked=0),
TextBox('comment-%d' % id, size=45)
])
if num > 0:
form.AddItem('<hr>')
form.AddItem(Center(Header(2, _('Unsubscription Requests'))))
form.AddItem(table)
return num
示例15: show_pending_subs
# 需要导入模块: from Mailman import Utils [as 别名]
# 或者: from Mailman.Utils import websafe [as 别名]
def show_pending_subs(mlist, form):
# Add the subscription request section
pendingsubs = mlist.GetSubscriptionIds()
if not pendingsubs:
return 0
form.AddItem('<hr>')
form.AddItem(Center(Header(2, _('Subscription Requests'))))
table = Table(border=2)
table.AddRow([Center(Bold(_('Address/name'))),
Center(Bold(_('Your decision'))),
Center(Bold(_('Reason for refusal')))
])
# Alphabetical order by email address
byaddrs = {}
for id in pendingsubs:
addr = mlist.GetRecord(id)[1]
byaddrs.setdefault(addr, []).append(id)
addrs = byaddrs.items()
addrs.sort()
num = 0
for addr, ids in addrs:
# Eliminate duplicates
for id in ids[1:]:
mlist.HandleRequest(id, mm_cfg.DISCARD)
id = ids[0]
time, addr, fullname, passwd, digest, lang = mlist.GetRecord(id)
fullname = Utils.uncanonstr(fullname, mlist.preferred_language)
radio = RadioButtonArray(id, (_('Defer'),
_('Approve'),
_('Reject'),
_('Discard')),
values=(mm_cfg.DEFER,
mm_cfg.SUBSCRIBE,
mm_cfg.REJECT,
mm_cfg.DISCARD),
checked=0).Format()
if addr not in mlist.ban_list:
radio += ('<br>' + '<label>' +
CheckBox('ban-%d' % id, 1).Format() +
' ' + _('Permanently ban from this list') +
'</label>')
# While the address may be a unicode, it must be ascii
paddr = addr.encode('us-ascii', 'replace')
table.AddRow(['%s<br><em>%s</em>' % (paddr, Utils.websafe(fullname)),
radio,
TextBox('comment-%d' % id, size=40)
])
num += 1
if num > 0:
form.AddItem(table)
return num