def put(self, env, start_response):
        """Writes a file passed in the request to the archive"""
        archivefile = None
        resp = interface_responses.Responses()
        path_info = env['PATH_INFO']
        mod_time = get_http_modified_time(env)
        stderr.flush()
        archivefile = self._archive.open(path_info, "w")
        try:
            content_length = int(env['CONTENT_LENGTH'])
        except Exception as ex:
            raise ArchiveInterfaceError("Can't get file content length with "\
                "error: " + str(ex))
        while content_length > 0:
            if content_length > BLOCK_SIZE:
                buf = env['wsgi.input'].read(BLOCK_SIZE)
            else:
                buf = env['wsgi.input'].read(content_length)
            archivefile.write(buf)
            content_length -= len(buf)

        self._response = resp.successful_put_response(start_response,
                                                      env['CONTENT_LENGTH'])
        archivefile.close()
        archivefile.set_mod_time(mod_time)
        return self.return_response()
 def test_get_http_modified_time(self):
     """test to see if the path size of a directory is returned"""
     env = dict()
     env['HTTP_LAST_MODIFIED'] = 'SUN, 06 NOV 1994 08:49:37 GMT'
     mod_time = get_http_modified_time(env)
     self.assertEqual(mod_time, 784111777)
     env = dict()
     mod_time = get_http_modified_time(env)
     self.assertEqual(int(mod_time), int(time.time()))
     for thing in (None, [], 46):
         hit_exception = False
         try:
             env['HTTP_LAST_MODIFIED'] = thing
             get_http_modified_time(env)
         except ArchiveInterfaceError, ex:
             hit_exception = True
         self.assertTrue(hit_exception)
 def test_get_http_modified_time(self):
     """test to see if the path size of a directory is returned"""
     env = dict()
     env['HTTP_LAST_MODIFIED'] = 'SUN, 06 NOV 1994 08:49:37 GMT'
     mod_time = get_http_modified_time(env)
     self.assertEqual(mod_time, 784111777)
     env = dict()
     mod_time = get_http_modified_time(env)
     self.assertEqual(int(mod_time), int(time.time()))
     for thing in (None, [], 46):
         hit_exception = False
         try:
             env['HTTP_LAST_MODIFIED'] = thing
             get_http_modified_time(env)
         except ArchiveInterfaceError, ex:
             hit_exception = True
         self.assertTrue(hit_exception)
    def put(self, env, start_response):
        """Writes a file passed in the request to the archive"""
        archivefile = None
        resp = interface_responses.Responses()
        path_info = env["PATH_INFO"]
        mod_time = get_http_modified_time(env)
        stderr.flush()
        archivefile = self._archive.open(path_info, "w")
        try:
            content_length = int(env["CONTENT_LENGTH"])
        except Exception as ex:
            raise ArchiveInterfaceError("Can't get file content length with " "error: " + str(ex))
        while content_length > 0:
            if content_length > BLOCK_SIZE:
                buf = env["wsgi.input"].read(BLOCK_SIZE)
            else:
                buf = env["wsgi.input"].read(content_length)
            archivefile.write(buf)
            content_length -= len(buf)

        self._response = resp.successful_put_response(start_response, env["CONTENT_LENGTH"])
        archivefile.close()
        archivefile.set_mod_time(mod_time)
        return self.return_response()