gcs/upload.py
def init_write_object_grpc(cls, db, request_iterator, context):
        """Process an WriteObject streaming RPC, returning the upload object associated with it."""
        upload, object_checksums, is_resumable = None, None, False
        for request in request_iterator:
            first_message = request.WhichOneof("first_message")
            if first_message == "upload_id":
                upload = db.get_upload(request.upload_id, context)
                if upload.complete:
                    testbench.error.invalid(
                        "Uploading to a completed upload %s" % upload.upload_id, context
                    )
                    return None, False
                is_resumable = True
            elif first_message == "write_object_spec":
                bucket = db.get_bucket(
                    request.write_object_spec.resource.bucket, context
                ).metadata
                upload = cls.__init_first_write_grpc(request, bucket, context)
            elif upload is None:
                testbench.error.invalid("Upload missing a first_message field", context)
                return None, False

            if request.HasField("object_checksums"):
                # The object checksums may appear only in the first message *or* the last message, but not both
                if first_message is None and request.finish_write == False:
                    testbench.error.invalid(
                        "Object checksums can be included only in the first or last message",
                        context,
                    )
                    return None, False
                if object_checksums is not None:
                    testbench.error.invalid(
                        "Duplicate object checksums in upload",
                        context,
                    )
                    return None, False
                object_checksums = request.object_checksums

            data = request.WhichOneof("data")
            if data == "checksummed_data":
                checksummed_data = request.checksummed_data
            else:
                print("WARNING unexpected data field %s\n" % data)
                continue
            content = checksummed_data.content
            crc32c_hash = (
                checksummed_data.crc32c if checksummed_data.HasField("crc32c") else None
            )
            if crc32c_hash is not None:
                actual_crc32c = crc32c.crc32c(content)
                if actual_crc32c != crc32c_hash:
                    testbench.error.mismatch(
                        "crc32c in checksummed data",
                        crc32c_hash,
                        actual_crc32c,
                        context,
                    )
                    return None, False
            upload.media += checksummed_data.content
            if request.finish_write:
                upload.complete = True

        if upload is None:
            testbench.error.invalid("Upload missing a first_message field", context)
            return None, False
        if object_checksums is None:
            upload.metadata.metadata["x_emulator_no_crc32c"] = "true"
            upload.metadata.metadata["x_emulator_no_md5"] = "true"
            return upload, is_resumable
        if object_checksums.HasField("crc32c"):
            upload.metadata.metadata[
                "x_emulator_crc32c"
            ] = testbench.common.rest_crc32c_from_proto(object_checksums.crc32c)
        else:
            upload.metadata.metadata["x_emulator_no_crc32c"] = "true"
        if object_checksums.md5_hash is not None and object_checksums.md5_hash != b"":
            upload.metadata.metadata[
                "x_emulator_md5"
            ] = testbench.common.rest_md5_from_proto(object_checksums.md5_hash)
        else:
            upload.metadata.metadata["x_emulator_no_md5"] = "true"
        return upload, is_resumable
