Compare commits
No commits in common. "main" and "v0.1.3" have entirely different histories.
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,5 +1,5 @@
|
|||||||
# claude
|
# claude
|
||||||
.claude/
|
CLAUDE.md
|
||||||
|
|
||||||
# python
|
# python
|
||||||
__pycache__/
|
__pycache__/
|
||||||
|
|||||||
@ -11,19 +11,17 @@ and swap the HTTP client while inheriting everything else.
|
|||||||
`requirements.txt`:
|
`requirements.txt`:
|
||||||
|
|
||||||
```
|
```
|
||||||
aioweb @ git+ssh://git@git.rethinkstudios.io/rethink-public/aioweb.git@v0.1.5
|
aioweb @ git+ssh://git@git.rethinkstudios.io/rethink-public/aioweb.git@v0.1.3
|
||||||
```
|
```
|
||||||
|
|
||||||
Direct:
|
Direct:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pip install "aioweb @ git+ssh://git@git.rethinkstudios.io/rethink-public/aioweb.git@v0.1.5"
|
pip install "aioweb @ git+ssh://git@git.rethinkstudios.io/rethink-public/aioweb.git@v0.1.3"
|
||||||
```
|
```
|
||||||
|
|
||||||
Requires `aiohttp` and `yarl` (pulled transitively).
|
Requires `aiohttp` and `yarl` (pulled transitively).
|
||||||
|
|
||||||
Drop the `@v0.1.5` suffix from the line above to install the latest unpinned.
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```python
|
```python
|
||||||
@ -149,4 +147,4 @@ Two changes can't be shimmed without re-introducing the bugs they fix:
|
|||||||
|
|
||||||
## Versioning
|
## Versioning
|
||||||
|
|
||||||
Releases are tagged `vX.Y.Z`. The install line above pins a release; drop the `@vX.Y.Z` suffix to install the latest unpinned. Pin deliberately for reproducible installs.
|
Tagged `vX.Y.Z`. Pin the tag in `requirements.txt`.
|
||||||
|
|||||||
@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "aioweb"
|
name = "aioweb"
|
||||||
version = "0.1.5"
|
version = "0.1.3"
|
||||||
description = "Async HTTP session wrapper over aiohttp — proxies, header overwrites, retries, previews. Config-free, installable."
|
description = "Async HTTP session wrapper over aiohttp — proxies, header overwrites, retries, previews. Config-free, installable."
|
||||||
requires-python = ">=3.10"
|
requires-python = ">=3.10"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
|||||||
@ -35,11 +35,9 @@ class RequestPreview:
|
|||||||
parts = [f"curl -X {shlex.quote(self.details['method'])}"]
|
parts = [f"curl -X {shlex.quote(self.details['method'])}"]
|
||||||
for header, value in (self.details["headers"] or {}).items():
|
for header, value in (self.details["headers"] or {}).items():
|
||||||
parts.append(f"-H {shlex.quote(f'{header}: {value}')}")
|
parts.append(f"-H {shlex.quote(f'{header}: {value}')}")
|
||||||
if self.details["data"] is not None:
|
if self.details["data"]:
|
||||||
parts.append(f"--data {shlex.quote(str(self.details['data']))}")
|
parts.append(f"--data {shlex.quote(str(self.details['data']))}")
|
||||||
elif self.details["json"] is not None:
|
elif self.details["json"]:
|
||||||
# is-not-None, not truthiness: an empty-but-valid body ({} / []) must still
|
|
||||||
# render rather than being dropped as falsy
|
|
||||||
parts.append(f"--data {shlex.quote(_json.dumps(self.details['json']))}")
|
parts.append(f"--data {shlex.quote(_json.dumps(self.details['json']))}")
|
||||||
parts.append(shlex.quote(str(self.details["url"])))
|
parts.append(shlex.quote(str(self.details["url"])))
|
||||||
if self.details["proxy"]:
|
if self.details["proxy"]:
|
||||||
|
|||||||
@ -92,9 +92,7 @@ class Response:
|
|||||||
"""parsed JSON content, or None if not valid JSON"""
|
"""parsed JSON content, or None if not valid JSON"""
|
||||||
try:
|
try:
|
||||||
return _json.loads(self.text())
|
return _json.loads(self.text())
|
||||||
except (_json.JSONDecodeError, UnicodeDecodeError):
|
except _json.JSONDecodeError:
|
||||||
# text() decodes the body and can raise UnicodeDecodeError on a non-UTF-8
|
|
||||||
# payload — that's a "not valid JSON" outcome, not an error to propagate
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def raise_for_status(self):
|
def raise_for_status(self):
|
||||||
|
|||||||
@ -124,13 +124,10 @@ class ExtendedSession:
|
|||||||
def _apply_overwrites(self, request_headers):
|
def _apply_overwrites(self, request_headers):
|
||||||
"""apply static overwrites and ephemeral headers to a request's headers"""
|
"""apply static overwrites and ephemeral headers to a request's headers"""
|
||||||
request_headers = dict(request_headers or {})
|
request_headers = dict(request_headers or {})
|
||||||
# snapshot the shared override dicts so a concurrent mutation (e.g. a command
|
for header, value in self.header_overwrites.items():
|
||||||
# editing ephemerals on a shared session) can't raise "dict changed size during
|
|
||||||
# iteration" — the loop body is sync, but the snapshot is cheap insurance
|
|
||||||
for header, value in list(self.header_overwrites.items()):
|
|
||||||
if self.inject or header in request_headers:
|
if self.inject or header in request_headers:
|
||||||
request_headers[header] = value
|
request_headers[header] = value
|
||||||
for header, value_callable in list(self.ephemeral_headers.items()):
|
for header, value_callable in self.ephemeral_headers.items():
|
||||||
if self.inject or header in request_headers:
|
if self.inject or header in request_headers:
|
||||||
value = value_callable()
|
value = value_callable()
|
||||||
if isinstance(value, dict):
|
if isinstance(value, dict):
|
||||||
@ -316,13 +313,10 @@ class ExtendedSession:
|
|||||||
if debug and result.redirect_chain:
|
if debug and result.redirect_chain:
|
||||||
log.info("redirect chain: %s", result.redirect_chain)
|
log.info("redirect chain: %s", result.redirect_chain)
|
||||||
return result
|
return result
|
||||||
except asyncio.TimeoutError as error:
|
except (aiohttp.ClientError, asyncio.TimeoutError) as error:
|
||||||
# a total ClientTimeout raises a bare asyncio.TimeoutError, which is NOT an
|
# a total ClientTimeout raises a bare asyncio.TimeoutError, which is NOT an
|
||||||
# aiohttp.ClientError subclass — wrap it as ServerTimeoutError (which IS both
|
# aiohttp.ClientError subclass — wrap it into the same typed path so direct
|
||||||
# a ClientError AND a TimeoutError) so direct callers get a typed failure and
|
# callers get a consistent failure instead of a raw timeout
|
||||||
# request_with_retries can still label it a timeout
|
|
||||||
raise aiohttp.ServerTimeoutError(f"timeout for {url}: {error}") from error
|
|
||||||
except aiohttp.ClientError as error:
|
|
||||||
raise aiohttp.ClientError(f"client error for {url}: {error}") from error
|
raise aiohttp.ClientError(f"client error for {url}: {error}") from error
|
||||||
|
|
||||||
async def request_with_retries(
|
async def request_with_retries(
|
||||||
@ -367,12 +361,6 @@ class ExtendedSession:
|
|||||||
log.error("all %d attempts failed for %s (last status %s)",
|
log.error("all %d attempts failed for %s (last status %s)",
|
||||||
attempts, url, exhausted.response.status_code)
|
attempts, url, exhausted.response.status_code)
|
||||||
return exhausted.response
|
return exhausted.response
|
||||||
except asyncio.TimeoutError:
|
|
||||||
# request() wraps a total timeout as ServerTimeoutError (a ClientError AND a
|
|
||||||
# TimeoutError); catch the timeout case first so it's labeled a timeout rather
|
|
||||||
# than falling into the generic client-error branch below
|
|
||||||
log.error("all %d attempts timed out for %s", attempts, url)
|
|
||||||
return FailureResponse(reason="timeout", url=url)
|
|
||||||
except aiohttp.ClientError as error:
|
except aiohttp.ClientError as error:
|
||||||
log.error("all %d attempts failed for %s (client error: %s)", attempts, url, error)
|
log.error("all %d attempts failed for %s (client error: %s)", attempts, url, error)
|
||||||
return FailureResponse(reason=f"client error: {error}", url=url)
|
return FailureResponse(reason=f"client error: {error}", url=url)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user