Пример #1
0
 def _object_path(self, bucket, object_name):
     if self.application.bucket_depth < 1:
         return os.path.abspath(os.path.join(
             self.application.directory, bucket, object_name))
     name_hash = utils.get_hash_str(object_name)
     path = os.path.abspath(os.path.join(
         self.application.directory, bucket))
     for i in range(self.application.bucket_depth):
         path = os.path.join(path, name_hash[:2 * (i + 1)])
     return os.path.join(path, object_name)
Пример #2
0
 def _object_path(self, bucket, object_name):
     if self.application.bucket_depth < 1:
         return os.path.abspath(os.path.join(
             self.application.directory, bucket, object_name))
     name_hash = utils.get_hash_str(object_name)
     path = os.path.abspath(os.path.join(
         self.application.directory, bucket))
     for i in range(self.application.bucket_depth):
         path = os.path.join(path, name_hash[:2 * (i + 1)])
     return os.path.join(path, object_name)
Пример #3
0
 def put(self, bucket, object_name):
     object_name = urllib.unquote(object_name)
     bucket_dir = os.path.abspath(
         os.path.join(self.application.directory, bucket))
     if (not bucket_dir.startswith(self.application.directory)
             or not os.path.isdir(bucket_dir)):
         self.set_404()
         return
     path = self._object_path(bucket, object_name)
     if not path.startswith(bucket_dir) or os.path.isdir(path):
         self.set_status(403)
         return
     directory = os.path.dirname(path)
     fileutils.ensure_tree(directory)
     object_file = open(path, "w")
     object_file.write(self.request.body)
     object_file.close()
     self.set_header('ETag', '"%s"' % utils.get_hash_str(self.request.body))
     self.finish()
Пример #4
0
 def put(self, bucket, object_name):
     object_name = parse.unquote(object_name)
     bucket_dir = os.path.abspath(os.path.join(
         self.application.directory, bucket))
     if (not bucket_dir.startswith(self.application.directory) or
             not os.path.isdir(bucket_dir)):
         self.set_404()
         return
     path = self._object_path(bucket, object_name)
     if not path.startswith(bucket_dir) or os.path.isdir(path):
         self.set_status(403)
         return
     directory = os.path.dirname(path)
     fileutils.ensure_tree(directory)
     object_file = open(path, "wb")
     object_file.write(self.request.body)
     object_file.close()
     self.set_header('ETag',
                     '"%s"' % utils.get_hash_str(self.request.body))
     self.finish()