def get_deposit(self, auth=None, atom_only=False):
        # FIXME: this does not deal with the Media Part headers on a multipart deposit
        """
        Take a request object and extract from it the parameters and content required for a SWORD deposit.  This
        includes determining whether this is an Atom Multipart request or not, and extracting the atom/payload where
        appropriate.  It also includes extracting the HTTP headers which are relevant to deposit, and for those not
        supplied providing their defaults in the returned DepositRequest object
        """
        d = DepositRequest()

        # map the webpy headers to something more standard
        mapped_headers = self._map_webpy_headers(request.environ)

        # get the headers that have been provided.  Any headers which have not been provided will
        # will have default values applied
        h = HttpHeaders()
        d.set_from_headers(h.get_sword_headers(mapped_headers))

        if d.content_type.startswith("application/atom+xml"):
            atom_only = True

        empty_request = False
        if d.content_length == 0:
            ssslog.info("Received empty deposit request")
            empty_request = True
        if config.max_upload_size is not None and d.content_length > config.max_upload_size:
            raise SwordError(
                error_uri=Errors.max_upload_size_exceeded,
                msg="Max upload size is " + str(config.max_upload_size) +
                "; incoming content length was " + str(d.content_length))

        # FIXME: this method does NOT support multipart
        # find out if this is a multipart or not
        is_multipart = False

        # FIXME: these headers aren't populated yet, because the webpy api doesn't
        # appear to have a mechanism to retrieve them.  urgh.
        #entry_part_headers = {}
        #media_part_headers = {}
        #webin = request.POST
        #ssslog.debug(webin)
        #if len(webin) == 2:
        #    ssslog.info("Received multipart deposit request")
        #    d.atom = webin['atom']
        # FIXME: this reads the payload into memory, we need to sort that out
        # read the zip file from the base64 encoded string
        #    d.content = base64.decodestring(webin['payload'])
        #    is_multipart = True
        #elif not empty_request:
        if not empty_request:
            # for this section, we have to reset the file pointer in the body_file
            # part of the request back to the start, since it may have
            # already been read once
            f = request.body_file
            f.seek(0, 0)

            # if this wasn't a multipart, and isn't an empty request, then read the
            # data from the body_file
            if atom_only:
                # we don't worry about scalability here - the entries should be
                # generally small
                ssslog.info("Received Entry deposit request")
                d.atom = f.read()
            else:
                ssslog.info("Received Binary deposit request")
                # FIXME: this is reading everything in, and should be re-evaluated for performance/scalability
                d.content_file = f

        if is_multipart:
            d.filename = h.extract_filename(media_part_headers)
        else:
            d.filename = h.extract_filename(mapped_headers)

        # now just attach the authentication data and return
        d.auth = auth
        return d
