Exemplo n.º 1
0
 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()
Exemplo n.º 2
0
 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()
Exemplo n.º 3
0
 def on_patch(self, request, response):
     """Patch the user's configuration (i.e. partial update)."""
     if self._user is None:
         not_found(response)
         return
     try:
         validator = PatchValidator(request, ATTRIBUTES)
     except UnknownPATCHRequestError as error:
         bad_request(
             response, b'Unknown attribute: {0}'.format(error.attribute))
     except ReadOnlyPATCHRequestError as error:
         bad_request(
             response, b'Read-only attribute: {0}'.format(error.attribute))
     else:
         validator.update(self._user, request)
         no_content(response)
Exemplo n.º 4
0
 def on_patch(self, request, response):
     """Patch the user's configuration (i.e. partial update)."""
     if self._user is None:
         not_found(response)
         return
     try:
         validator = PatchValidator(request, ATTRIBUTES)
     except UnknownPATCHRequestError as error:
         bad_request(
             response, b'Unknown attribute: {0}'.format(error.attribute))
     except ReadOnlyPATCHRequestError as error:
         bad_request(
             response, b'Read-only attribute: {0}'.format(error.attribute))
     else:
         validator.update(self._user, request)
         no_content(response)
Exemplo n.º 5
0
 def on_patch(self, request, response):
     """Patch the configuration (i.e. partial update)."""
     attributes = api_attributes(self.api)
     if self._attribute is None:
         # We're PATCHing one or more of the attributes on the list's
         # configuration resource, so all the writable attributes are valid
         # candidates for updating.
         converters = attributes
     else:
         # We're PATCHing a specific list configuration attribute
         # sub-resource.  Because the request data must be a dictionary, we
         # restrict it to containing only a single key, which must match
         # the attribute name.  First, check for any extra attributes in
         # the request.
         keys = [key for key, value in request.params.items()]
         if len(keys) > 1:
             bad_request(response,
                         'Expected 1 attribute, got {}'.format(len(keys)))
             return
         converter = attributes.get(self._attribute)
         if converter is None:
             # This is the case where the URL points to a nonexisting list
             # configuration attribute sub-resource.
             not_found(response,
                       'Unknown attribute: {}'.format(self._attribute))
             return
         converters = {self._attribute: converter}
     try:
         validator = PatchValidator(request, converters)
     except UnknownPATCHRequestError as error:
         # This is the case where the URL points to the list's entire
         # configuration resource, but the request dictionary contains a
         # nonexistent attribute.
         bad_request(response,
                     'Unknown attribute: {}'.format(error.attribute))
         return
     except ReadOnlyPATCHRequestError as error:
         bad_request(response,
                     'Read-only attribute: {}'.format(error.attribute))
         return
     try:
         validator.update(self._mlist, request)
     except ValueError as error:
         bad_request(response, str(error))
     else:
         no_content(response)
Exemplo n.º 6
0
 def on_patch(self, request, response):
     """Patch the configuration (i.e. partial update)."""
     if self._attribute is None:
         # We're PATCHing one or more of the attributes on the list's
         # configuration resource, so all the writable attributes are valid
         # candidates for updating.
         converters = ATTRIBUTES
     else:
         # We're PATCHing a specific list configuration attribute
         # sub-resource.  Because the request data must be a dictionary, we
         # restrict it to containing only a single key, which must match
         # the attribute name.  First, check for any extra attributes in
         # the request.
         keys = [key for key, value in request.params.items()]
         if len(keys) > 1:
             bad_request(response, 'Expected 1 attribute, got {}'.format(
                 len(keys)))
             return
         converter = ATTRIBUTES.get(self._attribute)
         if converter is None:
             # This is the case where the URL points to a nonexisting list
             # configuration attribute sub-resource.
             not_found(response, 'Unknown attribute: {}'.format(
                 self._attribute))
             return
         converters = {self._attribute: converter}
     try:
         validator = PatchValidator(request, converters)
     except UnknownPATCHRequestError as error:
         # This is the case where the URL points to the list's entire
         # configuration resource, but the request dictionary contains a
         # nonexistent attribute.
         bad_request(
             response, 'Unknown attribute: {}'.format(error.attribute))
         return
     except ReadOnlyPATCHRequestError as error:
         bad_request(
             response, 'Read-only attribute: {}'.format(error.attribute))
         return
     try:
         validator.update(self._mlist, request)
     except ValueError as error:
         bad_request(response, str(error))
     else:
         no_content(response)
Exemplo n.º 7
0
 def on_patch(self, request, response):
     """Patch the configuration (i.e. partial update)."""
     try:
         validator = PatchValidator(request, ATTRIBUTES)
     except UnknownPATCHRequestError as error:
         bad_request(
             response, b'Unknown attribute: {}'.format(error.attribute))
         return
     except ReadOnlyPATCHRequestError as error:
         bad_request(
             response, b'Read-only attribute: {}'.format(error.attribute))
         return
     try:
         validator.update(self._mlist, request)
     except ValueError as error:
         bad_request(response, str(error))
     else:
         no_content(response)
Exemplo n.º 8
0
 def on_patch(self, request, response):
     """Patch the configuration (i.e. partial update)."""
     try:
         validator = PatchValidator(request, ATTRIBUTES)
     except UnknownPATCHRequestError as error:
         bad_request(
             response, b'Unknown attribute: {}'.format(error.attribute))
         return
     except ReadOnlyPATCHRequestError as error:
         bad_request(
             response, b'Read-only attribute: {}'.format(error.attribute))
         return
     try:
         validator.update(self._mlist, request)
     except ValueError as error:
         bad_request(response, str(error))
     else:
         no_content(response)