posthoganalytics 6.7.4__tar.gz → 6.7.5__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.
- {posthoganalytics-6.7.4/posthoganalytics.egg-info → posthoganalytics-6.7.5}/PKG-INFO +1 -1
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/integrations/django.py +53 -14
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/version.py +1 -1
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5/posthoganalytics.egg-info}/PKG-INFO +1 -1
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/LICENSE +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/MANIFEST.in +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/README.md +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/__init__.py +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/ai/__init__.py +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/ai/anthropic/__init__.py +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/ai/anthropic/anthropic.py +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/ai/anthropic/anthropic_async.py +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/ai/anthropic/anthropic_converter.py +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/ai/anthropic/anthropic_providers.py +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/ai/gemini/__init__.py +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/ai/gemini/gemini.py +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/ai/gemini/gemini_converter.py +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/ai/langchain/__init__.py +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/ai/langchain/callbacks.py +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/ai/openai/__init__.py +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/ai/openai/openai.py +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/ai/openai/openai_async.py +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/ai/openai/openai_converter.py +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/ai/openai/openai_providers.py +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/ai/sanitization.py +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/ai/types.py +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/ai/utils.py +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/args.py +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/client.py +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/consumer.py +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/contexts.py +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/exception_capture.py +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/exception_utils.py +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/feature_flags.py +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/integrations/__init__.py +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/poller.py +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/py.typed +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/request.py +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/test/__init__.py +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/test/test_before_send.py +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/test/test_client.py +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/test/test_consumer.py +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/test/test_contexts.py +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/test/test_exception_capture.py +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/test/test_feature_flag.py +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/test/test_feature_flag_result.py +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/test/test_feature_flags.py +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/test/test_module.py +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/test/test_request.py +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/test/test_size_limited_dict.py +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/test/test_types.py +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/test/test_utils.py +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/types.py +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/utils.py +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics.egg-info/SOURCES.txt +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics.egg-info/dependency_links.txt +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics.egg-info/requires.txt +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics.egg-info/top_level.txt +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/pyproject.toml +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/setup.cfg +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/setup.py +0 -0
- {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/setup_analytics.py +0 -0
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
from typing import TYPE_CHECKING, cast
|
|
2
|
-
from posthoganalytics import contexts
|
|
2
|
+
from posthoganalytics import contexts
|
|
3
3
|
from posthoganalytics.client import Client
|
|
4
4
|
|
|
5
|
+
try:
|
|
6
|
+
from asgiref.sync import iscoroutinefunction
|
|
7
|
+
except ImportError:
|
|
8
|
+
# Fallback for older Django versions
|
|
9
|
+
import asyncio
|
|
10
|
+
|
|
11
|
+
iscoroutinefunction = asyncio.iscoroutinefunction
|
|
12
|
+
|
|
5
13
|
if TYPE_CHECKING:
|
|
6
14
|
from django.http import HttpRequest, HttpResponse # noqa: F401
|
|
7
|
-
from typing import Callable, Dict, Any, Optional # noqa: F401
|
|
15
|
+
from typing import Callable, Dict, Any, Optional, Union, Awaitable # noqa: F401
|
|
8
16
|
|
|
9
17
|
|
|
10
18
|
class PosthogContextMiddleware:
|
|
@@ -33,9 +41,24 @@ class PosthogContextMiddleware:
|
|
|
33
41
|
frontend. See the documentation for `set_context_session` and `identify_context` for more details.
|
|
34
42
|
"""
|
|
35
43
|
|
|
44
|
+
# Django middleware capability flags
|
|
45
|
+
sync_capable = True
|
|
46
|
+
async_capable = True
|
|
47
|
+
|
|
36
48
|
def __init__(self, get_response):
|
|
37
|
-
# type: (Callable[[HttpRequest], HttpResponse]) -> None
|
|
38
|
-
self.
|
|
49
|
+
# type: (Union[Callable[[HttpRequest], HttpResponse], Callable[[HttpRequest], Awaitable[HttpResponse]]]) -> None
|
|
50
|
+
self._is_coroutine = iscoroutinefunction(get_response)
|
|
51
|
+
self._async_get_response = None # type: Optional[Callable[[HttpRequest], Awaitable[HttpResponse]]]
|
|
52
|
+
self._sync_get_response = None # type: Optional[Callable[[HttpRequest], HttpResponse]]
|
|
53
|
+
|
|
54
|
+
if self._is_coroutine:
|
|
55
|
+
self._async_get_response = cast(
|
|
56
|
+
"Callable[[HttpRequest], Awaitable[HttpResponse]]", get_response
|
|
57
|
+
)
|
|
58
|
+
else:
|
|
59
|
+
self._sync_get_response = cast(
|
|
60
|
+
"Callable[[HttpRequest], HttpResponse]", get_response
|
|
61
|
+
)
|
|
39
62
|
|
|
40
63
|
from django.conf import settings
|
|
41
64
|
|
|
@@ -159,23 +182,39 @@ class PosthogContextMiddleware:
|
|
|
159
182
|
|
|
160
183
|
def __call__(self, request):
|
|
161
184
|
# type: (HttpRequest) -> HttpResponse
|
|
185
|
+
# Purely defensive around django's internal sync/async handling - this should be unreachable, but if it's reached, we may
|
|
186
|
+
# as well return something semi-meaningful
|
|
187
|
+
if self._is_coroutine:
|
|
188
|
+
raise RuntimeError(
|
|
189
|
+
"PosthogContextMiddleware received sync call but get_response is async"
|
|
190
|
+
)
|
|
191
|
+
|
|
162
192
|
if self.request_filter and not self.request_filter(request):
|
|
163
|
-
|
|
193
|
+
assert self._sync_get_response is not None
|
|
194
|
+
return self._sync_get_response(request)
|
|
164
195
|
|
|
165
196
|
with contexts.new_context(self.capture_exceptions, client=self.client):
|
|
166
197
|
for k, v in self.extract_tags(request).items():
|
|
167
198
|
contexts.tag(k, v)
|
|
168
199
|
|
|
169
|
-
|
|
200
|
+
assert self._sync_get_response is not None
|
|
201
|
+
return self._sync_get_response(request)
|
|
170
202
|
|
|
171
|
-
def
|
|
203
|
+
async def __acall__(self, request):
|
|
204
|
+
# type: (HttpRequest) -> HttpResponse
|
|
172
205
|
if self.request_filter and not self.request_filter(request):
|
|
173
|
-
|
|
206
|
+
if self._async_get_response is not None:
|
|
207
|
+
return await self._async_get_response(request)
|
|
208
|
+
else:
|
|
209
|
+
assert self._sync_get_response is not None
|
|
210
|
+
return self._sync_get_response(request)
|
|
174
211
|
|
|
175
|
-
|
|
176
|
-
|
|
212
|
+
with contexts.new_context(self.capture_exceptions, client=self.client):
|
|
213
|
+
for k, v in self.extract_tags(request).items():
|
|
214
|
+
contexts.tag(k, v)
|
|
177
215
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
216
|
+
if self._async_get_response is not None:
|
|
217
|
+
return await self._async_get_response(request)
|
|
218
|
+
else:
|
|
219
|
+
assert self._sync_get_response is not None
|
|
220
|
+
return self._sync_get_response(request)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/ai/anthropic/anthropic.py
RENAMED
|
File without changes
|
{posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/ai/anthropic/anthropic_async.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/ai/gemini/gemini_converter.py
RENAMED
|
File without changes
|
|
File without changes
|
{posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/ai/langchain/callbacks.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/ai/openai/openai_async.py
RENAMED
|
File without changes
|
{posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/ai/openai/openai_converter.py
RENAMED
|
File without changes
|
{posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/ai/openai/openai_providers.py
RENAMED
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/test/test_exception_capture.py
RENAMED
|
File without changes
|
{posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/test/test_feature_flag.py
RENAMED
|
File without changes
|
{posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/test/test_feature_flag_result.py
RENAMED
|
File without changes
|
{posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/test/test_feature_flags.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/test/test_size_limited_dict.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|