def validate_delete_request(self, web, section): h = HttpHeaders() # map the headers to standard http mapped_headers = self._map_webpy_headers(web.ctx.environ) ssslog.debug("Validating on header dictionary: " + str(mapped_headers)) try: # now validate the http headers h.validate(mapped_headers, section) except ValidationError as e: raise SwordError(error_uri=Errors.bad_request, msg=e.message)
def validate_deposit_request(self, web, entry_section=None, binary_section=None, multipart_section=None, empty_section=None, allow_multipart=True, allow_empty=False): h = HttpHeaders() # map the headers to standard http mapped_headers = self._map_webpy_headers(web.ctx.environ) ssslog.debug("Validating on header dictionary: " + str(mapped_headers)) # run the validation try: # there must be both an "atom" and "payload" input or data in web.data() webin = web.input() if len(webin) != 2 and len(webin) > 0: raise ValidationException("Multipart request does not contain exactly 2 parts") if len(webin) >= 2 and not webin.has_key("atom") and not webin.has_key("payload"): raise ValidationException("Multipart request must contain Content-Dispositions with names 'atom' and 'payload'") if len(webin) > 0 and not allow_multipart: raise ValidationException("Multipart request not permitted in this context") # if we get to here then we have a valid multipart or no multipart is_multipart = False is_empty = False if len(webin) != 2: # if it is not multipart if web.data() is None or web.data().strip() == "": # FIXME: this does not look safe to scale if allow_empty: ssslog.info("Validating an empty deposit (could be a control operation)") is_empty = True else: raise ValidationException("No content sent to the server") else: ssslog.info("Validating a multipart deposit") is_multipart = True is_entry = False content_type = mapped_headers.get("CONTENT-TYPE") if content_type is not None and content_type.startswith("application/atom+xml"): ssslog.info("Validating an atom-only deposit") is_entry = True if not is_entry and not is_multipart and not is_empty: ssslog.info("Validating a binary deposit") section = entry_section if is_entry else multipart_section if is_multipart else empty_section if is_empty else binary_section # now validate the http headers h.validate(mapped_headers, section) except ValidationException as e: raise SwordError(error_uri=Errors.bad_request, msg=e.message)
def validate_deposit_request(self, entry_section=None, binary_section=None, multipart_section=None, empty_section=None, allow_multipart=True, allow_empty=False): h = HttpHeaders() # map the headers to standard http mapped_headers = self._map_webpy_headers(request.environ) ssslog.debug("Validating on header dictionary: " + str(mapped_headers)) # run the validation try: # there must be both an "atom" and "payload" input or data in web.data() # FIXME: deposit does NOT support multipart if request.environ["CONTENT_TYPE"].startswith("multipart"): raise SwordError( error_uri=Errors.method_not_allowed, msg= "Pylons implementation does not currently support multipart/related requests" ) """ # leave this out until we can get multipart sorted (at a later date) webin = request.POST if len(webin) != 2 and len(webin) > 0: raise ValidationException("Multipart request does not contain exactly 2 parts") if len(webin) >= 2 and not webin.has_key("atom") and not webin.has_key("payload"): raise ValidationException("Multipart request must contain Content-Dispositions with names 'atom' and 'payload'") if len(webin) > 0 and not allow_multipart: raise ValidationException("Multipart request not permitted in this context") """ # if we get to here then we have a valid multipart or no multipart is_multipart = False is_empty = False #if len(webin) != 2: # if it is not multipart # FIXME: this is reading everything in, and should be re-evaluated for performance/scalability # wsgi_input = request.environ['wsgi.input'] f = request.body_file f.seek(0, 0) # FIXME: can't we just look at the Content-Type header???? # read a byte in, to see if the body is empty if f is not None: byte = f.read(1) if byte == "" and allow_empty: ssslog.debug( "first byte of deposit request is the empty string") is_empty = True else: ssslog.debug("first byte of deposit request is \"" + str(byte) + "\" ... not an empty request") f.seek(0, 0) else: is_empty = True # validate whether we allow an empty deposit if is_empty and not allow_empty: raise ValidationException("No content sent to the server") elif is_empty and allow_empty: ssslog.info( "Validating an empty deposit (could be a control operation)" ) #else: # ssslog.info("Validating a multipart deposit") # is_multipart = True is_entry = False content_type = mapped_headers.get("CONTENT-TYPE") if content_type is not None and content_type.startswith( "application/atom+xml"): ssslog.info("Validating an atom-only deposit") is_entry = True if not is_entry and not is_multipart and not is_empty: ssslog.info("Validating a binary deposit") section = entry_section if is_entry else multipart_section if is_multipart else empty_section if is_empty else binary_section # now validate the http headers h.validate(mapped_headers, section) except ValidationException as e: raise SwordError(error_uri=Errors.bad_request, msg=e.message)
def validate_deposit_request(self, entry_section=None, binary_section=None, multipart_section=None, empty_section=None, allow_multipart=True, allow_empty=False): h = HttpHeaders() # map the headers to standard http mapped_headers = self._map_webpy_headers(request.environ) ssslog.debug("Validating on header dictionary: " + str(mapped_headers)) # run the validation try: # there must be both an "atom" and "payload" input or data in web.data() # FIXME: deposit does NOT support multipart if request.environ["CONTENT_TYPE"].startswith("multipart"): raise SwordError(error_uri=Errors.method_not_allowed, msg="Pylons implementation does not currently support multipart/related requests") """ # leave this out until we can get multipart sorted (at a later date) webin = request.POST if len(webin) != 2 and len(webin) > 0: raise ValidationException("Multipart request does not contain exactly 2 parts") if len(webin) >= 2 and not webin.has_key("atom") and not webin.has_key("payload"): raise ValidationException("Multipart request must contain Content-Dispositions with names 'atom' and 'payload'") if len(webin) > 0 and not allow_multipart: raise ValidationException("Multipart request not permitted in this context") """ # if we get to here then we have a valid multipart or no multipart is_multipart = False is_empty = False #if len(webin) != 2: # if it is not multipart # FIXME: this is reading everything in, and should be re-evaluated for performance/scalability # wsgi_input = request.environ['wsgi.input'] f = request.body_file f.seek(0, 0) # FIXME: can't we just look at the Content-Type header???? # read a byte in, to see if the body is empty if f is not None: byte = f.read(1) if byte == "" and allow_empty: ssslog.debug("first byte of deposit request is the empty string") is_empty = True else: ssslog.debug("first byte of deposit request is \"" + str(byte) + "\" ... not an empty request") f.seek(0, 0) else: is_empty = True # validate whether we allow an empty deposit if is_empty and not allow_empty: raise ValidationException("No content sent to the server") elif is_empty and allow_empty: ssslog.info("Validating an empty deposit (could be a control operation)") #else: # ssslog.info("Validating a multipart deposit") # is_multipart = True is_entry = False content_type = mapped_headers.get("CONTENT-TYPE") if content_type is not None and content_type.startswith("application/atom+xml"): ssslog.info("Validating an atom-only deposit") is_entry = True if not is_entry and not is_multipart and not is_empty: ssslog.info("Validating a binary deposit") section = entry_section if is_entry else multipart_section if is_multipart else empty_section if is_empty else binary_section # now validate the http headers h.validate(mapped_headers, section) except ValidationException as e: raise SwordError(error_uri=Errors.bad_request, msg=e.message)