Skip to content

Commit 7d64c59

Browse files
committed
release: 0.4.0
2 parents 67ce45f + 214e50f commit 7d64c59

File tree

20 files changed

+503
-353
lines changed

20 files changed

+503
-353
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ jobs:
146146
python-version: "3.10"
147147

148148
- name: Setup Poetry
149-
uses: abatilo/actions-poetry@v3
149+
uses: abatilo/actions-poetry@v4
150150
with:
151151
poetry-version: 1.7.1
152152

aiobungie/__init__.py

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# MIT License
2-
#
2+
# ruff: noqa: F401
3+
# ruff: noqa: F403
4+
# ruff: noqa: F405
35
# Copyright (c) 2020 - Present nxtlo
46
#
57
# Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -36,13 +38,7 @@
3638

3739
from __future__ import annotations
3840

39-
from aiobungie import api
40-
from aiobungie import builders
41-
from aiobungie import crates
42-
from aiobungie import framework
43-
from aiobungie import traits
44-
from aiobungie import typedefs
45-
from aiobungie import url
41+
from aiobungie import api, builders, crates, framework, traits, typedefs, url
4642
from aiobungie.client import Client
4743
from aiobungie.error import *
4844
from aiobungie.internal.enums import *
@@ -58,26 +54,28 @@
5854
from .crates.components import ComponentPrivacy
5955

6056
# Entity enums
61-
from .crates.entity import GatingScope
62-
from .crates.entity import ObjectiveUIStyle
63-
from .crates.entity import ValueUIStyle
57+
from .crates.entity import GatingScope, ObjectiveUIStyle, ValueUIStyle
6458

6559
# Fireteam enums.
66-
from .crates.fireteams import FireteamActivity
67-
from .crates.fireteams import FireteamDate
68-
from .crates.fireteams import FireteamLanguage
69-
from .crates.fireteams import FireteamPlatform
60+
from .crates.fireteams import (
61+
FireteamActivity,
62+
FireteamDate,
63+
FireteamLanguage,
64+
FireteamPlatform,
65+
)
7066

7167
# Records enums
7268
from .crates.records import RecordState
7369

7470
# Package metadata
75-
from .metadata import __about__
76-
from .metadata import __author__
77-
from .metadata import __docs__
78-
from .metadata import __email__
79-
from .metadata import __license__
80-
from .metadata import __url__
81-
from .metadata import __version__
71+
from .metadata import (
72+
__about__,
73+
__author__,
74+
__docs__,
75+
__email__,
76+
__license__,
77+
__url__,
78+
__version__,
79+
)
8280

8381
__all__ = [mod for mod in dir() if not mod.startswith("_")] # type: ignore

aiobungie/api/framework.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,23 @@
3434
from sain import Iterator
3535

3636
from aiobungie import typedefs
37-
from aiobungie.crates import activity
38-
from aiobungie.crates import application
39-
from aiobungie.crates import character
40-
from aiobungie.crates import clans
41-
from aiobungie.crates import components
42-
from aiobungie.crates import entity
43-
from aiobungie.crates import fireteams
44-
from aiobungie.crates import friends
45-
from aiobungie.crates import items
46-
from aiobungie.crates import milestones
47-
from aiobungie.crates import profile
48-
from aiobungie.crates import progressions
49-
from aiobungie.crates import records
50-
from aiobungie.crates import season
51-
from aiobungie.crates import user
37+
from aiobungie.crates import (
38+
activity,
39+
application,
40+
character,
41+
clans,
42+
components,
43+
entity,
44+
fireteams,
45+
friends,
46+
items,
47+
milestones,
48+
profile,
49+
progressions,
50+
records,
51+
season,
52+
user,
53+
)
5254

5355

5456
class Framework(abc.ABC):

aiobungie/api/rest.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,16 @@
3434
import typing
3535

3636
from aiobungie import traits
37-
from aiobungie.internal import enums
38-
from aiobungie.internal import helpers
37+
from aiobungie.internal import enums, helpers
3938

