Skip to content

Commit 6308fa1

Browse files
author
Test User
committed
feat: implement phase 1, constants and common classes.
1 parent e1f2a49 commit 6308fa1

File tree

3 files changed

+126
-0
lines changed

3 files changed

+126
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Resumable media library for Google APIs."""
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Common constants and utilities for Resumable Media."""
16+
17+
# The default size for individual upload chunks (10 MB).
18+
# When a resumable upload is chunked, the size of each chunk (except the last)
19+
# must be a multiple of the chunk granularity specified by the server in the
20+
# `X-Goog-Upload-Chunk-Granularity` header during the initial `start` request.
21+
# 10 MB is used as a default.
22+
DEFAULT_CHUNK_SIZE = 10 * 1024 * 1024 # 10MB
23+
24+
# The header specifying the upload protocol.
25+
# Sent by the client during upload initiation.
26+
UPLOAD_PROTOCOL_HEADER = "X-Goog-Upload-Protocol"
27+
28+
# The header specifying the protocol command.
29+
# Sent by the client on active requests (e.g. start, upload, finalize, query).
30+
UPLOAD_COMMAND_HEADER = "X-Goog-Upload-Command"
31+
32+
# The header specifying the status of the upload.
33+
# Received from the server.
34+
UPLOAD_STATUS_HEADER = "X-Goog-Upload-Status"
35+
36+
# The header providing the dedicated upload URL.
37+
# Received from the server in the start command response.
38+
UPLOAD_URL_HEADER = "X-Goog-Upload-URL"
39+
40+
# The header specifying the byte offset of the current chunk.
41+
# Sent by the client during chunk uploads.
42+
UPLOAD_OFFSET_HEADER = "X-Goog-Upload-Offset"
43+
44+
# The header specifying the number of bytes successfully persisted so far.
45+
# Received from the server, typically in query responses.
46+
UPLOAD_SIZE_RECEIVED_HEADER = "X-Goog-Upload-Size-Received"
47+
48+
# The header specifying the required block alignment size for chunks.
49+
# Received from the server in the start command response.
50+
UPLOAD_CHUNK_GRANULARITY_HEADER = "X-Goog-Upload-Chunk-Granularity"
51+
52+
# The value indicating the resumable upload protocol.
53+
# Sent by the client in the `UPLOAD_PROTOCOL_HEADER`.
54+
UPLOAD_PROTOCOL_VALUE = "resumable"
55+
56+
class UploadCommand:
57+
"""HTTP Header values for the Resumable Upload command header."""
58+
START = "start"
59+
UPLOAD = "upload"
60+
FINALIZE = "finalize"
61+
QUERY = "query"
62+
CANCEL = "cancel"
63+
64+
class UploadStatus:
65+
"""HTTP Header values for the Resumable Upload status header."""
66+
ACTIVE = "active"
67+
FINAL = "final"
68+
CANCELLED = "cancelled"
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import pytest
16+
17+
from google.api_core.resumable_media import _common
18+
19+
20+
def test_constants():
21+
assert _common.UPLOAD_PROTOCOL_HEADER == "X-Goog-Upload-Protocol"
22+
assert _common.UPLOAD_COMMAND_HEADER == "X-Goog-Upload-Command"
23+
assert _common.UPLOAD_STATUS_HEADER == "X-Goog-Upload-Status"
24+
assert _common.UPLOAD_URL_HEADER == "X-Goog-Upload-URL"
25+
assert _common.UPLOAD_OFFSET_HEADER == "X-Goog-Upload-Offset"
26+
assert _common.UPLOAD_SIZE_RECEIVED_HEADER == "X-Goog-Upload-Size-Received"
27+
assert _common.UPLOAD_CHUNK_GRANULARITY_HEADER == "X-Goog-Upload-Chunk-Granularity"
28+
assert _common.UPLOAD_PROTOCOL_VALUE == "resumable"
29+
assert _common.DEFAULT_CHUNK_SIZE == 10 * 1024 * 1024
30+
31+
32+
def test_upload_command():
33+
assert _common.UploadCommand.START == "start"
34+
assert _common.UploadCommand.UPLOAD == "upload"
35+
assert _common.UploadCommand.FINALIZE == "finalize"
36+
assert _common.UploadCommand.QUERY == "query"
37+
assert _common.UploadCommand.CANCEL == "cancel"
38+
39+
40+
def test_upload_status():
41+
assert _common.UploadStatus.ACTIVE == "active"
42+
assert _common.UploadStatus.FINAL == "final"
43+
assert _common.UploadStatus.CANCELLED == "cancelled"

0 commit comments

Comments
 (0)