pktbin 0.1.0__py3-none-any.whl
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.
- pktbin/__init__.py +130 -0
- pktbin/_capture.py +122 -0
- pktbin/_clients.py +971 -0
- pktbin/_models.py +143 -0
- pktbin/_query/__init__.py +21 -0
- pktbin/_query/_dsl.py +1083 -0
- pktbin/_query/_fields.py +7447 -0
- pktbin/_requests.py +921 -0
- pktbin/_responses.py +234 -0
- pktbin/_session.py +866 -0
- pktbin/_sse.py +41 -0
- pktbin/_version.py +3 -0
- pktbin/exceptions.py +44 -0
- pktbin/py.typed +0 -0
- pktbin-0.1.0.dist-info/METADATA +267 -0
- pktbin-0.1.0.dist-info/RECORD +18 -0
- pktbin-0.1.0.dist-info/WHEEL +4 -0
- pktbin-0.1.0.dist-info/licenses/LICENSE +21 -0
pktbin/__init__.py
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
from ._clients import AsyncClient, SyncClient as Client
|
|
2
|
+
from ._capture import async_capture, capture
|
|
3
|
+
from ._session import AsyncCaptureSession, CaptureSession
|
|
4
|
+
from ._models import Capture, CaptureUrls, Url, Visibility
|
|
5
|
+
from ._responses import (
|
|
6
|
+
CaptureResponse,
|
|
7
|
+
Route,
|
|
8
|
+
SseEvent,
|
|
9
|
+
SseResponse,
|
|
10
|
+
TlsResponse,
|
|
11
|
+
WebSocketClose,
|
|
12
|
+
WebSocketResponse,
|
|
13
|
+
WebTransportResponse,
|
|
14
|
+
)
|
|
15
|
+
from ._requests import (
|
|
16
|
+
Body,
|
|
17
|
+
Connection,
|
|
18
|
+
ConnectionDetails,
|
|
19
|
+
ConnectionEnding,
|
|
20
|
+
DnsQuery,
|
|
21
|
+
GrpcCall,
|
|
22
|
+
Handshake,
|
|
23
|
+
HttpRequest,
|
|
24
|
+
Message,
|
|
25
|
+
MessageCounts,
|
|
26
|
+
MongoDbConnection,
|
|
27
|
+
KafkaConnection,
|
|
28
|
+
SocksConnection,
|
|
29
|
+
MqttConnection,
|
|
30
|
+
MysqlLogin,
|
|
31
|
+
OtherRequest,
|
|
32
|
+
Outcome,
|
|
33
|
+
Part,
|
|
34
|
+
PostgresLogin,
|
|
35
|
+
RedisConnection,
|
|
36
|
+
Request,
|
|
37
|
+
RequestClient,
|
|
38
|
+
RequestDetails,
|
|
39
|
+
SmtpSession,
|
|
40
|
+
SshLogin,
|
|
41
|
+
Status,
|
|
42
|
+
StunRequest,
|
|
43
|
+
Tls,
|
|
44
|
+
WebSocketSession,
|
|
45
|
+
WebTransportSession,
|
|
46
|
+
)
|
|
47
|
+
from . import exceptions
|
|
48
|
+
from .exceptions import (
|
|
49
|
+
PktbinApiError,
|
|
50
|
+
PktbinBadRequestError,
|
|
51
|
+
PktbinConnectionError,
|
|
52
|
+
PktbinError,
|
|
53
|
+
PktbinNoMatchError,
|
|
54
|
+
PktbinNotFoundError,
|
|
55
|
+
PktbinPermissionError,
|
|
56
|
+
PktbinRateLimitWarning,
|
|
57
|
+
PktbinTimeoutError,
|
|
58
|
+
)
|
|
59
|
+
from ._query import Expression, F, Field, FieldT, Fn, Query
|
|
60
|
+
from ._version import version
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
__all__ = [
|
|
64
|
+
"AsyncClient",
|
|
65
|
+
"AsyncCaptureSession",
|
|
66
|
+
"async_capture",
|
|
67
|
+
"Client",
|
|
68
|
+
"Capture",
|
|
69
|
+
"CaptureResponse",
|
|
70
|
+
"CaptureSession",
|
|
71
|
+
"capture",
|
|
72
|
+
"exceptions",
|
|
73
|
+
"PktbinApiError",
|
|
74
|
+
"PktbinBadRequestError",
|
|
75
|
+
"PktbinConnectionError",
|
|
76
|
+
"PktbinError",
|
|
77
|
+
"PktbinNoMatchError",
|
|
78
|
+
"PktbinNotFoundError",
|
|
79
|
+
"PktbinPermissionError",
|
|
80
|
+
"PktbinRateLimitWarning",
|
|
81
|
+
"PktbinTimeoutError",
|
|
82
|
+
"Expression",
|
|
83
|
+
"F",
|
|
84
|
+
"Field",
|
|
85
|
+
"FieldT",
|
|
86
|
+
"Fn",
|
|
87
|
+
"Query",
|
|
88
|
+
"Url",
|
|
89
|
+
"CaptureUrls",
|
|
90
|
+
"Visibility",
|
|
91
|
+
"Route",
|
|
92
|
+
"SseEvent",
|
|
93
|
+
"SseResponse",
|
|
94
|
+
"TlsResponse",
|
|
95
|
+
"WebSocketClose",
|
|
96
|
+
"WebSocketResponse",
|
|
97
|
+
"WebTransportResponse",
|
|
98
|
+
"Body",
|
|
99
|
+
"Connection",
|
|
100
|
+
"ConnectionDetails",
|
|
101
|
+
"ConnectionEnding",
|
|
102
|
+
"DnsQuery",
|
|
103
|
+
"GrpcCall",
|
|
104
|
+
"Handshake",
|
|
105
|
+
"HttpRequest",
|
|
106
|
+
"Message",
|
|
107
|
+
"MessageCounts",
|
|
108
|
+
"MongoDbConnection",
|
|
109
|
+
"KafkaConnection",
|
|
110
|
+
"SocksConnection",
|
|
111
|
+
"MqttConnection",
|
|
112
|
+
"MysqlLogin",
|
|
113
|
+
"OtherRequest",
|
|
114
|
+
"Outcome",
|
|
115
|
+
"Part",
|
|
116
|
+
"PostgresLogin",
|
|
117
|
+
"RedisConnection",
|
|
118
|
+
"Request",
|
|
119
|
+
"RequestClient",
|
|
120
|
+
"RequestDetails",
|
|
121
|
+
"SmtpSession",
|
|
122
|
+
"SshLogin",
|
|
123
|
+
"Status",
|
|
124
|
+
"StunRequest",
|
|
125
|
+
"Tls",
|
|
126
|
+
"WebSocketSession",
|
|
127
|
+
"WebTransportSession",
|
|
128
|
+
]
|
|
129
|
+
|
|
130
|
+
__version__ = version
|
pktbin/_capture.py
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import datetime
|
|
2
|
+
import warnings
|
|
3
|
+
from typing import Any
|
|
4
|
+
from collections.abc import AsyncGenerator, Callable, Generator
|
|
5
|
+
from contextlib import asynccontextmanager, contextmanager
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
from ._clients import AsyncClient, SyncClient
|
|
9
|
+
from ._responses import CaptureResponse
|
|
10
|
+
from ._session import AsyncCaptureSession, CaptureSession
|
|
11
|
+
from .exceptions import PktbinError
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@contextmanager
|
|
15
|
+
def capture(
|
|
16
|
+
ttl: datetime.timedelta | None = None,
|
|
17
|
+
*,
|
|
18
|
+
name: str | None = None,
|
|
19
|
+
region: str | None = None,
|
|
20
|
+
response: CaptureResponse | None = None,
|
|
21
|
+
delete: bool = False,
|
|
22
|
+
timeout: float | None = None,
|
|
23
|
+
**httpx_options: Any,
|
|
24
|
+
) -> Generator[CaptureSession, None, None]:
|
|
25
|
+
"""Creates a capture with its own client.
|
|
26
|
+
|
|
27
|
+
When the `with` block ends, the client closes. The capture stays until it expires,
|
|
28
|
+
so you can open it on pktbin.com afterwards, unless `delete` is true. To create many
|
|
29
|
+
captures, use one `Client`, which shares its connections.
|
|
30
|
+
|
|
31
|
+
Args:
|
|
32
|
+
ttl: The time until the capture expires. The default is one hour. The maximum is
|
|
33
|
+
one day.
|
|
34
|
+
name: The name of the capture. All readers of the capture see it.
|
|
35
|
+
region: Where pktbin creates the capture, for example `"de"`. If not given,
|
|
36
|
+
the default region.
|
|
37
|
+
response: What pktbin sends back to the traffic of the capture.
|
|
38
|
+
delete: If true, the capture is deleted when the block ends. If deleting fails
|
|
39
|
+
after the block raised, the client warns rather than hide the block's
|
|
40
|
+
error.
|
|
41
|
+
timeout: The HTTP timeout in seconds. The default is 30.
|
|
42
|
+
**httpx_options: Options for the `httpx.AsyncClient`, for example `proxy` or
|
|
43
|
+
`headers`.
|
|
44
|
+
|
|
45
|
+
Yields:
|
|
46
|
+
A session for the new capture.
|
|
47
|
+
"""
|
|
48
|
+
with SyncClient(timeout=timeout, **httpx_options) as client:
|
|
49
|
+
session = client.create_capture(
|
|
50
|
+
ttl, region=region, response=response, name=name
|
|
51
|
+
)
|
|
52
|
+
try:
|
|
53
|
+
yield session
|
|
54
|
+
except BaseException:
|
|
55
|
+
if delete:
|
|
56
|
+
_delete_quietly(session.delete, session.id)
|
|
57
|
+
raise
|
|
58
|
+
if delete:
|
|
59
|
+
session.delete()
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@asynccontextmanager
|
|
63
|
+
async def async_capture(
|
|
64
|
+
ttl: datetime.timedelta | None = None,
|
|
65
|
+
*,
|
|
66
|
+
name: str | None = None,
|
|
67
|
+
region: str | None = None,
|
|
68
|
+
response: CaptureResponse | None = None,
|
|
69
|
+
delete: bool = False,
|
|
70
|
+
timeout: float | None = None,
|
|
71
|
+
**httpx_options: Any,
|
|
72
|
+
) -> AsyncGenerator[AsyncCaptureSession, None]:
|
|
73
|
+
"""Creates a capture with its own async client.
|
|
74
|
+
|
|
75
|
+
When the `async with` block ends, the client closes. The capture stays until it
|
|
76
|
+
expires, so you can open it on pktbin.com afterwards, unless `delete` is true. To
|
|
77
|
+
create many captures, use one `AsyncClient`, which shares its connections.
|
|
78
|
+
|
|
79
|
+
Args:
|
|
80
|
+
ttl: The time until the capture expires. The default is one hour. The maximum is
|
|
81
|
+
one day.
|
|
82
|
+
name: The name of the capture. All readers of the capture see it.
|
|
83
|
+
region: Where pktbin creates the capture, for example `"de"`. If not given,
|
|
84
|
+
the default region.
|
|
85
|
+
response: What pktbin sends back to the traffic of the capture.
|
|
86
|
+
delete: If true, the capture is deleted when the block ends. If deleting fails
|
|
87
|
+
after the block raised, the client warns rather than hide the block's
|
|
88
|
+
error.
|
|
89
|
+
timeout: The HTTP timeout in seconds. The default is 30.
|
|
90
|
+
**httpx_options: Options for the `httpx.AsyncClient`, for example `proxy` or
|
|
91
|
+
`headers`.
|
|
92
|
+
|
|
93
|
+
Yields:
|
|
94
|
+
A session for the new capture.
|
|
95
|
+
"""
|
|
96
|
+
async with AsyncClient(timeout=timeout, **httpx_options) as client:
|
|
97
|
+
session = await client.create_capture(
|
|
98
|
+
ttl, region=region, response=response, name=name
|
|
99
|
+
)
|
|
100
|
+
try:
|
|
101
|
+
yield session
|
|
102
|
+
except BaseException:
|
|
103
|
+
if delete:
|
|
104
|
+
await _adelete_quietly(session)
|
|
105
|
+
raise
|
|
106
|
+
if delete:
|
|
107
|
+
await session.delete()
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def _delete_quietly(delete: Callable[[], None], capture_id: str) -> None:
|
|
111
|
+
"""Deletes a capture while an error is raised, which a failure must not hide."""
|
|
112
|
+
try:
|
|
113
|
+
delete()
|
|
114
|
+
except PktbinError as e:
|
|
115
|
+
warnings.warn(f"Couldn't delete capture {capture_id}: {e}", stacklevel=4)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
async def _adelete_quietly(session: AsyncCaptureSession) -> None:
|
|
119
|
+
try:
|
|
120
|
+
await session.delete()
|
|
121
|
+
except PktbinError as e:
|
|
122
|
+
warnings.warn(f"Couldn't delete capture {session.id}: {e}", stacklevel=4)
|