4039
if typing.TYPE_CHECKING:
4140
import concurrent.futures
4241
import types
4342

4443
from typing_extensions import Self
4544

46-
from aiobungie import builders
47-
from aiobungie import typedefs
48-
from aiobungie.crates import clans
49-
from aiobungie.crates import fireteams
45+
from aiobungie import builders, typedefs
46+
from aiobungie.crates import clans, fireteams
5047

5148
_ALLOWED_LANGS = typing.Literal[
5249
"en",

aiobungie/builders.py

Lines changed: 63 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
from __future__ import annotations
2525

26-
__all__ = ("OAuth2Response", "PlugSocketBuilder", "OAuthURL", "Image")
26+
__all__ = ("OAuth2Response", "PlugSocketBuilder", "OAuthURL", "Image", "Settings")
2727

2828
import asyncio
2929
import datetime
@@ -35,22 +35,19 @@
3535
import aiohttp
3636
import attrs
3737

38-
from . import error
39-
from . import url
40-
from .internal import enums
41-
from .internal import helpers
38+
from . import error, url
39+
from .internal import enums, helpers
4240

4341
if typing.TYPE_CHECKING:
4442
import collections.abc as collections
4543
import concurrent.futures
4644
import os
45+
import ssl
4746
import types
4847

49-
from typing_extensions import Required
50-
from typing_extensions import Self
48+
from typing_extensions import Required, Self
5149

52-
from aiobungie import traits
53-
from aiobungie import typedefs
50+
from aiobungie import traits, typedefs
5451

5552
class _FinderListingValue(typing.TypedDict):
5653
valueType: Required[int]
@@ -62,6 +59,49 @@ class _ListingFilter(typing.TypedDict):
6259
matchType: int
6360

6461

62+
@typing.final
63+
@attrs.define(kw_only=True)
64+
class Settings:
65+
"""Basic settings used within aiobungie HTTP clients."""
66+
67+
http_timeout: aiohttp.ClientTimeout = attrs.field(
68+
default=aiohttp.ClientTimeout(30.0)
69+
)
70+
"""Setting to control HTTP request timeouts, This includes
71+
the time it takes to acquire the client,
72+
timeout for connecting and reading the socket, and more.
73+
74+
Defaults to total of `30.0` seconds.
75+
"""
76+
77+
trust_env: bool = attrs.field(default=False)
78+
"""Trust environment settings for proxy configuration.
79+
80+
Gets proxy credentials from `~/.netrc` file if present or
81+
Gets HTTP Basic Auth credentials from `~/.netrc` file if present.
82+
83+
If `NETRC` environment variable is set, read from file specified
84+
there rather than from `~/.netrc`.
85+
"""
86+
87+
auth: aiohttp.BasicAuth | None = attrs.field(default=None)
88+
"""an object that represents HTTP Basic Authorization, Defaults to `None`."""
89+
90+
headers: collections.Mapping[str, typing.Any] | None = attrs.field(default=None)
91+
"""Default HTTP headers to send the request with, Defaults to `None`."""
92+
93+
use_dns_cache: bool = attrs.field(default=True)
94+
"""References [use_dns_cache](https://docs.aiohttp.org/en/stable/client_reference.html#aiohttp.TCPConnector)"""
95+
ttl_dns_cache: int = attrs.field(default=10)
96+
"""References [ttl_dns_cache](https://docs.aiohttp.org/en/stable/client_reference.html#aiohttp.TCPConnector)"""
97+
verify_ssl: bool = attrs.field(default=True)
98+
"""References [verify_ssl](https://docs.aiohttp.org/en/stable/client_reference.html#aiohttp.TCPConnector)"""
99+
ssl_context: ssl.SSLContext | None = attrs.field(default=None)
100+
"""References [ssl_context](https://docs.aiohttp.org/en/stable/client_reference.html#aiohttp.TCPConnector)"""
101+
ssl: bool | aiohttp.Fingerprint | ssl.SSLContext = attrs.field(default=True)
102+
"""References [ssl](https://docs.aiohttp.org/en/stable/client_reference.html#aiohttp.TCPConnector)"""
103+
104+
65105
@typing.final
66106
class MimeType(str, enums.Enum):
67107
"""Image mime types enum."""
@@ -82,7 +122,9 @@ def _open_write_path(path: pathlib.Path) -> typing.BinaryIO:
82122

83123
@typing.final
84124
class Image:
85-
"""A stream-able Bungie resource.
125+
"""A streamable Bungie resource.
126+
127+
Images are _lazy_, which mean they do nothing unless you `await` or poll them.
86128
87129
Example
88130
-------
@@ -171,7 +213,7 @@ def create_url(self) -> str:
171213
"""
172214
return url.BASE + "/" + self.path
173215

174-
async def static_request(self) -> aiohttp.ClientResponse:
216+
async def _static_request(self) -> aiohttp.ClientResponse:
175217
client_session = aiohttp.ClientSession()
176218
request = client_session.request(
177219
"GET", self.create_url(), raise_for_status=False
@@ -200,7 +242,7 @@ async def save(
200242
file_name: str,
201243
path: str | os.PathLike[str],
202244
*,
203-
mime_type: MimeType | str = MimeType.JPEG,
245+
mime_type: MimeType | str = MimeType.PNG,
204246
executor: concurrent.futures.Executor | None = None,
205247
) -> None:
206248
"""Saves this image to a file.
@@ -239,7 +281,7 @@ async def save(
239281
loop = helpers.get_or_make_loop()
240282
file = await loop.run_in_executor(executor, _open_write_path, path)
241283

242-
reader = await self.static_request()
284+
reader = await self._static_request()
243285
try:
244286
async for chunk in reader.content:
245287
await loop.run_in_executor(executor, file.write, chunk)
@@ -268,7 +310,7 @@ async def read(self) -> bytes:
268310
`bytes`:
269311
The bytes of this image.
270312
"""
271-
return await (await self.static_request()).read()
313+
return await (await self._static_request()).read()
272314

273315
async def stream(self) -> aiohttp.streams.AsyncStreamIterator[bytes]:
274316
"""Stream this image's data.
@@ -287,17 +329,16 @@ async def stream(self) -> aiohttp.streams.AsyncStreamIterator[bytes]:
287329
Returns
288330
-------
289331
`AsyncStreamIterator[bytes]`:
290-
A lazy async iterator that is ready in memory.
332+
A streaming iterator of this image bytes, yielding the entire data as soon as its received.
291333
"""
292-
return (await self.static_request()).content.iter_any()
334+
return (await self._static_request()).content.iter_any()
293335

294-
async def chunks(self, size: int) -> aiohttp.streams.AsyncStreamIterator[bytes]:
295-
"""Stream this image's data in chunks.
336+
async def chunks(self, n: int) -> aiohttp.streams.AsyncStreamIterator[bytes]:
337+
"""Stream the bytes of this image in `n` chunks.
296338
297339
Example
298340
-------
299341
```py
300-
# it must be awaited to fetch the image first.
301342
buffer_size = 1024
302343
image = Image.default()
303344
@@ -313,9 +354,9 @@ async def chunks(self, size: int) -> aiohttp.streams.AsyncStreamIterator[bytes]:
313354
Returns
314355
-------
315356
`AsyncStreamIterator[bytes]`:
316-
lazy async iterator that is ready in memory.
357+
A chunking stream of bytes.
317358
"""
318-
return (await self.static_request()).content.iter_chunked(size)
359+
return (await self._static_request()).content.iter_chunked(n)
319360

320361
async def iter(self) -> collections.AsyncGenerator[bytes, None]:
321362
"""Yield each byte in this image from start to end.
@@ -332,7 +373,7 @@ async def iter(self) -> collections.AsyncGenerator[bytes, None]:
332373
Returns
333374
-------
334375
`collections.AsyncGenerator[bytes, None]`
335-
An async generator that yields this image's bytes.
376+
An async generator that yields this image's bytes from start to end.
336377
"""
337378

338379
reader = await self.chunks(1024)

0 commit comments

Comments
 (0)