Exemple #1
0
    def process(self, src_resrc, request):

        if self.dst_exists:
            # Desitination exsists
            overwrite = get_overwrite(request)
            if not overwrite:
                return BadRequestResource(
                    "copying collection %s failed."
                    "because overwite value is invalid" % request.uri)
            elif overwrite != "T":
                # If the Overwrite header is set to "F" then the
                # operation will fail.
                # (RFC 2518 8.8.4)
                return PreconditionFailedResource(
                    "moving collection %s failed."
                    "because overwite is not "T"" % request.uri)

            if not self.dst_resrc.isWritable():
                return ForbiddenResource(
                    "copying collection %s failed." % request.uri)

            if self.dst_resrc.isdir():
                depth = get_depth(request)
                if not depth:
                    return BadRequestResource(
                        "copying collection %s failed."
                        "because depth depth value is invalid" % request.uri)
                self.dst_resrc.rmtree()
                if depth == "0":
                    os.mkdir(self.dst_path)
                    shutil.copymode(src_resrc.path, self.dst_path)
                    shutil.copystat(src_resrc.path, self.dst_path)
                else:
                    src_resrc.copytree(self.dst_path)
            else:
                os.remove(self.dst_path)
                src_resrc.copy(self.dst_path)
            # 204 (No Content) - The source resource was successfully
            # copied to a pre-existing destination resource.
            # (RFC 2518 8.8.5)
            return NoContentResource("%s copied" % request.uri)
        else:
            # Destination is new resource
            if not self.dst_resrc.isWritable():
                return ForbiddenResource(
                    "copying collection %s failed." % request.uri)

            if src_resrc.isdir():
                src_resrc.copytree(self.dst_path)
            else:
                src_resrc.copy(self.dst_path)
            # 201 (Created) - The source resource was successfully
            # moved, and a new resource was created at the
            # destination.
            # (RFC 2518 8.9.4)
            return CreatedResource("%s copied" % request.uri)
Exemple #2
0
    def process(self, src_resrc, request):

        if not src_resrc.isRemovable():
            return ForbiddenResource(
                "moving collection %s failed." % request.uri)

        if self.dst_exists:
            # Desitination exsists
            overwrite = get_overwrite(request)
            if not overwrite:
                return BadRequestResource(
                    "moving collection %s failed."
                    "because overwite value is invalid" % request.uri)
            elif overwrite != "T":
                # If a COPY or MOVE is not performed due to the value
                # of the Overwrite header, the method MUST fail with a
                # 412 (Precondition Failed) status code.
                # (RFC 2518 9.6)
                return PreconditionFailedResource(
                    "moving collection %s failed."
                    "because overwite is not "T"" % request.uri)

            if not self.dst_resrc.isWritable():
                return ForbiddenResource(
                    "moving collection %s failed." % request.uri)

            if self.dst_resrc.isdir():
                depth = get_depth(request)
                # If a resource exists at the destination and the
                # Overwrite header is "T" then prior to performing the
                # move the server MUST perform a DELETE with "Depth:
                # infinity" on the destination resource.
                # (RFC 2518 8.9.3)
                if not depth:
                    return BadRequestResource(
                        "moving collection %s failed."
                        "because depth depth value is invalid" % request.uri)
                self.dst_resrc.rmtree()

            src_resrc.move(self.dst_path)
            # 204 (No Content) - The source resource was successfully
            # moved to a pre-existing destination resource.
            return NoContentResource("%s moved" % request.uri)
        else:
            # Destination is new resource
            if not self.dst_resrc.isWritable():
                return ForbiddenResource(
                    "moving collection %s failed." % request.uri)

            src_resrc.move(self.dst_path)
            # 201 (Created) - The source resource was successfully
            # moved, and a new resource was created at the
            # destination.
            # (RFC 2518 8.9.4)
            return CreatedResource("%s moved" % request.uri)