• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python http.bad_request函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: patch_membership

    def patch_membership(self, request):
        """Patch the membership.

        This is how subscription changes are done.
        """
        if self._member is None:
            return http.not_found()
        try:
            values = Validator(
                address=unicode,
                delivery_mode=enum_validator(DeliveryMode),
                _optional=('address', 'delivery_mode'))(request)
        except ValueError as error:
            return http.bad_request([], str(error))
        if 'address' in values:
            email = values['address']
            address = getUtility(IUserManager).get_address(email)
            if address is None:
                return http.bad_request([], b'Address not registered')
            try:
                self._member.address = address
            except (MembershipError, UnverifiedAddressError) as error:
                return http.bad_request([], str(error))
        if 'delivery_mode' in values:
            self._member.preferences.delivery_mode = values['delivery_mode']
        return no_content()
开发者ID:bksim,项目名称:mailman,代码行数:26,代码来源:members.py


示例2: create

 def create(self, request):
     """Create a new member."""
     service = getUtility(ISubscriptionService)
     try:
         validator = Validator(
             list_id=unicode,
             subscriber=subscriber_validator,
             display_name=unicode,
             delivery_mode=enum_validator(DeliveryMode),
             role=enum_validator(MemberRole),
             _optional=('delivery_mode', 'display_name', 'role'))
         member = service.join(**validator(request))
     except AlreadySubscribedError:
         return http.conflict([], b'Member already subscribed')
     except NoSuchListError:
         return http.bad_request([], b'No such list')
     except InvalidEmailAddressError:
         return http.bad_request([], b'Invalid email address')
     except ValueError as error:
         return http.bad_request([], str(error))
     # The member_id are UUIDs.  We need to use the integer equivalent in
     # the URL.
     member_id = member.member_id.int
     location = path_to('members/{0}'.format(member_id))
     # Include no extra headers or body.
     return http.created(location, [], None)
开发者ID:bksim,项目名称:mailman,代码行数:26,代码来源:members.py


示例3: 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


示例4: create

 def create(self, request):
     """Create a new user."""
     try:
         validator = Validator(email=unicode,
                               display_name=unicode,
                               password=unicode,
                               _optional=('display_name', 'password'))
         arguments = validator(request)
     except ValueError as error:
         return http.bad_request([], str(error))
     # We can't pass the 'password' argument to the user creation method,
     # so strip that out (if it exists), then create the user, adding the
     # password after the fact if successful.
     password = arguments.pop('password', None)
     try:
         user = getUtility(IUserManager).create_user(**arguments)
     except ExistingAddressError as error:
         return http.bad_request([], b'Address already exists {0}'.format(
             error.email))
     if password is None:
         # This will have to be reset since it cannot be retrieved.
         password = generate(int(config.passwords.password_length))
     scheme = lookup(config.passwords.password_scheme.upper())
     user.password = make_secret(password, scheme)
     location = path_to('users/{0}'.format(user.user_id.int))
     return http.created(location, [], None)
开发者ID:kaushikmit,项目名称:mailman,代码行数:26,代码来源:users.py


示例5: test_bad_request

 def test_bad_request(self):
     r = http.bad_request()
     assert r.status.startswith('400')
     assert r.headers['Content-Type'] == 'text/plain'
     assert '400 Bad Request' in r.body
     r = http.bad_request([('Content-Type', 'text/html')], '<p>400 Bad Request</p>')
     assert r.status.startswith('400')
     assert r.headers['Content-Type'] == 'text/html'
     assert r.body == '<p>400 Bad Request</p>'
     exc = http.BadRequestError()
     r = exc.make_response()
     assert r.status.startswith('400')
开发者ID:ish,项目名称:restish,代码行数:12,代码来源:test_http.py


示例6: patch_update

 def patch_update(self, request):
     """Patch the user's configuration (i.e. partial update)."""
     if self._user is None:
         return http.not_found()
     try:
         validator = PatchValidator(request, ATTRIBUTES)
     except UnknownPATCHRequestError as error:
         return http.bad_request(
             [], b'Unknown attribute: {0}'.format(error.attribute))
     except ReadOnlyPATCHRequestError as error:
         return http.bad_request(
             [], b'Read-only attribute: {0}'.format(error.attribute))
     validator.update(self._user, request)
     return no_content()
