本文整理汇总了Python中mailman.interfaces.requests.IListRequests.of_type方法的典型用法代码示例。如果您正苦于以下问题:Python IListRequests.of_type方法的具体用法?Python IListRequests.of_type怎么用?Python IListRequests.of_type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mailman.interfaces.requests.IListRequests
的用法示例。
在下文中一共展示了IListRequests.of_type方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_collection
# 需要导入模块: from mailman.interfaces.requests import IListRequests [as 别名]
# 或者: from mailman.interfaces.requests.IListRequests import of_type [as 别名]
def _get_collection(self, request):
requests = IListRequests(self._mlist)
self._requests = requests
items = []
for request_type in MEMBERSHIP_CHANGE_REQUESTS:
for request in requests.of_type(request_type):
items.append(request)
return items
示例2: auto_discard
# 需要导入模块: from mailman.interfaces.requests import IListRequests [as 别名]
# 或者: from mailman.interfaces.requests.IListRequests import of_type [as 别名]
def auto_discard(mlist):
# Discard old held messages
discard_count = 0
expire = config.days(mlist.max_days_to_hold)
requestsdb = IListRequests(mlist)
heldmsgs = list(requestsdb.of_type(RequestType.held_message))
if expire and heldmsgs:
for request in heldmsgs:
key, data = requestsdb.get_request(request.id)
if now - data['date'] > expire:
handle_request(mlist, request.id, config.DISCARD)
discard_count += 1
mlist.Save()
return discard_count
示例3: pending_requests
# 需要导入模块: from mailman.interfaces.requests import IListRequests [as 别名]
# 或者: from mailman.interfaces.requests.IListRequests import of_type [as 别名]
def pending_requests(mlist):
# Must return a byte string
lcset = mlist.preferred_language.charset
pending = []
first = True
requestsdb = IListRequests(mlist)
for request in requestsdb.of_type(RequestType.subscription):
if first:
pending.append(_('Pending subscriptions:'))
first = False
key, data = requestsdb.get_request(request.id)
when = data['when']
addr = data['addr']
fullname = data['fullname']
passwd = data['passwd']
digest = data['digest']
lang = data['lang']
if fullname:
if isinstance(fullname, unicode):
fullname = fullname.encode(lcset, 'replace')
fullname = ' (%s)' % fullname
pending.append(' %s%s %s' % (addr, fullname, time.ctime(when)))
first = True
for request in requestsdb.of_type(RequestType.held_message):
if first:
pending.append(_('\nPending posts:'))
first = False
key, data = requestsdb.get_request(request.id)
when = data['when']
sender = data['sender']
subject = data['subject']
reason = data['reason']
text = data['text']
msgdata = data['msgdata']
subject = Utils.oneline(subject, lcset)
date = time.ctime(when)
reason = _(reason)
pending.append(_("""\
From: $sender on $date
Subject: $subject
Cause: $reason"""))
pending.append('')
# Coerce all items in pending to a Unicode so we can join them
upending = []
charset = mlist.preferred_language.charset
for s in pending:
if isinstance(s, unicode):
upending.append(s)
else:
upending.append(unicode(s, charset, 'replace'))
# Make sure that the text we return from here can be encoded to a byte
# string in the charset of the list's language. This could fail if for
# example, the request was pended while the list's language was French,
# but then it was changed to English before checkdbs ran.
text = NL.join(upending)
charset = Charset(mlist.preferred_language.charset)
incodec = charset.input_codec or 'ascii'
outcodec = charset.output_codec or 'ascii'
if isinstance(text, unicode):
return text.encode(outcodec, 'replace')
# Be sure this is a byte string encodeable in the list's charset
utext = unicode(text, incodec, 'replace')
return utext.encode(outcodec, 'replace')
示例4: TestRequests
# 需要导入模块: from mailman.interfaces.requests import IListRequests [as 别名]
# 或者: from mailman.interfaces.requests.IListRequests import of_type [as 别名]
class TestRequests(unittest.TestCase):
layer = ConfigLayer
def setUp(self):
self._mlist = create_list('[email protected]')
self._requests_db = IListRequests(self._mlist)
self._msg = mfs("""\
From: [email protected]
To: [email protected]
Subject: Something
Message-ID: <alpha>
Something else.
""")
def test_get_request_with_type(self):
# get_request() takes an optional request type.
request_id = hold_message(self._mlist, self._msg)
# Submit a request with a non-matching type. This should return None
# as if there were no matches.
response = self._requests_db.get_request(
request_id, RequestType.subscription)
self.assertEqual(response, None)
# Submit the same request with a matching type.
key, data = self._requests_db.get_request(
request_id, RequestType.held_message)
self.assertEqual(key, '<alpha>')
# It should also succeed with no optional request type given.
key, data = self._requests_db.get_request(request_id)
self.assertEqual(key, '<alpha>')
def test_hold_with_bogus_type(self):
# Calling hold_request() with a bogus request type is an error.
with self.assertRaises(TypeError) as cm:
self._requests_db.hold_request(5, 'foo')
self.assertEqual(cm.exception.args[0], 5)
def test_delete_missing_request(self):
# Trying to delete a missing request is an error.
with self.assertRaises(KeyError) as cm:
self._requests_db.delete_request(801)
self.assertEqual(cm.exception.args[0], 801)
def test_only_return_this_lists_requests(self):
# Issue #161: get_requests() returns requests that are not specific to
# the mailing list in question.
request_id = hold_message(self._mlist, self._msg)
bee = create_list('[email protected]')
self.assertIsNone(IListRequests(bee).get_request(request_id))
def test_request_order(self):
# Requests must be sorted in creation order.
#
# This test only "works" for PostgreSQL, in the sense that if you
# remove the fix in ../requests.py, it will still pass in SQLite.
# Apparently SQLite auto-sorts results by ID but PostgreSQL autosorts
# by insertion time. It's still worth keeping the test to prevent
# regressions.
#
# We modify the auto-incremented ids by listening to SQLAlchemy's
# flush event, and hacking all the _Request object id's to the next
# value in a descending counter.
request_ids = []
counter = count(200, -1)
def id_hacker(session, flush_context, instances): # noqa
for instance in session.new:
if isinstance(instance, _Request):
instance.id = next(counter)
with before_flush(id_hacker):
for index in range(10):
msg = mfs(self._msg.as_string())
msg.replace_header('Message-ID', '<alpha{}>'.format(index))
request_ids.append(hold_message(self._mlist, msg))
config.db.store.flush()
# Make sure that our ID are not already sorted.
self.assertNotEqual(request_ids, sorted(request_ids))
# Get requests and check their order.
requests = self._requests_db.of_type(RequestType.held_message)
self.assertEqual([r.id for r in requests], sorted(request_ids))