Example #2
0
 def get_deposit(self, web, auth=None, atom_only=False):
     # FIXME: this reads files into memory, and therefore does not scale
     # FIXME: this does not deal with the Media Part headers on a multipart deposit
     """
     Take a web.py web object and extract from it the parameters and content required for a SWORD deposit.  This
     includes determining whether this is an Atom Multipart request or not, and extracting the atom/payload where
     appropriate.  It also includes extracting the HTTP headers which are relevant to deposit, and for those not
     supplied providing their defaults in the returned DepositRequest object
     """
     d = DepositRequest()
     
     # map the webpy headers to something more standard
     mapped_headers = self._map_webpy_headers(web.ctx.environ)
     
     # get the headers that have been provided.  Any headers which have not been provided will
     # will have default values applied
     h = HttpHeaders()
     d.set_from_headers(h.get_sword_headers(mapped_headers))
     
     if d.content_type.startswith("application/atom+xml"):
         atom_only=True
     
     empty_request = False
     if d.content_length == 0:
         ssslog.info("Received empty deposit request")
         empty_request = True
     if d.content_length > config.max_upload_size:
         raise SwordError(error_uri=Errors.max_upload_size_exceeded, 
                         msg="Max upload size is " + str(config.max_upload_size) + 
                         "; incoming content length was " + str(d.content_length))
     
     # find out if this is a multipart or not
     is_multipart = False
     
     # FIXME: these headers aren't populated yet, because the webpy api doesn't
     # appear to have a mechanism to retrieve them.  urgh.
     entry_part_headers = {}
     media_part_headers = {}
     webin = web.input()
     if len(webin) == 2:
         ssslog.info("Received multipart deposit request")
         d.atom = webin['atom']
         # FIXME: this reads the payload into memory, we need to sort that out
         # read the zip file from the base64 encoded string
         d.content = base64.decodestring(webin['payload'])
         is_multipart = True
     elif not empty_request:
         # if this wasn't a multipart, and isn't an empty request, then the data is in web.data().  This could be a binary deposit or
         # an atom entry deposit - reply on the passed/determined argument to determine which
         if atom_only:
             ssslog.info("Received Entry deposit request")
             d.atom = web.data()
         else:
             ssslog.info("Received Binary deposit request")
             d.content = web.data()
     
     if is_multipart:
         d.filename = h.extract_filename(media_part_headers)
     else:
         d.filename = h.extract_filename(mapped_headers)
     
     # now just attach the authentication data and return
     d.auth = auth
     return d
 def get_deposit(self, auth=None, atom_only=False):
     # FIXME: this does not deal with the Media Part headers on a multipart deposit
     """
     Take a request object and extract from it the parameters and content required for a SWORD deposit.  This
     includes determining whether this is an Atom Multipart request or not, and extracting the atom/payload where
     appropriate.  It also includes extracting the HTTP headers which are relevant to deposit, and for those not
     supplied providing their defaults in the returned DepositRequest object
     """
     d = DepositRequest()
     
     # map the webpy headers to something more standard
     mapped_headers = self._map_webpy_headers(request.environ)
     
     # get the headers that have been provided.  Any headers which have not been provided will
     # will have default values applied
     h = HttpHeaders()
     d.set_from_headers(h.get_sword_headers(mapped_headers))
     
     if d.content_type.startswith("application/atom+xml"):
         atom_only=True
     
     empty_request = False
     if d.content_length == 0:
         ssslog.info("Received empty deposit request")
         empty_request = True
     if config.max_upload_size is not None and d.content_length > config.max_upload_size:
         raise SwordError(error_uri=Errors.max_upload_size_exceeded, 
                         msg="Max upload size is " + str(config.max_upload_size) + 
                         "; incoming content length was " + str(d.content_length))
     
     # FIXME: this method does NOT support multipart
     # find out if this is a multipart or not
     is_multipart = False
     
     # FIXME: these headers aren't populated yet, because the webpy api doesn't
     # appear to have a mechanism to retrieve them.  urgh.
     #entry_part_headers = {}
     #media_part_headers = {}
     #webin = request.POST
     #ssslog.debug(webin)
     #if len(webin) == 2:
     #    ssslog.info("Received multipart deposit request")
     #    d.atom = webin['atom']
         # FIXME: this reads the payload into memory, we need to sort that out
         # read the zip file from the base64 encoded string
     #    d.content = base64.decodestring(webin['payload'])
     #    is_multipart = True
     #elif not empty_request:
     if not empty_request:
         # for this section, we have to reset the file pointer in the body_file
         # part of the request back to the start, since it may have 
         # already been read once
         f = request.body_file
         f.seek(0, 0)
         
         # if this wasn't a multipart, and isn't an empty request, then read the 
         # data from the body_file
         if atom_only:
             # we don't worry about scalability here - the entries should be
             # generally small
             ssslog.info("Received Entry deposit request")
             d.atom = f.read()
         else:
             ssslog.info("Received Binary deposit request")
             # FIXME: this is reading everything in, and should be re-evaluated for performance/scalability
             d.content_file = f
     
     if is_multipart:
         d.filename = h.extract_filename(media_part_headers)
     else:
         d.filename = h.extract_filename(mapped_headers)
     
     # now just attach the authentication data and return
     d.auth = auth
     return d