asgiref 3.9.0__tar.gz → 3.9.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. {asgiref-3.9.0/asgiref.egg-info → asgiref-3.9.2}/PKG-INFO +1 -1
  2. asgiref-3.9.2/asgiref/__init__.py +1 -0
  3. {asgiref-3.9.0 → asgiref-3.9.2}/asgiref/local.py +14 -15
  4. {asgiref-3.9.0 → asgiref-3.9.2}/asgiref/wsgi.py +2 -2
  5. {asgiref-3.9.0 → asgiref-3.9.2/asgiref.egg-info}/PKG-INFO +1 -1
  6. {asgiref-3.9.0 → asgiref-3.9.2}/tests/test_garbage_collection.py +6 -0
  7. {asgiref-3.9.0 → asgiref-3.9.2}/tests/test_local.py +16 -0
  8. {asgiref-3.9.0 → asgiref-3.9.2}/tox.ini +1 -1
  9. asgiref-3.9.0/asgiref/__init__.py +0 -1
  10. {asgiref-3.9.0 → asgiref-3.9.2}/LICENSE +0 -0
  11. {asgiref-3.9.0 → asgiref-3.9.2}/MANIFEST.in +0 -0
  12. {asgiref-3.9.0 → asgiref-3.9.2}/README.rst +0 -0
  13. {asgiref-3.9.0 → asgiref-3.9.2}/asgiref/compatibility.py +0 -0
  14. {asgiref-3.9.0 → asgiref-3.9.2}/asgiref/current_thread_executor.py +0 -0
  15. {asgiref-3.9.0 → asgiref-3.9.2}/asgiref/py.typed +0 -0
  16. {asgiref-3.9.0 → asgiref-3.9.2}/asgiref/server.py +0 -0
  17. {asgiref-3.9.0 → asgiref-3.9.2}/asgiref/sync.py +0 -0
  18. {asgiref-3.9.0 → asgiref-3.9.2}/asgiref/testing.py +0 -0
  19. {asgiref-3.9.0 → asgiref-3.9.2}/asgiref/timeout.py +0 -0
  20. {asgiref-3.9.0 → asgiref-3.9.2}/asgiref/typing.py +0 -0
  21. {asgiref-3.9.0 → asgiref-3.9.2}/asgiref.egg-info/SOURCES.txt +0 -0
  22. {asgiref-3.9.0 → asgiref-3.9.2}/asgiref.egg-info/dependency_links.txt +0 -0
  23. {asgiref-3.9.0 → asgiref-3.9.2}/asgiref.egg-info/not-zip-safe +0 -0
  24. {asgiref-3.9.0 → asgiref-3.9.2}/asgiref.egg-info/requires.txt +0 -0
  25. {asgiref-3.9.0 → asgiref-3.9.2}/asgiref.egg-info/top_level.txt +0 -0
  26. {asgiref-3.9.0 → asgiref-3.9.2}/setup.cfg +0 -0
  27. {asgiref-3.9.0 → asgiref-3.9.2}/setup.py +0 -0
  28. {asgiref-3.9.0 → asgiref-3.9.2}/tests/test_compatibility.py +0 -0
  29. {asgiref-3.9.0 → asgiref-3.9.2}/tests/test_server.py +0 -0
  30. {asgiref-3.9.0 → asgiref-3.9.2}/tests/test_sync.py +0 -0
  31. {asgiref-3.9.0 → asgiref-3.9.2}/tests/test_sync_contextvars.py +0 -0
  32. {asgiref-3.9.0 → asgiref-3.9.2}/tests/test_testing.py +0 -0
  33. {asgiref-3.9.0 → asgiref-3.9.2}/tests/test_wsgi.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: asgiref
3
- Version: 3.9.0
3
+ Version: 3.9.2
4
4
  Summary: ASGI specs, helper code, and adapters
5
5
  Home-page: https://github.com/django/asgiref/
6
6
  Author: Django Software Foundation
@@ -0,0 +1 @@
1
+ __version__ = "3.9.2"
@@ -2,38 +2,37 @@ import asyncio
2
2
  import contextlib
3
3
  import contextvars
4
4
  import threading
5
- from typing import Any, Union
5
+ from typing import Any, Dict, Union
6
6
 
7
7
 
8
8
  class _CVar:
9
9
  """Storage utility for Local."""