开发者ID:trevor,项目名称:mailman3,代码行数:14,代码来源:users.py


示例7: system

 def system(self, request, segments):
     """/<api>/system"""
     if len(segments) == 0:
         resource = dict(
             mailman_version=system.mailman_version,
             python_version=system.python_version,
             self_link=path_to('system'),
             )
     elif len(segments) > 1:
         return http.bad_request()
     elif segments[0] == 'preferences':
         return ReadOnlyPreferences(system_preferences, 'system'), []
     else:
         return http.bad_request()
     return http.ok([], etag(resource))
开发者ID:bksim,项目名称:mailman,代码行数:15,代码来源:root.py


示例8: patch_configuration

 def patch_configuration(self, request):
     """Patch the configuration (i.e. partial update)."""
     try:
         validator = PatchValidator(request, ATTRIBUTES)
     except UnknownPATCHRequestError as error:
         return http.bad_request(
             [], b'Unknown attribute: {0}'.format(error.attribute))
     except ReadOnlyPATCHRequestError as error:
         return http.bad_request(
             [], b'Read-only attribute: {0}'.format(error.attribute))
     try:
         validator.update(self._mlist, request)
     except ValueError as error:
         return http.bad_request([], str(error))
     return no_content()
开发者ID:trevor,项目名称:mailman3,代码行数:15,代码来源:configuration.py


示例9: create

 def create(self, request):
     """Create a new mailing list."""
     try:
         validator = Validator(fqdn_listname=unicode)
         mlist = create_list(**validator(request))
     except ListAlreadyExistsError:
         return http.bad_request([], b'Mailing list exists')
     except BadDomainSpecificationError as error:
         return http.bad_request([], b'Domain does not exist {0}'.format(
             error.domain))
     except ValueError as error:
         return http.bad_request([], str(error))
     # wsgiref wants headers to be bytes, not unicodes.
     location = path_to('lists/{0}'.format(mlist.fqdn_listname))
     # Include no extra headers or body.
     return http.created(location, [], None)
开发者ID:bksim,项目名称:mailman,代码行数:16,代码来源:lists.py


示例10: locate_resource

 def locate_resource(self, request):
     """
     Locate the resource at the path in request URL by traversing the
     resource hierarchy.
     """
     # Calculate the path segments relative to the application,
     # special-casing requests for the the root segment (because we already
     # have a reference to the root resource).
     try:
         segments = url.split_path(request.environ['PATH_INFO'])
     except UnicodeDecodeError:
         return http.bad_request()
     if segments == ['']:
         segments = []
     # Recurse into the resource hierarchy until we run out of segments or
     # find a Response.
     resource = self.root
     while segments and not isinstance(resource, http.Response):
         resource_child = getattr(resource, 'resource_child', None)
         # No resource_child method? 404.
         if resource_child is None:
             raise http.NotFoundError()
         result = resource_child(request, segments)
         # No result returned? 404.
         if result is None:
             raise http.NotFoundError()
         # Either a (resource, remaining segments) tuple or an object to
         # forward the lookup to is acceptable.
         if isinstance(result, tuple):
             resource, segments = result
         else:
             resource = result
     return resource
开发者ID:ish,项目名称:restish,代码行数:33,代码来源:app.py


示例11: put_update

 def put_update(self, request):
     """Put the user's configuration (i.e. full update)."""
     if self._user is None:
         return http.not_found()
     validator = Validator(**ATTRIBUTES)
     try:
         validator.update(self._user, request)
     except UnknownPATCHRequestError as error:
         return http.bad_request(
             [], b'Unknown attribute: {0}'.format(error.attribute))
     except ReadOnlyPATCHRequestError as error:
         return http.bad_request(
             [], b'Read-only attribute: {0}'.format(error.attribute))
     except ValueError as error:
         return http.bad_request([], str(error))
     return no_content()
开发者ID:trevor,项目名称:mailman3,代码行数:16,代码来源:users.py


示例12: memberships

 def memberships(self, request, segments):
     """/addresses/<email>/memberships"""
     if len(segments) != 0:
         return http.bad_request()
     if self._address is None:
         return http.not_found()
     return AddressMemberships(self._address)
开发者ID:trevor,项目名称:mailman3,代码行数:7,代码来源:addresses.py