Process an WriteObject streaming RPC, returning the upload object associated with it.
Process an WriteObject streaming RPC, returning the upload object associated with it.
Process an WriteObject streaming RPC returning the upload object associated with it .
def init_write_object_grpc(cls, db, request_iterator, context):
        upload, object_checksums, is_resumable = None, None, False
        for request in request_iterator:
            first_message = request.WhichOneof("first_message")
            if first_message == "upload_id":
                upload = db.get_upload(request.upload_id, context)
                if upload.complete:
                    testbench.error.invalid(
                        "Uploading to a completed upload %s" % upload.upload_id, context
                    )
                    return None, False
                is_resumable = True
            elif first_message == "write_object_spec":
                bucket = db.get_bucket(
                    request.write_object_spec.resource.bucket, context
                ).metadata
                upload = cls.__init_first_write_grpc(request, bucket, context)
            elif upload is None:
                testbench.error.invalid("Upload missing a first_message field", context)
                return None, False
            if request.HasField("object_checksums"):
                if first_message is None and request.finish_write == False:
                    testbench.error.invalid(
                        "Object checksums can be included only in the first or last message",
                        context,
                    )
                    return None, False
                if object_checksums is not None:
                    testbench.error.invalid(
                        "Duplicate object checksums in upload",
                        context,
                    )
                    return None, False
                object_checksums = request.object_checksums
            data = request.WhichOneof("data")
            if data == "checksummed_data":
                checksummed_data = request.checksummed_data
            else:
                print("WARNING unexpected data field %s\n" % data)
                continue
            content = checksummed_data.content
            crc32c_hash = (
                checksummed_data.crc32c if checksummed_data.HasField("crc32c") else None
            )
            if crc32c_hash is not None:
                actual_crc32c = crc32c.crc32c(content)
                if actual_crc32c != crc32c_hash:
                    testbench.error.mismatch(
                        "crc32c in checksummed data",
                        crc32c_hash,
                        actual_crc32c,
                        context,
                    )
                    return None, False
            upload.media += checksummed_data.content
            if request.finish_write:
                upload.complete = True
        if upload is None:
            testbench.error.invalid("Upload missing a first_message field", context)
            return None, False
        if object_checksums is None:
            upload.metadata.metadata["x_emulator_no_crc32c"] = "true"
            upload.metadata.metadata["x_emulator_no_md5"] = "true"
            return upload, is_resumable
        if object_checksums.HasField("crc32c"):
            upload.metadata.metadata[
                "x_emulator_crc32c"
            ] = testbench.common.rest_crc32c_from_proto(object_checksums.crc32c)
        else:
            upload.metadata.metadata["x_emulator_no_crc32c"] = "true"
        if object_checksums.md5_hash is not None and object_checksums.md5_hash != b"":
            upload.metadata.metadata[
                "x_emulator_md5"
            ] = testbench.common.rest_md5_from_proto(object_checksums.md5_hash)
        else:
            upload.metadata.metadata["x_emulator_no_md5"] = "true"
        return upload, is_resumable
def init_write_object_grpc ( cls , db , request_iterator , context ) : upload , object_checksums , is_resumable = None , None , False for request in request_iterator : first_message = request . WhichOneof ( "first_message" ) if first_message == "upload_id" : upload = db . get_upload ( request . upload_id , context ) if upload . complete : testbench . error . invalid ( "Uploading to a completed upload %s" % upload . upload_id , context ) return None , False is_resumable = True elif first_message == "write_object_spec" : bucket = db . get_bucket ( request . write_object_spec . resource . bucket , context ) . metadata upload = cls . __init_first_write_grpc ( request , bucket , context ) elif upload is None : testbench . error . invalid ( "Upload missing a first_message field" , context ) return None , False if request . HasField ( "object_checksums" ) : if first_message is None and request . finish_write == False : testbench . error . invalid ( "Object checksums can be included only in the first or last message" , context , ) return None , False if object_checksums is not None : testbench . error . invalid ( "Duplicate object checksums in upload" , context , ) return None , False object_checksums = request . object_checksums data = request . WhichOneof ( "data" ) if data == "checksummed_data" : checksummed_data = request . checksummed_data else : print ( "WARNING unexpected data field %s\n" % data ) continue content = checksummed_data . content crc32c_hash = ( checksummed_data . crc32c if checksummed_data . HasField ( "crc32c" ) else None ) if crc32c_hash is not None : actual_crc32c = crc32c . crc32c ( content ) if actual_crc32c != crc32c_hash : testbench . error . mismatch ( "crc32c in checksummed data" , crc32c_hash , actual_crc32c , context , ) return None , False upload . media += checksummed_data . content if request . finish_write : upload . complete = True if upload is None : testbench . error . invalid ( "Upload missing a first_message field" , context ) return None , False if object_checksums is None : upload . metadata . metadata [ "x_emulator_no_crc32c" ] = "true" upload . metadata . metadata [ "x_emulator_no_md5" ] = "true" return upload , is_resumable if object_checksums . HasField ( "crc32c" ) : upload . metadata . metadata [ "x_emulator_crc32c" ] = testbench . common . rest_crc32c_from_proto ( object_checksums . crc32c ) else : upload . metadata . metadata [ "x_emulator_no_crc32c" ] = "true" if object_checksums . md5_hash is not None and object_checksums . md5_hash != b"" : upload . metadata . metadata [ "x_emulator_md5" ] = testbench . common . rest_md5_from_proto ( object_checksums . md5_hash ) else : upload . metadata . metadata [ "x_emulator_no_md5" ] = "true" return upload , is_resumable
Process an WriteObject streaming RPC, returning the upload object associated with it.
Process an WriteObject streaming RPC returning the upload object associated with it .
"""Process an WriteObject streaming RPC, returning the upload object associated with it.""" # The object checksums may appear only in the first message *or* the last message, but not both
cls
db
request_iterator
context