10
10
 
11
11
  def __init__(self) -> None:
12
- self._data: dict[str, contextvars.ContextVar[Any]] = {}
12
+ self._data: "contextvars.ContextVar[Dict[str, Any]]" = contextvars.ContextVar(
13
+ "asgiref.local"
14
+ )
13
15
 
14
- def __getattr__(self, key: str) -> Any:
16
+ def __getattr__(self, key):
17
+ storage_object = self._data.get({})
15
18
  try:
16
- var = self._data[key]
19
+ return storage_object[key]
17
20
  except KeyError:
18
21
  raise AttributeError(f"{self!r} object has no attribute {key!r}")
19
22
 
20
- try:
21
- return var.get()
22
- except LookupError:
23
- raise AttributeError(f"{self!r} object has no attribute {key!r}")
24
-
25
23
  def __setattr__(self, key: str, value: Any) -> None:
26
24
  if key == "_data":
27
25
  return super().__setattr__(key, value)
28
26
 
29
- var = self._data.get(key)
30
- if var is None:
31
- self._data[key] = var = contextvars.ContextVar(key)
32
- var.set(value)
27
+ storage_object = self._data.get({}).copy()
28
+ storage_object[key] = value
29
+ self._data.set(storage_object)
33
30
 
34
31
  def __delattr__(self, key: str) -> None:
35
- if key in self._data:
36
- del self._data[key]
32
+ storage_object = self._data.get({}).copy()
33
+ if key in storage_object:
34
+ del storage_object[key]
35
+ self._data.set(storage_object)
37
36
  else:
38
37
  raise AttributeError(f"{self!r} object has no attribute {key!r}")
39
38
 
@@ -1,4 +1,4 @@
1
- from io import BytesIO
1
+ import sys
2
2
  from tempfile import SpooledTemporaryFile
3
3
 
4
4
  from asgiref.sync import AsyncToSync, sync_to_async
@@ -67,7 +67,7 @@ class WsgiToAsgiInstance:
67
67
  "wsgi.version": (1, 0),
68
68
  "wsgi.url_scheme": scope.get("scheme", "http"),
69
69
  "wsgi.input": body,
70
- "wsgi.errors": BytesIO(),
70
+ "wsgi.errors": sys.stderr,
71
71
  "wsgi.multithread": True,
72
72
  "wsgi.multiprocess": True,
73
73
  "wsgi.run_once": False,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: asgiref
3
- Version: 3.9.0
3
+ Version: 3.9.2
4
4
  Summary: ASGI specs, helper code, and adapters
5
5
  Home-page: https://github.com/django/asgiref/
6
6
  Author: Django Software Foundation
@@ -1,4 +1,7 @@
1
1
  import gc
2
+ import sys
3
+
4
+ import pytest
2
5
 
3
6
  from asgiref.local import Local
4
7
 
@@ -29,6 +32,9 @@ def clean_up_after_garbage_collection_test() -> None:
29
32
  gc.enable()
30
33
 
31
34
 
35
+ @pytest.mark.skipif(
36
+ sys.implementation.name == "pypy", reason="Test relies on CPython GC internals"
37
+ )
32
38
  def test_thread_critical_Local_remove_all_reference_cycles() -> None:
33
39
  try:
34
40
  # given
@@ -375,3 +375,19 @@ async def test_visibility_task() -> None:
375
375
 
376
376
  # Changes should not leak to the caller
377
377
  assert test_local.value == 0
378
+
379
+
380
+ @pytest.mark.asyncio
381
+ async def test_deletion() -> None:
382
+ """Check visibility with asyncio tasks."""
383
+ test_local = Local()
384
+ test_local.value = 123
385
+
386
+ async def _test() -> None:
387
+ # Local is inherited when changing task
388
+ assert test_local.value == 123
389
+ del test_local.value
390
+ assert not hasattr(test_local, "value")
391
+
392
+ await asyncio.create_task(_test())
393
+ assert test_local.value == 123
@@ -1,6 +1,6 @@
1
1
  [tox]
2
2
  envlist =
3
- py{38,39,310,311,312,313}-{test,mypy}
3
+ py{39,310,311,312,313,314}-{test,mypy}
4
4
  qa
5
5
 
6
6
  [testenv]
@@ -1 +0,0 @@
1
- __version__ = "3.9.0"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes