当前位置: 首页>>代码示例>>Python>>正文


Python requests.IListRequests类代码示例

本文整理汇总了Python中mailman.interfaces.requests.IListRequests的典型用法代码示例。如果您正苦于以下问题:Python IListRequests类的具体用法?Python IListRequests怎么用?Python IListRequests使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了IListRequests类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: moderate

 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()
开发者ID:aregee,项目名称:Mailman,代码行数:26,代码来源:moderation.py

示例2: hold_subscription

def hold_subscription(mlist, address, display_name, password, mode, language):
    data = dict(when=now().isoformat(),
                address=address,
                display_name=display_name,
                password=password,
                delivery_mode=mode.name,
                language=language)
    # Now hold this request.  We'll use the address as the key.
    requestsdb = IListRequests(mlist)
    request_id = requestsdb.hold_request(
        RequestType.subscription, address, data)
    vlog.info('%s: held subscription request from %s',
              mlist.fqdn_listname, address)
    # Possibly notify the administrator in default list language
    if mlist.admin_immed_notify:
        subject = _(
            'New subscription request to $mlist.display_name from $address')
        text = make('subauth.txt',
                    mailing_list=mlist,
                    username=address,
                    listname=mlist.fqdn_listname,
                    admindb_url=mlist.script_url('admindb'),
                    )
        # This message should appear to come from the <list>-owner so as
        # to avoid any useless bounce processing.
        msg = UserNotification(
            mlist.owner_address, mlist.owner_address,
            subject, text, mlist.preferred_language)
        msg.send(mlist, tomoderators=True)
    return request_id
开发者ID:adam-iris,项目名称:mailman,代码行数:30,代码来源:moderator.py

示例3: _make_resource

 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
开发者ID:maxking,项目名称:mailman,代码行数:27,代码来源:post_moderation.py

示例4: on_post

 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)
开发者ID:adam-iris,项目名称:mailman,代码行数:31,代码来源:moderation.py

示例5: test_request_is_not_held_message

 def test_request_is_not_held_message(self):
     requests = IListRequests(self._mlist)
     with transaction():
         request_id = requests.hold_request(RequestType.subscription, 'foo')
     with self.assertRaises(HTTPError) as cm:
         call_api('http://localhost:9001/3.0/lists/ant.example.com'
                  '/held/{}'.format(request_id))
     self.assertEqual(cm.exception.code, 404)
开发者ID:aswinpj,项目名称:Mailman,代码行数:8,代码来源:test_moderation.py

示例6: _get_collection

 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
开发者ID:aregee,项目名称:Mailman,代码行数:8,代码来源:moderation.py

示例7: handle_ListDeletingEvent

def handle_ListDeletingEvent(event):
    if not isinstance(event, ListDeletingEvent):
        return
    # Get the held requests database for the mailing list.  Since the mailing
    # list is about to get deleted, we can delete all associated requests.
    requestsdb = IListRequests(event.mailing_list)
    for request in requestsdb.held_requests:
        requestsdb.delete_request(request.id)
开发者ID:adam-iris,项目名称:mailman,代码行数:8,代码来源:moderator.py

示例8: test_lp_1031391

 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)
开发者ID:bksim,项目名称:mailman,代码行数:10,代码来源:test_moderation.py

示例9: test_hold_action_alias_for_defer

 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>')
开发者ID:bksim,项目名称:mailman,代码行数:12,代码来源:test_moderation.py

示例10: auto_discard

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
开发者ID:aregee,项目名称:Mailman,代码行数:14,代码来源:checkdbs.py

示例11: test_get_request_with_type

 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>')
开发者ID:bksim,项目名称:mailman,代码行数:16,代码来源:test_requests.py

示例12: details

 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))
开发者ID:bksim,项目名称:mailman,代码行数:18,代码来源:moderation.py

示例13: hold_message

def hold_message(mlist, msg, msgdata=None, reason=None):
    """Hold a message for moderator approval.

    The message is added to the mailing list's request database.

    :param mlist: The mailing list to hold the message on.
    :param msg: The message to hold.
    :param msgdata: Optional message metadata to hold.  If not given, a new
        metadata dictionary is created and held with the message.
    :param reason: Optional string reason why the message is being held.  If
        not given, the empty string is used.
    :return: An id used to handle the held message later.
    """
    if msgdata is None:
        msgdata = {}
    else:
        # Make a copy of msgdata so that subsequent changes won't corrupt the
        # request database.  TBD: remove the `filebase' key since this will
        # not be relevant when the message is resurrected.
        msgdata = msgdata.copy()
    if reason is None:
        reason = ''
    # Add the message to the message store.  It is required to have a
    # Message-ID header.
    message_id = msg.get('message-id')
    if message_id is None:
        msg['Message-ID'] = message_id = unicode(make_msgid())
    assert isinstance(message_id, unicode), (
        'Message-ID is not a unicode: %s' % message_id)
    getUtility(IMessageStore).add(msg)
    # Prepare the message metadata with some extra information needed only by
    # the moderation interface.
    msgdata['_mod_message_id'] = message_id
    msgdata['_mod_fqdn_listname'] = mlist.fqdn_listname
    msgdata['_mod_sender'] = msg.sender
    msgdata['_mod_subject'] = msg.get('subject', _('(no subject)'))
    msgdata['_mod_reason'] = reason
    msgdata['_mod_hold_date'] = now().isoformat()
    # Now hold this request.  We'll use the message_id as the key.
    requestsdb = IListRequests(mlist)
    request_id = requestsdb.hold_request(
        RequestType.held_message, message_id, msgdata)
    return request_id
开发者ID:adam-iris,项目名称:mailman,代码行数:43,代码来源:moderator.py

示例14: on_post

 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)
开发者ID:aditigupta96,项目名称:mailman3,代码行数:19,代码来源:post_moderation.py

示例15: handle_subscription

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)
开发者ID:bksim,项目名称:mailman,代码行数:42,代码来源:moderator.py


注:本文中的mailman.interfaces.requests.IListRequests类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。