Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/pip/aiohttp-3.8.4
Browse files Browse the repository at this point in the history
  • Loading branch information
karajan1001 authored Mar 26, 2023
2 parents 5b43b37 + 936588f commit f71d6e1
Show file tree
Hide file tree
Showing 16 changed files with 74 additions and 174 deletions.
2 changes: 1 addition & 1 deletion .cruft.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"template": "https://github.com/iterative/py-template",
"commit": "75abeda8b405100ca48820bb33191a85de9f446f",
"commit": "c4e24f909659b6ce9c34a1da631290f0c70ff2f2",
"checkout": null,
"context": {
"cookiecutter": {
Expand Down
13 changes: 6 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ default_language_version:
python: python3
repos:
- repo: https://github.com/psf/black
rev: 22.10.0
rev: 23.1.0
hooks:
- id: black
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v4.4.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
Expand All @@ -29,21 +29,20 @@ repos:
- id: codespell
additional_dependencies: ["tomli"]
- repo: https://github.com/asottile/pyupgrade
rev: v3.2.2
rev: v3.3.1
hooks:
- id: pyupgrade
args: [--py38-plus]
- repo: https://github.com/PyCQA/isort
rev: 5.10.1
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/pycqa/flake8
rev: 5.0.4
rev: 6.0.0
hooks:
- id: flake8
additional_dependencies:
- flake8-broken-line==0.6.0
- flake8-bugbear==22.10.27
- flake8-bugbear==23.1.20
- flake8-comprehensions==3.10.1
- flake8-debugger==4.1.2
- flake8-string-format==0.3.0
Expand Down
1 change: 0 additions & 1 deletion examples/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ async def async_go():
async with AioBucket(
auth, "http://oss-cn-hangzhou.aliyuncs.com", BUCKET_NAME
) as bucket:

# upload object to oss
data = b"\x01" * 1024
resp = await bucket.put_object(data_obj, data)
Expand Down
7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
[tool.setuptools_scm]

[tool.black]
line-length = 79
line-length = 88
include = '\.pyi?$'
exclude = '''
/(
Expand All @@ -25,7 +25,7 @@ exclude = '''
[tool.isort]
profile = "black"
known_first_party = ["aiooss2"]
line_length = 79
line_length = 88

[tool.pytest.ini_options]
addopts = "-ra"
Expand Down Expand Up @@ -63,6 +63,9 @@ warn_redundant_casts = true
warn_unreachable = true
files = ["src", "tests"]

[tool.pylint.format]
max-line-length = 88

[tool.pylint.message_control]
enable = ["c-extension-no-member", "no-else-return"]

Expand Down
16 changes: 10 additions & 6 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ package_dir=
include_package_data = True
install_requires =
aiohttp==3.8.4
oss2==2.16.0
oss2==2.17.0

[options.extras_require]
docs =
Expand Down Expand Up @@ -57,12 +57,16 @@ where=src

[flake8]
ignore=
E203, # Whitespace before ':'
E266, # Too many leading '#' for block comment
W503, # Line break occurred before a binary operator
P1, # unindexed parameters in the str.format, see:
# Whitespace before ':'
E203
# Too many leading '#' for block comment
E266
# Line break occurred before a binary operator
W503
# unindexed parameters in the str.format, see:
# https://pypi.org/project/flake8-string-format/
max_line_length = 79
P1
max_line_length = 88
max-complexity = 15
select = B,C,E,F,W,T4,B902,T,P
show_source = true
Expand Down
11 changes: 3 additions & 8 deletions src/aiooss2/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,9 @@ def _invoke_callbacks(self, content: Union[str, bytes]):
)
self.discard -= real_discard

_invoke_progress_callback(
self.progress_callback, self.offset, self.size
)
_invoke_progress_callback(self.progress_callback, self.offset, self.size)
_invoke_crc_callback(self.crc_callback, content, real_discard)
content = _invoke_cipher_callback(
self.cipher_callback, content, real_discard
)
content = _invoke_cipher_callback(self.cipher_callback, content, real_discard)

return content

Expand Down Expand Up @@ -184,8 +180,7 @@ def __init__(self, stream, discard: int = 0, **kwargs):
super().__init__(stream, **kwargs)
if discard:
raise ValueError(
"discard not supported in Async "
f"Iterable input {self.stream}"
"discard not supported in Async " f"Iterable input {self.stream}"
)

async def read(self, amt: int = -1) -> bytes:
Expand Down
60 changes: 15 additions & 45 deletions src/aiooss2/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ def __init__(
self.endpoint = _normalize_endpoint(endpoint.strip())
if is_valid_endpoint(self.endpoint) is not True:
raise ClientError(
"The endpoint you has specified is not valid, "
f"endpoint: {endpoint}"
"The endpoint you has specified is not valid, " f"endpoint: {endpoint}"
)
self.session = session
self.timeout = connect_timeout or defaults.connect_timeout
Expand All @@ -130,7 +129,6 @@ def __init__(
async def _do(
self, method: str, bucket_name: str, key: Union[bytes, str], **kwargs
) -> "AioResponse":

key = to_string(key)
req = Request(
method,
Expand All @@ -143,9 +141,7 @@ async def _do(
)

assert self.session
resp: "AioResponse" = await self.session.do_request(
req, timeout=self.timeout
)
resp: "AioResponse" = await self.session.do_request(req, timeout=self.timeout)

logger.debug(
"Responses from the server, req_id: %s, status_code: %d",
Expand Down Expand Up @@ -174,9 +170,7 @@ async def _do_url(self, method, sign_url, **kwargs):
proxies=self.proxies,
**kwargs,
)
resp: "AioResponse" = await self.session.do_request(
req, timeout=self.timeout
)
resp: "AioResponse" = await self.session.do_request(req, timeout=self.timeout)
if resp.status // 100 != 2:
err = await make_exception(resp)
logger.info("Exception: %s", err)
Expand All @@ -191,9 +185,7 @@ async def _do_url(self, method, sign_url, **kwargs):
return resp

@staticmethod
async def _parse_result(
resp: "AioResponse", parse_func: Callable, klass: Type
):
async def _parse_result(resp: "AioResponse", parse_func: Callable, klass: Type):
result = klass(resp)
parse_func(result, await resp.read())
return result
Expand Down Expand Up @@ -345,9 +337,7 @@ async def get_object( # pylint: disable=too-many-arguments
if process:
params[Bucket.PROCESS] = process

resp = await self._do_object(
"GET", key, headers=headers_dict, params=params
)
resp = await self._do_object("GET", key, headers=headers_dict, params=params)
logger.debug("Get object done")

return AioGetObjectResult(resp, progress_callback, self.enable_crc)
Expand Down Expand Up @@ -379,9 +369,7 @@ async def delete_object(
RequestResult:
"""

resp = await self._do_object(
"DELETE", key, params=params, headers=headers
)
resp = await self._do_object("DELETE", key, params=params, headers=headers)
logger.debug("Delete object done")
return RequestResult(resp)

Expand Down Expand Up @@ -425,9 +413,7 @@ async def list_objects( # pylint: disable=too-many-arguments
headers=headers,
)
logger.debug("List objects done")
return await self._parse_result(
resp, parse_list_objects, ListObjectsResult
)
return await self._parse_result(resp, parse_list_objects, ListObjectsResult)

async def get_object_meta(
self,
Expand Down Expand Up @@ -458,15 +444,11 @@ async def get_object_meta(
if Bucket.OBJECTMETA not in params:
params[Bucket.OBJECTMETA] = ""

resp = await self._do_object(
"GET", key, params=params, headers=headers
)
resp = await self._do_object("GET", key, params=params, headers=headers)
logger.debug("Get object metadata done")
return GetObjectMetaResult(resp)

async def object_exists(
self, key: str, headers: Optional[Dict] = None
) -> bool:
async def object_exists(self, key: str, headers: Optional[Dict] = None) -> bool:
"""Return True if key exists, False otherwise. raise Exception
for other exceptions.
Expand Down Expand Up @@ -803,18 +785,14 @@ async def head_object(
headers,
)

resp = await self._do_object(
"HEAD", key, headers=headers, params=params
)
resp = await self._do_object("HEAD", key, headers=headers, params=params)

logger.debug(
"Head object done, req_id: %s, status_code: %s",
resp.request_id,
resp.status,
)
return await self._parse_result(
resp, parse_dummy_result, HeadObjectResult
)
return await self._parse_result(resp, parse_dummy_result, HeadObjectResult)

async def abort_multipart_upload(
self: "AioBucket", *args, **kwargs
Expand Down Expand Up @@ -842,21 +820,15 @@ async def list_multipart_uploads(
"""List multipart uploading process"""
return await list_multipart_uploads(self, *args, **kwargs)

async def list_parts(
self: "AioBucket", *args, **kwargs
) -> ListPartsResult:
async def list_parts(self: "AioBucket", *args, **kwargs) -> ListPartsResult:
"""list uploaded parts in a part uploading progress."""
return await list_parts(self, *args, **kwargs)

async def upload_part(
self: "AioBucket", *args, **kwargs
) -> PutObjectResult:
async def upload_part(self: "AioBucket", *args, **kwargs) -> PutObjectResult:
"""upload single part."""
return await upload_part(self, *args, **kwargs)

async def upload_part_copy(
self: "AioBucket", *args, **kwargs
) -> PutObjectResult:
async def upload_part_copy(self: "AioBucket", *args, **kwargs) -> PutObjectResult:
"""copy part or whole of a source file to a slice of a target file."""
return await upload_part_copy(self, *args, **kwargs)

Expand Down Expand Up @@ -933,6 +905,4 @@ async def list_buckets(

resp = await self._do("GET", "", "", params=list_param)
logger.debug("List buckets done")
return await self._parse_result(
resp, parse_list_buckets, ListBucketsResult
)
return await self._parse_result(resp, parse_list_buckets, ListBucketsResult)
4 changes: 1 addition & 3 deletions src/aiooss2/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
"""

from oss2.exceptions import _OSS_ERROR_TO_EXCEPTION
from oss2.exceptions import (
InvalidEncryptionRequest as _InvalidEncryptionRequest,
)
from oss2.exceptions import InvalidEncryptionRequest as _InvalidEncryptionRequest
from oss2.exceptions import ServerError, _parse_error_body


Expand Down
1 change: 0 additions & 1 deletion src/aiooss2/iterators.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ def __init__(
self.headers = http.CaseInsensitiveDict(headers)

async def _fetch(self):

result: ListObjectsResult = await self.bucket.list_objects(
prefix=self.prefix,
delimiter=self.delimiter,
Expand Down
24 changes: 7 additions & 17 deletions src/aiooss2/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,29 +71,21 @@ def _make_crypto(self, byte_range, discard):

if content_crypto_material.is_unencrypted():
logger.info(
"The object is not encrypted, "
"use crypto provider is not recommended"
"The object is not encrypted, use crypto provider is not recommended"
)
else:
crypto_provider = self.__crypto_provider
if (
content_crypto_material.mat_desc
!= self.__crypto_provider.mat_desc
):
if content_crypto_material.mat_desc != self.__crypto_provider.mat_desc:
logger.warning(
"The material description of the object "
"and the provider is inconsistent"
)
encryption_materials = (
self.__crypto_provider.get_encryption_materials(
content_crypto_material.mat_desc
)
encryption_materials = self.__crypto_provider.get_encryption_materials(
content_crypto_material.mat_desc
)
if encryption_materials:
crypto_provider = (
self.__crypto_provider.reset_encryption_materials(
encryption_materials
)
crypto_provider = self.__crypto_provider.reset_encryption_materials(
encryption_materials
)
else:
raise ClientError(
Expand Down Expand Up @@ -124,9 +116,7 @@ def _make_crypto(self, byte_range, discard):

offset = 0
if self.content_range:
start, _ = crypto_provider.adjust_range(
byte_range[0], byte_range[1]
)
start, _ = crypto_provider.adjust_range(byte_range[0], byte_range[1])
offset = content_crypto_material.cipher.calc_offset(start)

cipher = copy.copy(content_crypto_material.cipher)
Expand Down
Loading

0 comments on commit f71d6e1

Please sign in to comment.