示例13: patch_configuration

 def patch_configuration(self, request):
     """Patch the configuration (i.e. partial update)."""
     # Validate only the partial subset of attributes given in the request.
     validationators = {}
     for attribute in request.PATCH:
         if attribute not in ATTRIBUTES:
             return http.bad_request([], b"Unknown attribute: {0}".format(attribute))
         elif ATTRIBUTES[attribute].decoder is None:
             return http.bad_request([], b"Read-only attribute: {0}".format(attribute))
         else:
             validationators[attribute] = VALIDATORS[attribute]
     validator = Validator(**validationators)
     try:
         self._set_writable_attributes(validator, request)
     except ValueError as error:
         return http.bad_request([], str(error))
     return no_content()
开发者ID:mousadialo,项目名称:mailman,代码行数:17,代码来源:configuration.py


示例14: unverify

 def unverify(self, request, segments):
     """/addresses/<email>/verify"""
     if len(segments) != 0:
         return http.bad_request()
     if self._address is None:
         return http.not_found()
     child = _VerifyResource(self._address, 'unverify')
     return child, []
开发者ID:trevor,项目名称:mailman3,代码行数:8,代码来源:addresses.py


示例15: details

 def details(self, request):
     try:
         request_id = int(self._request_id)
     except ValueError:
         return http.bad_request()
     resource = self._make_resource(request_id)
     if resource is None:
         return http.not_found()
     return http.ok([], etag(resource))
开发者ID:aregee,项目名称:Mailman,代码行数:9,代码来源:moderation.py


示例16: create

 def create(self, request):
     """Create a new domain."""
     domain_manager = getUtility(IDomainManager)
     try:
         validator = Validator(mail_host=unicode,
                               description=unicode,
                               base_url=unicode,
                               contact_address=unicode,
                               _optional=('description', 'base_url',
                                          'contact_address'))
         domain = domain_manager.add(**validator(request))
     except BadDomainSpecificationError:
         return http.bad_request([], b'Domain exists')
     except ValueError as error:
         return http.bad_request([], str(error))
     location = path_to('domains/{0}'.format(domain.mail_host))
     # Include no extra headers or body.
     return http.created(location, [], None)
开发者ID:aregee,项目名称:Mailman,代码行数:18,代码来源:domains.py


示例17: lists

 def lists(self, request, segments):
     """/domains/<domain>/lists"""
     if len(segments) == 0:
         domain = getUtility(IDomainManager).get(self._domain)
         if domain is None:
             return http.not_found()
         return ListsForDomain(domain)
     else:
         return http.bad_request()
开发者ID:aregee,项目名称:Mailman,代码行数:9,代码来源:domains.py


示例18: wrapper

 def wrapper(self, request, *args, **kwargs):
     try:
         count = int(request.GET['count'])
         page = int(request.GET['page'])
         if count < 0 or page < 0:
             return http.bad_request([], b'Invalid parameters')
     # Wrong parameter types or no GET attribute in request object.
     except (AttributeError, ValueError, TypeError):
         return http.bad_request([], b'Invalid parameters')
     # No count/page params.
     except KeyError:
         count = page = None
     result = method(self, request, *args, **kwargs)
     if count is None and page is None:
         return result
     list_start = int((page - 1) * count)
     list_end = int(page * count)
     return result[list_start:list_end]
开发者ID:trevor,项目名称:mailman3,代码行数:18,代码来源:helpers.py


示例19: preferences

 def preferences(self, request, segments):
     """/members/<id>/preferences"""
     if len(segments) != 0:
         return http.bad_request()
     if self._member is None:
         return http.not_found()
     child = Preferences(
         self._member.preferences,
         'members/{0}'.format(self._member.member_id.int))
     return child, []
开发者ID:bksim,项目名称:mailman,代码行数:10,代码来源:members.py


示例20: preferences

 def preferences(self, request, segments):
     """/addresses/<email>/preferences"""
     if len(segments) != 0:
         return http.bad_request()
     if self._user is None:
         return http.not_found()
     child = Preferences(
         self._user.preferences,
         'users/{0}'.format(self._user.user_id.int))
     return child, []
开发者ID:kaushikmit,项目名称:mailman,代码行数:10,代码来源:users.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python http.not_found函数代码示例发布时间:2022-05-26
下一篇:
Python restfulie.Restfulie类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap