本文整理汇总了Python中mailman.interfaces.requests.IListRequests.get_request方法的典型用法代码示例。如果您正苦于以下问题:Python IListRequests.get_request方法的具体用法?Python IListRequests.get_request怎么用?Python IListRequests.get_request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mailman.interfaces.requests.IListRequests
的用法示例。
在下文中一共展示了IListRequests.get_request方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle_unsubscription
# 需要导入模块: from mailman.interfaces.requests import IListRequests [as 别名]
# 或者: from mailman.interfaces.requests.IListRequests import get_request [as 别名]
def handle_unsubscription(mlist, id, action, comment=None):
requestdb = IListRequests(mlist)
key, data = requestdb.get_request(id)
address = data['address']
if action is Action.defer:
# Nothing to do.
return
elif action is Action.discard:
# Nothing to do except delete the request from the database.
pass
elif action is Action.reject:
key, data = requestdb.get_request(id)
_refuse(mlist, _('Unsubscription request'), address,
comment or _('[No reason given]'))
elif action is Action.accept:
key, data = requestdb.get_request(id)
try:
delete_member(mlist, address)
except NotAMemberError:
# User has already been unsubscribed.
pass
slog.info('%s: deleted %s', mlist.fqdn_listname, address)
else:
raise AssertionError('Unexpected action: {0}'.format(action))
# Delete the request from the database.
requestdb.delete_request(id)
示例2: test_hold_action_alias_for_defer
# 需要导入模块: from mailman.interfaces.requests import IListRequests [as 别名]
# 或者: from mailman.interfaces.requests.IListRequests import get_request [as 别名]
def test_hold_action_alias_for_defer(self):
# In handle_message(), the 'hold' action is the same as 'defer' for
# purposes of this API.
request_id = hold_message(self._mlist, self._msg)
handle_message(self._mlist, request_id, Action.defer)
# The message is still in the pending requests.
requests_db = IListRequests(self._mlist)
key, data = requests_db.get_request(request_id)
self.assertEqual(key, '<alpha>')
handle_message(self._mlist, request_id, Action.hold)
key, data = requests_db.get_request(request_id)
self.assertEqual(key, '<alpha>')
示例3: TestRequests
# 需要导入模块: from mailman.interfaces.requests import IListRequests [as 别名]
# 或者: from mailman.interfaces.requests.IListRequests import get_request [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))
示例4: test_get_request_with_type
# 需要导入模块: from mailman.interfaces.requests import IListRequests [as 别名]
# 或者: from mailman.interfaces.requests.IListRequests import get_request [as 别名]
def test_get_request_with_type(self):
# get_request() takes an optional request type.
request_id = hold_message(self._mlist, self._msg)
requests_db = IListRequests(self._mlist)
# Submit a request with a non-matching type. This should return None
# as if there were no matches.
response = requests_db.get_request(
request_id, RequestType.subscription)
self.assertEqual(response, None)
# Submit the same request with a matching type.
key, data = 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 = requests_db.get_request(request_id)
self.assertEqual(key, '<alpha>')
示例5: _make_resource
# 需要导入模块: from mailman.interfaces.requests import IListRequests [as 别名]
# 或者: from mailman.interfaces.requests.IListRequests import get_request [as 别名]
def _make_resource(self, request_id):
requests = IListRequests(self._mlist)
results = requests.get_request(request_id)
if results is None:
return None
key, data = results
resource = dict(key=key, request_id=request_id)
# Flatten the IRequest payload into the JSON representation.
if data is not None:
resource.update(data)
# Check for a matching request type, and insert the type name into the
# resource.
try:
request_type = RequestType[resource.pop('_request_type', None)]
except KeyError:
request_type = None
if request_type is not RequestType.held_message:
return None
resource['type'] = RequestType.held_message.name
# This key isn't what you think it is. Usually, it's the Pendable
# record's row id, which isn't helpful at all. If it's not there,
# that's fine too.
resource.pop('id', None)
# Add a self_link.
resource['self_link'] = self.api.path_to(
'lists/{}/held/{}'.format(self._mlist.list_id, request_id))
return resource
示例6: on_post
# 需要导入模块: from mailman.interfaces.requests import IListRequests [as 别名]
# 或者: from mailman.interfaces.requests.IListRequests import get_request [as 别名]
def on_post(self, request, response):
try:
validator = Validator(action=enum_validator(Action))
arguments = validator(request)
except ValueError as error:
bad_request(response, str(error))
return
requests = IListRequests(self._mlist)
try:
request_id = int(self._request_id)
except ValueError:
bad_request(response)
return
results = requests.get_request(request_id)
if results is None:
not_found(response)
return
key, data = results
try:
request_type = RequestType[data['_request_type']]
except ValueError:
bad_request(response)
return
if request_type is RequestType.subscription:
handle_subscription(self._mlist, request_id, **arguments)
elif request_type is RequestType.unsubscription:
handle_unsubscription(self._mlist, request_id, **arguments)
else:
bad_request(response)
return
no_content(response)
示例7: moderate
# 需要导入模块: from mailman.interfaces.requests import IListRequests [as 别名]
# 或者: from mailman.interfaces.requests.IListRequests import get_request [as 别名]
def moderate(self, request):
try:
validator = Validator(action=enum_validator(Action))
arguments = validator(request)
except ValueError as error:
return http.bad_request([], str(error))
requests = IListRequests(self._mlist)
try:
request_id = int(self._request_id)
except ValueError:
return http.bad_request()
results = requests.get_request(request_id)
if results is None:
return http.not_found()
key, data = results
try:
request_type = RequestType(data['_request_type'])
except ValueError:
return http.bad_request()
if request_type is RequestType.subscription:
handle_subscription(self._mlist, request_id, **arguments)
elif request_type is RequestType.unsubscription:
handle_unsubscription(self._mlist, request_id, **arguments)
else:
return http.bad_request()
return no_content()
示例8: test_lp_1031391
# 需要导入模块: from mailman.interfaces.requests import IListRequests [as 别名]
# 或者: from mailman.interfaces.requests.IListRequests import get_request [as 别名]
def test_lp_1031391(self):
# LP: #1031391 msgdata['received_time'] gets added by the LMTP server.
# The value is a datetime. If this message gets held, it will break
# pending requests since they require string keys and values.
received_time = now()
msgdata = dict(received_time=received_time)
request_id = hold_message(self._mlist, self._msg, msgdata)
requests_db = IListRequests(self._mlist)
key, data = requests_db.get_request(request_id)
self.assertEqual(data['received_time'], received_time)
示例9: handle_subscription
# 需要导入模块: from mailman.interfaces.requests import IListRequests [as 别名]
# 或者: from mailman.interfaces.requests.IListRequests import get_request [as 别名]
def handle_subscription(mlist, id, action, comment=None):
requestdb = IListRequests(mlist)
if action is Action.defer:
# Nothing to do.
return
elif action is Action.discard:
# Nothing to do except delete the request from the database.
pass
elif action is Action.reject:
key, data = requestdb.get_request(id)
_refuse(mlist, _('Subscription request'),
data['address'],
comment or _('[No reason given]'),
lang=getUtility(ILanguageManager)[data['language']])
elif action is Action.accept:
key, data = requestdb.get_request(id)
enum_value = data['delivery_mode'].split('.')[-1]
delivery_mode = DeliveryMode(enum_value)
address = data['address']
display_name = data['display_name']
language = getUtility(ILanguageManager)[data['language']]
password = data['password']
try:
add_member(mlist, address, display_name, password,
delivery_mode, language)
except AlreadySubscribedError:
# The address got subscribed in some other way after the original
# request was made and accepted.
pass
else:
if mlist.send_welcome_message:
send_welcome_message(mlist, address, language, delivery_mode)
if mlist.admin_notify_mchanges:
send_admin_subscription_notice(
mlist, address, display_name, language)
slog.info('%s: new %s, %s %s', mlist.fqdn_listname,
delivery_mode, formataddr((display_name, address)),
'via admin approval')
else:
raise AssertionError('Unexpected action: {0}'.format(action))
# Delete the request from the database.
requestdb.delete_request(id)
示例10: auto_discard
# 需要导入模块: from mailman.interfaces.requests import IListRequests [as 别名]
# 或者: from mailman.interfaces.requests.IListRequests import get_request [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
示例11: handle_subscription
# 需要导入模块: from mailman.interfaces.requests import IListRequests [as 别名]
# 或者: from mailman.interfaces.requests.IListRequests import get_request [as 别名]
def handle_subscription(mlist, id, action, comment=None):
requestdb = IListRequests(mlist)
if action is Action.defer:
# Nothing to do.
return
elif action is Action.discard:
# Nothing to do except delete the request from the database.
pass
elif action is Action.reject:
key, data = requestdb.get_request(id)
send_rejection(
mlist, _('Subscription request'),
data['email'],
comment or _('[No reason given]'),
lang=getUtility(ILanguageManager)[data['language']])
elif action is Action.accept:
key, data = requestdb.get_request(id)
delivery_mode = DeliveryMode[data['delivery_mode']]
email = data['email']
display_name = data['display_name']
language = getUtility(ILanguageManager)[data['language']]
try:
add_member(
mlist,
RequestRecord(email, display_name, delivery_mode, language))
except AlreadySubscribedError:
# The address got subscribed in some other way after the original
# request was made and accepted.
pass
slog.info('%s: new %s, %s %s', mlist.fqdn_listname,
delivery_mode, formataddr((display_name, email)),
'via admin approval')
else:
raise AssertionError('Unexpected action: {0}'.format(action))
# Delete the request from the database.
requestdb.delete_request(id)
示例12: details
# 需要导入模块: from mailman.interfaces.requests import IListRequests [as 别名]
# 或者: from mailman.interfaces.requests.IListRequests import get_request [as 别名]
def details(self, request):
requests = IListRequests(self._mlist)
try:
request_id = int(self._request_id)
except ValueError:
return http.bad_request()
results = requests.get_request(request_id, RequestType.held_message)
if results is None:
return http.not_found()
key, data = results
msg = getUtility(IMessageStore).get_message_by_id(key)
resource = dict(
key=key,
data=data,
msg=msg.as_string(),
id=request_id,
)
return http.ok([], etag(resource))
示例13: on_post
# 需要导入模块: from mailman.interfaces.requests import IListRequests [as 别名]
# 或者: from mailman.interfaces.requests.IListRequests import get_request [as 别名]
def on_post(self, request, response):
try:
validator = Validator(action=enum_validator(Action))
arguments = validator(request)
except ValueError as error:
bad_request(response, str(error))
return
requests = IListRequests(self._mlist)
try:
request_id = int(self._request_id)
except ValueError:
bad_request(response)
return
results = requests.get_request(request_id, RequestType.held_message)
if results is None:
not_found(response)
else:
handle_message(self._mlist, request_id, **arguments)
no_content(response)
示例14: _make_resource
# 需要导入模块: from mailman.interfaces.requests import IListRequests [as 别名]
# 或者: from mailman.interfaces.requests.IListRequests import get_request [as 别名]
def _make_resource(self, request_id, expected_request_types):
requests = IListRequests(self._mlist)
results = requests.get_request(request_id)
if results is None:
return None
key, data = results
resource = dict(key=key, request_id=request_id)
# Flatten the IRequest payload into the JSON representation.
resource.update(data)
# Check for a matching request type, and insert the type name into the
# resource.
request_type = RequestType(resource.pop('_request_type'))
if request_type not in expected_request_types:
return None
resource['type'] = request_type.name
# This key isn't what you think it is. Usually, it's the Pendable
# record's row id, which isn't helpful at all. If it's not there,
# that's fine too.
resource.pop('id', None)
return resource
示例15: test_requests_are_deleted_when_mailing_list_is_deleted
# 需要导入模块: from mailman.interfaces.requests import IListRequests [as 别名]
# 或者: from mailman.interfaces.requests.IListRequests import get_request [as 别名]
def test_requests_are_deleted_when_mailing_list_is_deleted(self):
# When a mailing list is deleted, its requests database is deleted
# too, e.g. all its message hold requests (but not the messages
# themselves).
msg = specialized_message_from_string("""\
From: [email protected]
To: [email protected]
Subject: Hold me
Message-ID: <argon>
""")
request_id = hold_message(self._ant, msg)
getUtility(IListManager).delete(self._ant)
# This is a hack. ListRequests don't access self._mailinglist in
# their get_request() method.
requestsdb = IListRequests(self._bee)
request = requestsdb.get_request(request_id)
self.assertEqual(request, None)
saved_message = getUtility(IMessageStore).get_message_by_id('<argon>')
self.assertEqual(saved_message.as_string(), msg.as_string())