Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename file_infos parameter #397

Merged
merged 10 commits into from
Jun 15, 2023
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Deprecated
* Deprecate `file_infos` argument. Use `file_info` instead. Old argument name won't be supported in v3.

### Changed
* `version_utils` decorators now ignore `current_version` parameter to better fit `apiver` needs

### Fixed
* Circular symlinks no longer cause infinite loops when syncing a folder

Expand Down
35 changes: 18 additions & 17 deletions b2sdk/bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# License https://www.backblaze.com/using_b2_code.html
#
######################################################################
from __future__ import annotations

import fnmatch
import logging
Expand Down Expand Up @@ -488,14 +489,14 @@ def upload_bytes(
data_bytes,
file_name,
content_type=None,
file_infos=None,
file_info: dict | None = None,
progress_listener=None,
encryption: Optional[EncryptionSetting] = None,
file_retention: Optional[FileRetentionSetting] = None,
legal_hold: Optional[LegalHold] = None,
large_file_sha1: Optional[Sha1HexDigest] = None,
custom_upload_timestamp: Optional[int] = None,
cache_control: Optional[str] = None,
encryption: EncryptionSetting | None = None,
file_retention: FileRetentionSetting | None = None,
legal_hold: LegalHold | None = None,
large_file_sha1: Sha1HexDigest | None = None,
custom_upload_timestamp: int | None = None,
cache_control: str | None = None,
):
"""
Upload bytes in memory to a B2 file.
Expand All @@ -506,7 +507,7 @@ def upload_bytes(
:param bytes data_bytes: a byte array to upload
:param str file_name: a file name to upload bytes to
:param str,None content_type: the MIME type, or ``None`` to accept the default based on file extension of the B2 file name
:param dict,None file_infos: a file info to store with the file or ``None`` to not store anything
:param dict,None file_info: a file info to store with the file or ``None`` to not store anything
:param b2sdk.v2.AbstractProgressListener,None progress_listener: a progress listener object to use, or ``None`` to not track progress
:param b2sdk.v2.EncryptionSetting encryption: encryption settings (``None`` if unknown)
:param b2sdk.v2.FileRetentionSetting file_retention: file retention setting
Expand All @@ -521,7 +522,7 @@ def upload_bytes(
upload_source,
file_name,
content_type=content_type,
file_info=file_infos,
file_info=file_info,
progress_listener=progress_listener,
encryption=encryption,
file_retention=file_retention,
Expand All @@ -536,16 +537,16 @@ def upload_local_file(
local_file,
file_name,
content_type=None,
file_infos=None,
file_info: dict | None = None,
sha1_sum=None,
min_part_size=None,
progress_listener=None,
encryption: Optional[EncryptionSetting] = None,
file_retention: Optional[FileRetentionSetting] = None,
legal_hold: Optional[LegalHold] = None,
encryption: EncryptionSetting | None = None,
file_retention: FileRetentionSetting | None = None,
legal_hold: LegalHold | None = None,
upload_mode: UploadMode = UploadMode.FULL,
custom_upload_timestamp: Optional[int] = None,
cache_control: Optional[str] = None,
custom_upload_timestamp: int | None = None,
cache_control: str | None = None,
):
"""
Upload a file on local disk to a B2 file.
Expand All @@ -560,7 +561,7 @@ def upload_local_file(
:param str local_file: a path to a file on local disk
:param str file_name: a file name of the new B2 file
:param str,None content_type: the MIME type, or ``None`` to accept the default based on file extension of the B2 file name
:param dict,None file_infos: a file info to store with the file or ``None`` to not store anything
:param dict,None file_info: a file info to store with the file or ``None`` to not store anything
:param str,None sha1_sum: file SHA1 hash or ``None`` to compute it automatically
:param int min_part_size: a minimum size of a part
:param b2sdk.v2.AbstractProgressListener,None progress_listener: a progress listener object to use, or ``None`` to not report progress
Expand Down Expand Up @@ -593,7 +594,7 @@ def upload_local_file(
sources,
file_name,
content_type=content_type,
file_info=file_infos,
file_info=file_info,
min_part_size=min_part_size,
progress_listener=progress_listener,
encryption=encryption,
Expand Down
13 changes: 7 additions & 6 deletions b2sdk/file_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# License https://www.backblaze.com/using_b2_code.html
#
######################################################################
from __future__ import annotations

from typing import Any, Dict, Optional, Union, Tuple, TYPE_CHECKING
import re
Expand Down Expand Up @@ -64,15 +65,15 @@ def __init__(
id_: str,
file_name: str,
size: int,
content_type: Optional[str],
content_sha1: Optional[str],
file_info: Dict[str, str],
content_type: str | None,
content_sha1: str | None,
file_info: dict[str, str] | None,
upload_timestamp: int,
server_side_encryption: EncryptionSetting,
file_retention: FileRetentionSetting = NO_RETENTION_FILE_SETTING,
legal_hold: LegalHold = LegalHold.UNSET,
replication_status: Optional[ReplicationStatus] = None,
cache_control: Optional[str] = None,
replication_status: ReplicationStatus | None = None,
cache_control: str | None = None,
):
self.api = api
self.id_ = id_
Expand Down Expand Up @@ -345,7 +346,7 @@ def _get_upload_headers(self) -> bytes:
content_length=self.size,
content_type=self.content_type,
content_sha1=self.content_sha1,
file_infos=self.file_info,
file_info=self.file_info,
server_side_encryption=sse,
file_retention=self.file_retention,
legal_hold=self.legal_hold,
Expand Down
33 changes: 17 additions & 16 deletions b2sdk/raw_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# License https://www.backblaze.com/using_b2_code.html
#
######################################################################
from __future__ import annotations

import base64
import re
Expand Down Expand Up @@ -314,12 +315,12 @@ def get_upload_file_headers(
content_length: int,
content_type: str,
content_sha1: str,
file_infos: dict,
server_side_encryption: Optional[EncryptionSetting],
file_retention: Optional[FileRetentionSetting],
legal_hold: Optional[LegalHold],
custom_upload_timestamp: Optional[int] = None,
cache_control: Optional[str] = None,
file_info: dict,
server_side_encryption: EncryptionSetting | None,
file_retention: FileRetentionSetting | None,
legal_hold: LegalHold | None,
custom_upload_timestamp: int | None = None,
cache_control: str | None = None,
) -> dict:
headers = {
'Authorization': upload_auth_token,
Expand All @@ -328,7 +329,7 @@ def get_upload_file_headers(
'Content-Type': content_type,
'X-Bz-Content-Sha1': content_sha1,
}
for k, v in file_infos.items():
for k, v in file_info.items():
headers[FILE_INFO_HEADER_PREFIX + k] = b2_url_encode(v)
if server_side_encryption is not None:
assert server_side_encryption.mode in (
Expand Down Expand Up @@ -359,7 +360,7 @@ def upload_file(
content_length,
content_type,
content_sha1,
file_infos,
file_info,
data_stream,
server_side_encryption: Optional[EncryptionSetting] = None,
file_retention: Optional[FileRetentionSetting] = None,
Expand Down Expand Up @@ -896,13 +897,13 @@ def upload_file(
content_length,
content_type,
content_sha1,
file_infos,
file_info: dict,
data_stream,
server_side_encryption: Optional[EncryptionSetting] = None,
file_retention: Optional[FileRetentionSetting] = None,
legal_hold: Optional[LegalHold] = None,
custom_upload_timestamp: Optional[int] = None,
cache_control: Optional[str] = None,
server_side_encryption: EncryptionSetting | None = None,
file_retention: FileRetentionSetting | None = None,
legal_hold: LegalHold | None = None,
custom_upload_timestamp: int | None = None,
cache_control: str | None = None,
):
"""
Upload one, small file to b2.
Expand All @@ -913,7 +914,7 @@ def upload_file(
:param content_length: number of bytes in the file
:param content_type: MIME type
:param content_sha1: hex SHA1 of the contents of the file
:param file_infos: extra file info to upload
:param file_info: extra file info to upload
:param data_stream: a file like object from which the contents of the file can be read
:param server_side_encryption: encryption setting for the file
:param file_retention: retention setting for the file
Expand All @@ -930,7 +931,7 @@ def upload_file(
content_length=content_length,
content_type=content_type,
content_sha1=content_sha1,
file_infos=file_infos,
file_info=file_info,
server_side_encryption=server_side_encryption,
file_retention=file_retention,
legal_hold=legal_hold,
Expand Down
49 changes: 25 additions & 24 deletions b2sdk/raw_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# License https://www.backblaze.com/using_b2_code.html
#
######################################################################
from __future__ import annotations

import collections
import io
Expand Down Expand Up @@ -1009,13 +1010,13 @@ def upload_file(
content_length: int,
content_type: str,
content_sha1: str,
file_infos: dict,
file_info: dict,
data_stream,
server_side_encryption: Optional[EncryptionSetting] = None,
file_retention: Optional[FileRetentionSetting] = None,
legal_hold: Optional[LegalHold] = None,
custom_upload_timestamp: Optional[int] = None,
cache_control: Optional[str] = None,
server_side_encryption: EncryptionSetting | None = None,
file_retention: FileRetentionSetting | None = None,
legal_hold: LegalHold | None = None,
custom_upload_timestamp: int | None = None,
cache_control: str | None = None,
):
data_bytes = self._simulate_chunked_post(data_stream, content_length)
assert len(data_bytes) == content_length
Expand All @@ -1034,7 +1035,7 @@ def upload_file(

encryption = server_side_encryption or self.default_server_side_encryption
if encryption: # FIXME: remove this part when RawApi<->Encryption adapters are implemented properly
file_infos = encryption.add_key_id_to_file_info(file_infos)
file_info = encryption.add_key_id_to_file_info(file_info)

upload_timestamp = next(self.upload_timestamp_counter)
if custom_upload_timestamp is not None:
Expand All @@ -1048,7 +1049,7 @@ def upload_file(
file_name,
content_type,
content_sha1,
file_infos,
file_info,
data_bytes,
upload_timestamp,
server_side_encryption=encryption,
Expand Down Expand Up @@ -1792,12 +1793,12 @@ def get_upload_file_headers(
content_length: int,
content_type: str,
content_sha1: str,
file_infos: dict,
server_side_encryption: Optional[EncryptionSetting],
file_retention: Optional[FileRetentionSetting],
legal_hold: Optional[LegalHold],
custom_upload_timestamp: Optional[int] = None,
cache_control: Optional[str] = None,
file_info: dict,
server_side_encryption: EncryptionSetting | None,
file_retention: FileRetentionSetting | None,
legal_hold: LegalHold | None,
custom_upload_timestamp: int | None = None,
cache_control: str | None = None,
) -> dict:

# fix to allow calculating headers on unknown key - only for simulation
Expand All @@ -1812,7 +1813,7 @@ def get_upload_file_headers(
content_length=content_length,
content_type=content_type,
content_sha1=content_sha1,
file_infos=file_infos,
file_info=file_info,
server_side_encryption=server_side_encryption,
file_retention=file_retention,
legal_hold=legal_hold,
Expand All @@ -1828,13 +1829,13 @@ def upload_file(
content_length: int,
content_type: str,
content_sha1: str,
file_infos: dict,
file_info: dict,
data_stream,
server_side_encryption: Optional[EncryptionSetting] = None,
file_retention: Optional[FileRetentionSetting] = None,
legal_hold: Optional[LegalHold] = None,
custom_upload_timestamp: Optional[int] = None,
cache_control: Optional[str] = None,
server_side_encryption: EncryptionSetting | None = None,
file_retention: FileRetentionSetting | None = None,
legal_hold: LegalHold | None = None,
custom_upload_timestamp: int | None = None,
cache_control: str | None = None,
):
with ConcurrentUsedAuthTokenGuard(
self.currently_used_auth_tokens[upload_auth_token], upload_auth_token
Expand All @@ -1851,7 +1852,7 @@ def upload_file(
assert server_side_encryption.mode in (
EncryptionMode.NONE, EncryptionMode.SSE_B2, EncryptionMode.SSE_C
)
file_infos = server_side_encryption.add_key_id_to_file_info(file_infos)
file_info = server_side_encryption.add_key_id_to_file_info(file_info)

# we don't really need headers further on
# but we still simulate their calculation
Expand All @@ -1861,7 +1862,7 @@ def upload_file(
content_length=content_length,
content_type=content_type,
content_sha1=content_sha1,
file_infos=file_infos,
file_info=file_info,
server_side_encryption=server_side_encryption,
file_retention=file_retention,
legal_hold=legal_hold,
Expand All @@ -1876,7 +1877,7 @@ def upload_file(
content_length,
content_type,
content_sha1,
file_infos,
file_info,
data_stream,
server_side_encryption,
file_retention,
Expand Down
15 changes: 8 additions & 7 deletions b2sdk/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# License https://www.backblaze.com/using_b2_code.html
#
######################################################################
from __future__ import annotations

from functools import partial
from enum import Enum, unique
Expand Down Expand Up @@ -348,13 +349,13 @@ def upload_file(
content_length,
content_type,
content_sha1,
file_infos,
file_info,
data_stream,
server_side_encryption: Optional[EncryptionSetting] = None,
file_retention: Optional[FileRetentionSetting] = None,
legal_hold: Optional[LegalHold] = None,
custom_upload_timestamp: Optional[int] = None,
cache_control: Optional[str] = None,
server_side_encryption: EncryptionSetting | None = None,
file_retention: FileRetentionSetting | None = None,
legal_hold: LegalHold | None = None,
custom_upload_timestamp: int | None = None,
cache_control: str | None = None,
):
return self._wrap_token(
self.raw_api.upload_file,
Expand All @@ -364,7 +365,7 @@ def upload_file(
content_length,
content_type,
content_sha1,
file_infos,
file_info,
data_stream,
server_side_encryption,
file_retention=file_retention,
Expand Down
14 changes: 14 additions & 0 deletions b2sdk/v2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,17 @@
from .session import B2Session
from .sync import B2SyncPath
from .transfer import DownloadManager, UploadManager

# version & version utils

from .version_utils import rename_argument, rename_function

# raw_simulator

from .raw_simulator import BucketSimulator
from .raw_simulator import RawSimulator

# raw_api

from .raw_api import AbstractRawApi
from .raw_api import B2RawHTTPApi
Loading