chasky-botsmith-sdk 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.
- chasky_botsmith/__init__.py +73 -0
- chasky_botsmith/bot.py +205 -0
- chasky_botsmith/client.py +200 -0
- chasky_botsmith/errors.py +59 -0
- chasky_botsmith/polling.py +116 -0
- chasky_botsmith/redact.py +44 -0
- chasky_botsmith/types.py +113 -0
- chasky_botsmith_sdk-0.1.0.dist-info/METADATA +74 -0
- chasky_botsmith_sdk-0.1.0.dist-info/RECORD +11 -0
- chasky_botsmith_sdk-0.1.0.dist-info/WHEEL +4 -0
- chasky_botsmith_sdk-0.1.0.dist-info/licenses/LICENSE +202 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"""Client SDK for the Chasky Bot API.
|
|
2
|
+
|
|
3
|
+
This is a port of the contract in ../docs/00-spec.md, not of the TypeScript SDK.
|
|
4
|
+
The guarantees (G1-G9) and delegations (L1-L5) are identical and the shared
|
|
5
|
+
conformance suite verifies that; the shape is Python's — asyncio, exceptions,
|
|
6
|
+
decorators, snake_case.
|
|
7
|
+
|
|
8
|
+
Basic use::
|
|
9
|
+
|
|
10
|
+
bot = Bot(token=os.environ["CHASKY_BOT_TOKEN"])
|
|
11
|
+
|
|
12
|
+
@bot.command("start")
|
|
13
|
+
async def start(event: Event) -> None:
|
|
14
|
+
await event.reply("Hello.")
|
|
15
|
+
|
|
16
|
+
@bot.on_text
|
|
17
|
+
async def echo(event: Event) -> None:
|
|
18
|
+
await event.reply(f"You said: {event.message.text}")
|
|
19
|
+
|
|
20
|
+
await bot.run()
|
|
21
|
+
|
|
22
|
+
Three things the contract insists on, because they are what a hand-written
|
|
23
|
+
client gets wrong:
|
|
24
|
+
|
|
25
|
+
* Exactly one process may poll a bot. Starting a second one evicts the first,
|
|
26
|
+
which then receives 409 CONFLICT_POLLING and stops.
|
|
27
|
+
* The offset always advances, even past an update whose handler raised. It is a
|
|
28
|
+
read cursor, not a business acknowledgement.
|
|
29
|
+
* The token travels in the URL path, so it leaks into transport errors. Every
|
|
30
|
+
exception this package raises has been redacted first.
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
from .bot import Bot, Event, Handler
|
|
34
|
+
from .client import (
|
|
35
|
+
DEFAULT_BASE_URL,
|
|
36
|
+
MAX_LIMIT,
|
|
37
|
+
MAX_TIMEOUT_SECONDS,
|
|
38
|
+
Client,
|
|
39
|
+
)
|
|
40
|
+
from .errors import APIError, ChaskyError, TransportError, UsageError
|
|
41
|
+
from .polling import Polling, Transport
|
|
42
|
+
from .types import (
|
|
43
|
+
BotIdentity,
|
|
44
|
+
BotMessage,
|
|
45
|
+
Chat,
|
|
46
|
+
ChatAction,
|
|
47
|
+
Update,
|
|
48
|
+
User,
|
|
49
|
+
WebhookInfo,
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
__all__ = [
|
|
53
|
+
"APIError",
|
|
54
|
+
"Bot",
|
|
55
|
+
"BotIdentity",
|
|
56
|
+
"BotMessage",
|
|
57
|
+
"ChaskyError",
|
|
58
|
+
"Chat",
|
|
59
|
+
"ChatAction",
|
|
60
|
+
"Client",
|
|
61
|
+
"DEFAULT_BASE_URL",
|
|
62
|
+
"Event",
|
|
63
|
+
"Handler",
|
|
64
|
+
"MAX_LIMIT",
|
|
65
|
+
"MAX_TIMEOUT_SECONDS",
|
|
66
|
+
"Polling",
|
|
67
|
+
"Transport",
|
|
68
|
+
"TransportError",
|
|
69
|
+
"Update",
|
|
70
|
+
"UsageError",
|
|
71
|
+
"User",
|
|
72
|
+
"WebhookInfo",
|
|
73
|
+
]
|
chasky_botsmith/bot.py
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
"""The runtime: handlers, dispatch, and a managed Idempotency-Key."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
import uuid
|
|
7
|
+
from dataclasses import dataclass, field
|
|
8
|
+
from typing import Awaitable, Callable
|
|
9
|
+
|
|
10
|
+
import httpx
|
|
11
|
+
|
|
12
|
+
from .client import Client
|
|
13
|
+
from .errors import UsageError, classify
|
|
14
|
+
from .polling import Polling, Transport, TransportDeps, _backoff
|
|
15
|
+
from .types import BotMessage, ChatID, MessageID, Update
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@dataclass(slots=True)
|
|
19
|
+
class Event:
|
|
20
|
+
"""One update delivered to a handler, with the shortcuts to answer it."""
|
|
21
|
+
|
|
22
|
+
update: Update
|
|
23
|
+
message: BotMessage
|
|
24
|
+
chat_id: ChatID
|
|
25
|
+
client: Client
|
|
26
|
+
_attempts: int = field(repr=False, default=4)
|
|
27
|
+
_on_error: Callable[[BaseException], None] = field(repr=False, default=lambda _e: None)
|
|
28
|
+
|
|
29
|
+
async def reply(self, text: str, *, reply_to_message_id: MessageID | None = None) -> BotMessage:
|
|
30
|
+
"""Send to this update's chat with a managed Idempotency-Key."""
|
|
31
|
+
return await _send_with_retry(
|
|
32
|
+
self.client,
|
|
33
|
+
# G9: the chat id goes back exactly as it arrived. Never parsed,
|
|
34
|
+
# never rebuilt — a real chat id carries "bot:" twice, and anything
|
|
35
|
+
# that takes it apart breaks against a live server.
|
|
36
|
+
chat_id=self.chat_id,
|
|
37
|
+
text=text,
|
|
38
|
+
reply_to_message_id=reply_to_message_id,
|
|
39
|
+
attempts=self._attempts,
|
|
40
|
+
on_error=self._on_error,
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
async def typing(self) -> None:
|
|
44
|
+
"""Explicit on purpose: the runtime never sends a chat action itself.
|
|
45
|
+
|
|
46
|
+
Whether the indicator helps depends on how long the bot takes to
|
|
47
|
+
answer, which is the author's call and not the SDK's.
|
|
48
|
+
"""
|
|
49
|
+
await self.client.send_chat_action(chat_id=self.chat_id)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
Handler = Callable[[Event], Awaitable[None]]
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class Bot:
|
|
56
|
+
def __init__(
|
|
57
|
+
self,
|
|
58
|
+
token: str,
|
|
59
|
+
*,
|
|
60
|
+
base_url: str | None = None,
|
|
61
|
+
transport: Transport | None = None,
|
|
62
|
+
send_attempts: int = 4,
|
|
63
|
+
http: httpx.AsyncClient | None = None,
|
|
64
|
+
on_warning: Callable[[str], None] | None = None,
|
|
65
|
+
allow_insecure_transport: bool = False,
|
|
66
|
+
) -> None:
|
|
67
|
+
self.client = Client(
|
|
68
|
+
token,
|
|
69
|
+
base_url=base_url,
|
|
70
|
+
http=http,
|
|
71
|
+
on_warning=on_warning,
|
|
72
|
+
allow_insecure_transport=allow_insecure_transport,
|
|
73
|
+
)
|
|
74
|
+
self._transport = transport or Polling()
|
|
75
|
+
self._attempts = send_attempts
|
|
76
|
+
self._commands: dict[str, Handler] = {}
|
|
77
|
+
self._handlers: list[Handler] = []
|
|
78
|
+
self._error_listeners: list[Callable[[BaseException], None]] = []
|
|
79
|
+
self._running = False
|
|
80
|
+
|
|
81
|
+
def command(self, name: str) -> Callable[[Handler], Handler]:
|
|
82
|
+
"""Register a handler for ``/name``, as a decorator."""
|
|
83
|
+
|
|
84
|
+
def decorate(handler: Handler) -> Handler:
|
|
85
|
+
self._commands[name.lstrip("/")] = handler
|
|
86
|
+
return handler
|
|
87
|
+
|
|
88
|
+
return decorate
|
|
89
|
+
|
|
90
|
+
def on_text(self, handler: Handler) -> Handler:
|
|
91
|
+
"""Register a handler for any text that matched no command."""
|
|
92
|
+
self._handlers.append(handler)
|
|
93
|
+
return handler
|
|
94
|
+
|
|
95
|
+
def on_error(self, listener: Callable[[BaseException], None]) -> Callable[[BaseException], None]:
|
|
96
|
+
self._error_listeners.append(listener)
|
|
97
|
+
return listener
|
|
98
|
+
|
|
99
|
+
async def run(self) -> None:
|
|
100
|
+
"""Poll until cancelled, or until a terminal failure, which is raised.
|
|
101
|
+
|
|
102
|
+
There is no ``on_fatal``: in Python an error that ends the loop is an
|
|
103
|
+
exception, and callers already know how to handle one.
|
|
104
|
+
"""
|
|
105
|
+
# G1: one in-flight poll per instance. Two overlapping polls on one bot
|
|
106
|
+
# used to split the updates silently; the server now answers 409, but
|
|
107
|
+
# the SDK should never be the one causing it.
|
|
108
|
+
if self._running:
|
|
109
|
+
raise UsageError("this bot is already running")
|
|
110
|
+
self._running = True
|
|
111
|
+
try:
|
|
112
|
+
await self._transport.run(
|
|
113
|
+
TransportDeps(
|
|
114
|
+
client=self.client,
|
|
115
|
+
on_update=self._dispatch,
|
|
116
|
+
on_error=self._emit_error,
|
|
117
|
+
)
|
|
118
|
+
)
|
|
119
|
+
finally:
|
|
120
|
+
self._running = False
|
|
121
|
+
|
|
122
|
+
async def aclose(self) -> None:
|
|
123
|
+
await self.client.aclose()
|
|
124
|
+
|
|
125
|
+
async def __aenter__(self) -> "Bot":
|
|
126
|
+
return self
|
|
127
|
+
|
|
128
|
+
async def __aexit__(self, *_exc: object) -> None:
|
|
129
|
+
await self.aclose()
|
|
130
|
+
|
|
131
|
+
def _emit_error(self, error: BaseException) -> None:
|
|
132
|
+
for listener in self._error_listeners:
|
|
133
|
+
listener(error)
|
|
134
|
+
|
|
135
|
+
async def _dispatch(self, update: Update) -> None:
|
|
136
|
+
if update.message is None:
|
|
137
|
+
return
|
|
138
|
+
event = Event(
|
|
139
|
+
update=update,
|
|
140
|
+
message=update.message,
|
|
141
|
+
chat_id=update.message.chat.id,
|
|
142
|
+
client=self.client,
|
|
143
|
+
_attempts=self._attempts,
|
|
144
|
+
_on_error=self._emit_error,
|
|
145
|
+
)
|
|
146
|
+
command = _parse_command(update.message.text)
|
|
147
|
+
handler = self._commands.get(command) if command else None
|
|
148
|
+
if handler is not None:
|
|
149
|
+
await handler(event)
|
|
150
|
+
return
|
|
151
|
+
for fallback in self._handlers:
|
|
152
|
+
await fallback(event)
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
async def _send_with_retry(
|
|
156
|
+
client: Client,
|
|
157
|
+
*,
|
|
158
|
+
chat_id: ChatID,
|
|
159
|
+
text: str,
|
|
160
|
+
reply_to_message_id: MessageID | None,
|
|
161
|
+
attempts: int,
|
|
162
|
+
on_error: Callable[[BaseException], None],
|
|
163
|
+
) -> BotMessage:
|
|
164
|
+
"""G4: one key per logical message, the SAME key on every retry of THAT one.
|
|
165
|
+
|
|
166
|
+
The key is generated once, outside the loop. A fresh key per attempt turns
|
|
167
|
+
a retry into a second message — the user sees the bot answer twice — and
|
|
168
|
+
reusing one key across different messages makes the server discard the
|
|
169
|
+
second SILENTLY, which is worse because it looks like it worked.
|
|
170
|
+
"""
|
|
171
|
+
key = str(uuid.uuid4())
|
|
172
|
+
last_error: BaseException | None = None
|
|
173
|
+
for attempt in range(1, attempts + 1):
|
|
174
|
+
try:
|
|
175
|
+
return await client.send_message(
|
|
176
|
+
chat_id=chat_id,
|
|
177
|
+
text=text,
|
|
178
|
+
reply_to_message_id=reply_to_message_id,
|
|
179
|
+
idempotency_key=key,
|
|
180
|
+
)
|
|
181
|
+
except asyncio.CancelledError:
|
|
182
|
+
raise
|
|
183
|
+
except Exception as error: # noqa: BLE001 - classify decides
|
|
184
|
+
last_error = error
|
|
185
|
+
if classify(error, "call") != "transient":
|
|
186
|
+
raise
|
|
187
|
+
if attempt == attempts:
|
|
188
|
+
break
|
|
189
|
+
on_error(error)
|
|
190
|
+
await asyncio.sleep(_backoff(attempt, 0.25, 4.0))
|
|
191
|
+
assert last_error is not None
|
|
192
|
+
raise last_error
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
def _parse_command(text: str) -> str:
|
|
196
|
+
stripped = text.strip()
|
|
197
|
+
if not stripped.startswith("/"):
|
|
198
|
+
return ""
|
|
199
|
+
# split() on whitespace-only returns [], so indexing it would raise on a
|
|
200
|
+
# message that is just "/ ". Take the head defensively.
|
|
201
|
+
parts = stripped[1:].split()
|
|
202
|
+
if not parts:
|
|
203
|
+
return ""
|
|
204
|
+
name = parts[0]
|
|
205
|
+
return name if name.replace("_", "").isalnum() else ""
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"""The raw client: a 1:1 wrapper over the four methods, with no loop."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import ipaddress
|
|
6
|
+
from typing import Any, Callable
|
|
7
|
+
from urllib.parse import urlparse
|
|
8
|
+
|
|
9
|
+
import httpx
|
|
10
|
+
|
|
11
|
+
from .errors import APIError, TransportError, UsageError
|
|
12
|
+
from .redact import redact_exception
|
|
13
|
+
from .types import (
|
|
14
|
+
BotIdentity,
|
|
15
|
+
BotMessage,
|
|
16
|
+
ChatAction,
|
|
17
|
+
ChatID,
|
|
18
|
+
MessageID,
|
|
19
|
+
Update,
|
|
20
|
+
WebhookInfo,
|
|
21
|
+
message_from_wire,
|
|
22
|
+
update_from_wire,
|
|
23
|
+
webhook_info_from_wire,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
#: Server maximums, hardcoded because the server does not publish them yet
|
|
27
|
+
#: (request S3 in §13). When it does, these become the fallback.
|
|
28
|
+
MAX_LIMIT = 100
|
|
29
|
+
MAX_TIMEOUT_SECONDS = 30
|
|
30
|
+
|
|
31
|
+
DEFAULT_BASE_URL = "https://api.chasky.io/api/v1"
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class Client:
|
|
35
|
+
"""Safe to share; every method is a single request."""
|
|
36
|
+
|
|
37
|
+
def __init__(
|
|
38
|
+
self,
|
|
39
|
+
token: str,
|
|
40
|
+
*,
|
|
41
|
+
base_url: str | None = None,
|
|
42
|
+
http: httpx.AsyncClient | None = None,
|
|
43
|
+
on_warning: Callable[[str], None] | None = None,
|
|
44
|
+
allow_insecure_transport: bool = False,
|
|
45
|
+
) -> None:
|
|
46
|
+
if not token:
|
|
47
|
+
raise UsageError("a bot token is required")
|
|
48
|
+
self._token = token
|
|
49
|
+
self._base_url = (base_url or DEFAULT_BASE_URL).rstrip("/")
|
|
50
|
+
self._warn = on_warning or (lambda _message: None)
|
|
51
|
+
self._owns_http = http is None
|
|
52
|
+
# Room for the longest poll plus latency. Cancellation is the task's
|
|
53
|
+
# job, not this timeout's.
|
|
54
|
+
self._http = http or httpx.AsyncClient(timeout=MAX_TIMEOUT_SECONDS + 15)
|
|
55
|
+
|
|
56
|
+
# D8: warn ONCE, at construction. A warning per poll is noise that ends
|
|
57
|
+
# up filtered out of a grep, which is the same as no warning at all.
|
|
58
|
+
if not allow_insecure_transport and _is_insecure(self._base_url):
|
|
59
|
+
self._warn(
|
|
60
|
+
"base_url uses plaintext http:// to a non-loopback host. The bot token "
|
|
61
|
+
"travels in the URL PATH, so every proxy on the way writes it down. Use "
|
|
62
|
+
"https://, or pass allow_insecure_transport=True to accept this."
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
async def __aenter__(self) -> "Client":
|
|
66
|
+
return self
|
|
67
|
+
|
|
68
|
+
async def __aexit__(self, *_exc: object) -> None:
|
|
69
|
+
await self.aclose()
|
|
70
|
+
|
|
71
|
+
async def aclose(self) -> None:
|
|
72
|
+
if self._owns_http:
|
|
73
|
+
await self._http.aclose()
|
|
74
|
+
|
|
75
|
+
async def get_me(self) -> BotIdentity:
|
|
76
|
+
raw = await self._call("getMe", {})
|
|
77
|
+
return BotIdentity(
|
|
78
|
+
id=raw.get("id", ""),
|
|
79
|
+
is_bot=True,
|
|
80
|
+
username=raw.get("username", ""),
|
|
81
|
+
# Prefer display_name if the server ever adds it (S2).
|
|
82
|
+
display_name=raw.get("display_name") or raw.get("first_name", ""),
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
async def get_updates(
|
|
86
|
+
self,
|
|
87
|
+
*,
|
|
88
|
+
offset: int = 0,
|
|
89
|
+
limit: int | None = None,
|
|
90
|
+
timeout_seconds: int | None = None,
|
|
91
|
+
) -> list[Update]:
|
|
92
|
+
body = {
|
|
93
|
+
"offset": offset,
|
|
94
|
+
"limit": self._clamp_limit(limit),
|
|
95
|
+
"timeout": self._clamp_timeout(timeout_seconds),
|
|
96
|
+
}
|
|
97
|
+
raw = await self._call("getUpdates", body)
|
|
98
|
+
# A missing or malformed result is an empty batch, never a crash: the
|
|
99
|
+
# poll loop must survive a server that answers something unexpected.
|
|
100
|
+
if not isinstance(raw, list):
|
|
101
|
+
return []
|
|
102
|
+
return [update_from_wire(item) for item in raw]
|
|
103
|
+
|
|
104
|
+
async def send_message(
|
|
105
|
+
self,
|
|
106
|
+
*,
|
|
107
|
+
chat_id: ChatID,
|
|
108
|
+
text: str,
|
|
109
|
+
reply_to_message_id: MessageID | None = None,
|
|
110
|
+
idempotency_key: str | None = None,
|
|
111
|
+
) -> BotMessage:
|
|
112
|
+
if not text:
|
|
113
|
+
raise UsageError("send_message requires a non-empty text")
|
|
114
|
+
body: dict[str, Any] = {"chat_id": chat_id, "text": text}
|
|
115
|
+
if reply_to_message_id is not None:
|
|
116
|
+
body["reply_to_message_id"] = reply_to_message_id
|
|
117
|
+
headers = {"Idempotency-Key": idempotency_key} if idempotency_key else None
|
|
118
|
+
return message_from_wire(await self._call("sendMessage", body, headers))
|
|
119
|
+
|
|
120
|
+
async def get_webhook_info(self) -> WebhookInfo:
|
|
121
|
+
"""Report the bot's webhook state. Empty ``state`` means still polling."""
|
|
122
|
+
raw = await self._call("getWebhookInfo", {})
|
|
123
|
+
return webhook_info_from_wire(raw if isinstance(raw, dict) else {})
|
|
124
|
+
|
|
125
|
+
async def send_chat_action(self, *, chat_id: ChatID, action: ChatAction = "typing") -> bool:
|
|
126
|
+
await self._call("sendChatAction", {"chat_id": chat_id, "action": action})
|
|
127
|
+
return True
|
|
128
|
+
|
|
129
|
+
def _clamp_limit(self, limit: int | None) -> int:
|
|
130
|
+
if limit is None or limit == 0:
|
|
131
|
+
return MAX_LIMIT
|
|
132
|
+
if limit < 1:
|
|
133
|
+
# The server answers 400 to these. Rejecting locally, with the
|
|
134
|
+
# reason, beats spending a request to be told the same thing less
|
|
135
|
+
# clearly.
|
|
136
|
+
raise UsageError(f"limit must be at least 1, got {limit}")
|
|
137
|
+
if limit > MAX_LIMIT:
|
|
138
|
+
self._warn(f"limit {limit} clamped to the server maximum of {MAX_LIMIT}")
|
|
139
|
+
return MAX_LIMIT
|
|
140
|
+
return limit
|
|
141
|
+
|
|
142
|
+
def _clamp_timeout(self, seconds: int | None) -> int:
|
|
143
|
+
if seconds is None:
|
|
144
|
+
return 0
|
|
145
|
+
if seconds < 0:
|
|
146
|
+
raise UsageError(f"timeout_seconds must not be negative, got {seconds}")
|
|
147
|
+
if seconds > MAX_TIMEOUT_SECONDS:
|
|
148
|
+
self._warn(
|
|
149
|
+
f"timeout_seconds {seconds} clamped to the server maximum of {MAX_TIMEOUT_SECONDS}"
|
|
150
|
+
)
|
|
151
|
+
return MAX_TIMEOUT_SECONDS
|
|
152
|
+
return seconds
|
|
153
|
+
|
|
154
|
+
async def _call(
|
|
155
|
+
self,
|
|
156
|
+
method: str,
|
|
157
|
+
body: Any,
|
|
158
|
+
headers: dict[str, str] | None = None,
|
|
159
|
+
) -> Any:
|
|
160
|
+
url = f"{self._base_url}/bot{self._token}/{method}"
|
|
161
|
+
try:
|
|
162
|
+
response = await self._http.post(url, json=body, headers=headers)
|
|
163
|
+
except Exception as error: # noqa: BLE001 - the URL is in here either way
|
|
164
|
+
# Redact before it can reach a log.
|
|
165
|
+
raise TransportError(
|
|
166
|
+
f"{method} could not reach the server: "
|
|
167
|
+
f"{redact_exception(error, self._token)}"
|
|
168
|
+
) from error
|
|
169
|
+
|
|
170
|
+
try:
|
|
171
|
+
envelope = response.json()
|
|
172
|
+
except Exception as error: # noqa: BLE001
|
|
173
|
+
raise TransportError(
|
|
174
|
+
f"{method} returned a body that is not JSON (HTTP {response.status_code}): "
|
|
175
|
+
f"{redact_exception(error, self._token)}"
|
|
176
|
+
) from error
|
|
177
|
+
|
|
178
|
+
if not isinstance(envelope, dict) or not envelope.get("ok"):
|
|
179
|
+
code = (envelope or {}).get("error_code") or response.status_code
|
|
180
|
+
description = (envelope or {}).get("description") or "UNKNOWN"
|
|
181
|
+
raise APIError(code, description, method)
|
|
182
|
+
return envelope.get("result")
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def _is_insecure(base_url: str) -> bool:
|
|
186
|
+
"""Plaintext to a non-loopback host.
|
|
187
|
+
|
|
188
|
+
Loopback only, and deliberately not ``*.local``: mDNS can resolve to a real
|
|
189
|
+
machine on the network, and there the token travels in the clear.
|
|
190
|
+
"""
|
|
191
|
+
parsed = urlparse(base_url)
|
|
192
|
+
if parsed.scheme != "http":
|
|
193
|
+
return False
|
|
194
|
+
host = (parsed.hostname or "").lower()
|
|
195
|
+
if host == "localhost" or host.endswith(".localhost"):
|
|
196
|
+
return False
|
|
197
|
+
try:
|
|
198
|
+
return not ipaddress.ip_address(host).is_loopback
|
|
199
|
+
except ValueError:
|
|
200
|
+
return True
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"""Exception hierarchy and the classification that drives retries (§10)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Literal
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class ChaskyError(Exception):
|
|
9
|
+
"""Base for everything this package raises."""
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class APIError(ChaskyError):
|
|
13
|
+
"""A failure the server described in its envelope."""
|
|
14
|
+
|
|
15
|
+
def __init__(self, code: int, description: str, method: str) -> None:
|
|
16
|
+
super().__init__(f"{method} failed: {code} {description}")
|
|
17
|
+
#: The flow control. Never branch on ``description``: the server
|
|
18
|
+
#: declares it readable and stable, but not enumerated.
|
|
19
|
+
self.code = code
|
|
20
|
+
self.description = description
|
|
21
|
+
self.method = method
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class TransportError(ChaskyError):
|
|
25
|
+
"""The request never produced an envelope: network, cancellation, bad JSON.
|
|
26
|
+
|
|
27
|
+
The message is already redacted. ``__cause__`` still reaches the original,
|
|
28
|
+
so ``isinstance(err.__cause__, asyncio.CancelledError)`` keeps working.
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class UsageError(ChaskyError):
|
|
33
|
+
"""Raised locally, before spending a request."""
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
ErrorClass = Literal["terminal", "business", "transient"]
|
|
37
|
+
ErrorSource = Literal["poll", "call"]
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def classify(error: BaseException, source: ErrorSource) -> ErrorClass:
|
|
41
|
+
"""Decide what the SDK does with a failure (§10.2, G7).
|
|
42
|
+
|
|
43
|
+
Classification reads the code and *which call produced it*, never the
|
|
44
|
+
description. A 403 while polling means this bot is barred from polling at
|
|
45
|
+
all and is terminal; a 403 from a send means that one chat is not ours and
|
|
46
|
+
the bot lives on. Reading the method is both correct and immune to a
|
|
47
|
+
description the server never promised to keep enumerated.
|
|
48
|
+
"""
|
|
49
|
+
if isinstance(error, APIError):
|
|
50
|
+
if error.code >= 500:
|
|
51
|
+
return "transient"
|
|
52
|
+
if source == "poll" and error.code in (401, 403, 409):
|
|
53
|
+
return "terminal"
|
|
54
|
+
if source == "call" and error.code == 401:
|
|
55
|
+
return "terminal"
|
|
56
|
+
return "business"
|
|
57
|
+
if isinstance(error, UsageError):
|
|
58
|
+
return "business"
|
|
59
|
+
return "transient"
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"""The polling transport, and the seam for D4."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
import random
|
|
7
|
+
from dataclasses import dataclass
|
|
8
|
+
from typing import Awaitable, Callable, Protocol
|
|
9
|
+
|
|
10
|
+
from .client import Client
|
|
11
|
+
from .errors import classify
|
|
12
|
+
from .types import Update
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@dataclass(slots=True)
|
|
16
|
+
class TransportDeps:
|
|
17
|
+
client: Client
|
|
18
|
+
#: Called once per NEW update, in ascending order. May raise; the loop
|
|
19
|
+
#: survives.
|
|
20
|
+
on_update: Callable[[Update], Awaitable[None]]
|
|
21
|
+
#: Recoverable problems, already redacted.
|
|
22
|
+
on_error: Callable[[BaseException], None]
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class Transport(Protocol):
|
|
26
|
+
"""Polling is the only implementation today.
|
|
27
|
+
|
|
28
|
+
When the server grows outbound webhooks, a Webhook transport joins it and
|
|
29
|
+
the caller's handlers do not change. That is the whole promise — nothing
|
|
30
|
+
about the webhook's shape is committed here, because the server has not
|
|
31
|
+
built it.
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
kind: str
|
|
35
|
+
|
|
36
|
+
async def run(self, deps: TransportDeps) -> None:
|
|
37
|
+
"""Return on cancellation; raise the terminal failure."""
|
|
38
|
+
...
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class Polling:
|
|
42
|
+
kind = "polling"
|
|
43
|
+
|
|
44
|
+
def __init__(
|
|
45
|
+
self,
|
|
46
|
+
*,
|
|
47
|
+
limit: int | None = None,
|
|
48
|
+
timeout_seconds: int | None = None,
|
|
49
|
+
retry_base: float = 0.25,
|
|
50
|
+
retry_max: float = 8.0,
|
|
51
|
+
) -> None:
|
|
52
|
+
self._limit = limit
|
|
53
|
+
self._timeout_seconds = timeout_seconds
|
|
54
|
+
self._retry_base = retry_base
|
|
55
|
+
self._retry_max = retry_max
|
|
56
|
+
|
|
57
|
+
async def run(self, deps: TransportDeps) -> None:
|
|
58
|
+
# The ENTIRE state of the loop: one integer.
|
|
59
|
+
#
|
|
60
|
+
# It is both the dedup threshold (G3) and the source of the offset
|
|
61
|
+
# (G2), which are the same number — offset == last_seen + 1 holds at
|
|
62
|
+
# all times. Keeping two fields in sync would be a bug waiting for the
|
|
63
|
+
# day they diverge.
|
|
64
|
+
last_seen = -1
|
|
65
|
+
failures = 0
|
|
66
|
+
|
|
67
|
+
while True:
|
|
68
|
+
try:
|
|
69
|
+
batch = await deps.client.get_updates(
|
|
70
|
+
offset=last_seen + 1,
|
|
71
|
+
limit=self._limit,
|
|
72
|
+
timeout_seconds=self._timeout_seconds,
|
|
73
|
+
)
|
|
74
|
+
failures = 0
|
|
75
|
+
except asyncio.CancelledError:
|
|
76
|
+
raise
|
|
77
|
+
except Exception as error: # noqa: BLE001 - classify decides
|
|
78
|
+
if classify(error, "poll") == "terminal":
|
|
79
|
+
# 401, 403 and 409 while polling all mean the same thing:
|
|
80
|
+
# this bot will not be allowed to poll. Retrying a 409 in
|
|
81
|
+
# particular is an eviction war — two instances displacing
|
|
82
|
+
# each other forever, neither processing anything (§3.1).
|
|
83
|
+
raise
|
|
84
|
+
deps.on_error(error)
|
|
85
|
+
failures += 1
|
|
86
|
+
await asyncio.sleep(_backoff(failures, self._retry_base, self._retry_max))
|
|
87
|
+
continue
|
|
88
|
+
|
|
89
|
+
for update in batch:
|
|
90
|
+
# G3: a threshold, not a data structure. The server delivers in
|
|
91
|
+
# strictly ascending order and emits no regressive ids, so
|
|
92
|
+
# anything at or below the threshold is a redelivery —
|
|
93
|
+
# including a full stream replay after the consumer group is
|
|
94
|
+
# recreated, where a finite window would fail.
|
|
95
|
+
if update.update_id <= last_seen:
|
|
96
|
+
continue
|
|
97
|
+
|
|
98
|
+
# G2, and the order is the point: the cursor advances BEFORE
|
|
99
|
+
# the handler runs, so a handler that raises cannot pin the bot
|
|
100
|
+
# on one update forever. The offset is a read cursor, not a
|
|
101
|
+
# business acknowledgement.
|
|
102
|
+
last_seen = update.update_id
|
|
103
|
+
|
|
104
|
+
try:
|
|
105
|
+
await deps.on_update(update)
|
|
106
|
+
except asyncio.CancelledError:
|
|
107
|
+
raise
|
|
108
|
+
except Exception as error: # noqa: BLE001 - the author's bug, reported
|
|
109
|
+
deps.on_error(error)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def _backoff(attempt: int, base: float, maximum: float) -> float:
|
|
113
|
+
delay = min(maximum, base * 2 ** (attempt - 1))
|
|
114
|
+
# Jitter so many bots recovering from one outage do not resynchronise into
|
|
115
|
+
# a thundering herd against the API.
|
|
116
|
+
return delay * (0.5 + random.random() * 0.5)
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"""Token redaction (G5).
|
|
2
|
+
|
|
3
|
+
Not a logging convenience but a correctness requirement: the token travels in
|
|
4
|
+
the URL path, so an HTTP client embeds it in its own exceptions. A plain
|
|
5
|
+
"connection refused" is enough to write the credential into a log, and the
|
|
6
|
+
caller cannot defend against that because they do not know the exception has a
|
|
7
|
+
URL inside.
|
|
8
|
+
|
|
9
|
+
Everything this package raises has been through here.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import re
|
|
15
|
+
|
|
16
|
+
REDACTED = "<REDACTED>"
|
|
17
|
+
|
|
18
|
+
#: Catches a token other than the configured one, e.g. after a rotation.
|
|
19
|
+
_BOT_PATH = re.compile(r"/bot[^/\s]+")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def redact_text(text: str, token: str) -> str:
|
|
23
|
+
if token:
|
|
24
|
+
text = text.replace(token, REDACTED)
|
|
25
|
+
return _BOT_PATH.sub(f"/bot{REDACTED}", text)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def redact_exception(error: BaseException, token: str) -> str:
|
|
29
|
+
"""Render an exception's message safely, following ``__cause__``.
|
|
30
|
+
|
|
31
|
+
The cause chain is walked because that is where an HTTP library keeps the
|
|
32
|
+
real network error, and therefore where the URL usually is. The original
|
|
33
|
+
exception is never mutated: it may be shared, and mutating it would be a
|
|
34
|
+
side effect on someone else's object.
|
|
35
|
+
"""
|
|
36
|
+
parts: list[str] = []
|
|
37
|
+
seen: set[int] = set()
|
|
38
|
+
current: BaseException | None = error
|
|
39
|
+
while current is not None and id(current) not in seen:
|
|
40
|
+
seen.add(id(current))
|
|
41
|
+
rendered = str(current) or type(current).__name__
|
|
42
|
+
parts.append(redact_text(rendered, token))
|
|
43
|
+
current = current.__cause__ or current.__context__
|
|
44
|
+
return ": ".join(parts)
|
chasky_botsmith/types.py
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"""Domain types. See §7.1 of ../../docs/00-spec.md."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from datetime import datetime, timezone
|
|
7
|
+
from typing import Any, Literal
|
|
8
|
+
|
|
9
|
+
# Identifiers are strings and this package never converts one. See §9 of the
|
|
10
|
+
# contract: a real chat id carries the "bot:" prefix twice, so anything that
|
|
11
|
+
# "understands" the format well enough to take it apart breaks on a live
|
|
12
|
+
# server. An id is an opaque label.
|
|
13
|
+
ChatID = str
|
|
14
|
+
UserID = str
|
|
15
|
+
MessageID = str
|
|
16
|
+
|
|
17
|
+
# The one numeric identifier: an int counter, one per bot. Python ints are
|
|
18
|
+
# arbitrary precision, so the 2^53 caveat the JavaScript SDK carries does not
|
|
19
|
+
# apply here. Gaps in the sequence are valid and are not loss.
|
|
20
|
+
UpdateID = int
|
|
21
|
+
|
|
22
|
+
ChatAction = Literal["typing"]
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@dataclass(frozen=True, slots=True)
|
|
26
|
+
class WebhookInfo:
|
|
27
|
+
"""What ``get_webhook_info`` reports.
|
|
28
|
+
|
|
29
|
+
An empty ``state`` means the bot has no destination registered and is still
|
|
30
|
+
polling; ``active`` and ``suspended`` are the webhook states.
|
|
31
|
+
``has_secret_token`` answers "is one configured", never "which one" — the
|
|
32
|
+
server does not reveal it and neither does this.
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
url: str
|
|
36
|
+
has_secret_token: bool
|
|
37
|
+
pending_update_count: int
|
|
38
|
+
#: The LAST RUN of failures, not all time: a successful delivery clears
|
|
39
|
+
#: them. An error from three days ago beside a working webhook explains
|
|
40
|
+
#: nothing.
|
|
41
|
+
last_error_at: datetime | None = None
|
|
42
|
+
last_error_message: str | None = None
|
|
43
|
+
#: Empty while polling.
|
|
44
|
+
state: str | None = None
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def webhook_info_from_wire(raw: dict[str, Any]) -> WebhookInfo:
|
|
48
|
+
last_error = raw.get("last_error_date")
|
|
49
|
+
return WebhookInfo(
|
|
50
|
+
url=raw.get("url", ""),
|
|
51
|
+
has_secret_token=raw.get("has_secret_token", False),
|
|
52
|
+
pending_update_count=raw.get("pending_update_count", 0),
|
|
53
|
+
last_error_at=datetime.fromtimestamp(last_error, tz=timezone.utc) if last_error else None,
|
|
54
|
+
last_error_message=raw.get("last_error_message") or None,
|
|
55
|
+
state=raw.get("state") or None,
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
@dataclass(frozen=True, slots=True)
|
|
60
|
+
class User:
|
|
61
|
+
id: UserID
|
|
62
|
+
name: str
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
@dataclass(frozen=True, slots=True)
|
|
66
|
+
class Chat:
|
|
67
|
+
id: ChatID
|
|
68
|
+
type: str
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
@dataclass(frozen=True, slots=True)
|
|
72
|
+
class BotMessage:
|
|
73
|
+
message_id: MessageID
|
|
74
|
+
from_user: User
|
|
75
|
+
chat: Chat
|
|
76
|
+
#: The wire carries seconds since the epoch; this is timezone-aware UTC.
|
|
77
|
+
date: datetime
|
|
78
|
+
text: str
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
@dataclass(frozen=True, slots=True)
|
|
82
|
+
class Update:
|
|
83
|
+
update_id: UpdateID
|
|
84
|
+
message: BotMessage | None = None
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
@dataclass(frozen=True, slots=True)
|
|
88
|
+
class BotIdentity:
|
|
89
|
+
id: UserID
|
|
90
|
+
is_bot: bool
|
|
91
|
+
username: str
|
|
92
|
+
#: Mapped from the server's ``first_name``, which is Telegram-shaped while
|
|
93
|
+
#: the rest of the contract is Chasky-shaped. Server request S2 in §13.
|
|
94
|
+
display_name: str
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def message_from_wire(raw: dict[str, Any]) -> BotMessage:
|
|
98
|
+
sender = raw.get("from") or {}
|
|
99
|
+
return BotMessage(
|
|
100
|
+
message_id=raw.get("message_id", ""),
|
|
101
|
+
from_user=User(id=sender.get("id", ""), name=sender.get("name", "")),
|
|
102
|
+
chat=Chat(id=raw["chat"]["id"], type=raw["chat"].get("type", "")),
|
|
103
|
+
date=datetime.fromtimestamp(raw.get("date", 0), tz=timezone.utc),
|
|
104
|
+
text=raw.get("text", ""),
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def update_from_wire(raw: dict[str, Any]) -> Update:
|
|
109
|
+
message = raw.get("message")
|
|
110
|
+
return Update(
|
|
111
|
+
update_id=raw["update_id"],
|
|
112
|
+
message=message_from_wire(message) if message else None,
|
|
113
|
+
)
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: chasky-botsmith-sdk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Client SDK for the Chasky Bot API
|
|
5
|
+
Project-URL: Repository, https://github.com/chaskyapp/botsmith-sdk
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Python: >=3.11
|
|
9
|
+
Requires-Dist: httpx>=0.27
|
|
10
|
+
Provides-Extra: dev
|
|
11
|
+
Requires-Dist: build>=1.2; extra == 'dev'
|
|
12
|
+
Requires-Dist: twine>=5.1; extra == 'dev'
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
|
|
15
|
+
# `chasky-botsmith-sdk` — Python SDK
|
|
16
|
+
|
|
17
|
+
**Delivery 3.** Implemented; conformance runner in [`conformance/`](conformance/).
|
|
18
|
+
|
|
19
|
+
It arrives last, with the contract already shaken out by two implementations —
|
|
20
|
+
which makes it the cheapest of the three, not the least important.
|
|
21
|
+
|
|
22
|
+
## Shape
|
|
23
|
+
|
|
24
|
+
The guarantees are identical to the other two SDKs; the shape is Python's.
|
|
25
|
+
|
|
26
|
+
| | TypeScript | Go | Python |
|
|
27
|
+
|---|---|---|---|
|
|
28
|
+
| Concurrency | `AbortSignal` | `context.Context` | `asyncio` |
|
|
29
|
+
| Terminal failure | `onFatal` callback | returned by `Run` | **raised** |
|
|
30
|
+
| Handlers | `bot.on("text", fn)` | `bot.Handle(fn)` | `@bot.on_text` |
|
|
31
|
+
| Entry point | `await bot.start()` | `bot.Run(ctx)` | `await bot.run()` |
|
|
32
|
+
| Conformance | a CLI | `go test` | `unittest` |
|
|
33
|
+
|
|
34
|
+
There is no `on_fatal`: in Python an error that ends the loop is an exception,
|
|
35
|
+
and callers already know how to handle one. Cancel the task to stop the bot.
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
bot = Bot(token=os.environ["CHASKY_BOT_TOKEN"])
|
|
39
|
+
|
|
40
|
+
@bot.command("start")
|
|
41
|
+
async def start(event: Event) -> None:
|
|
42
|
+
await event.reply("Hello.")
|
|
43
|
+
|
|
44
|
+
@bot.on_text
|
|
45
|
+
async def echo(event: Event) -> None:
|
|
46
|
+
await event.reply(f"You said: {event.message.text}")
|
|
47
|
+
|
|
48
|
+
await bot.run()
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## The one dependency
|
|
52
|
+
|
|
53
|
+
`httpx`, and it is not reached for lightly. Go and Node ship async HTTP in their
|
|
54
|
+
standard library; Python does not. The alternative is `urllib` on a thread pool,
|
|
55
|
+
and a 30-second long poll blocking a thread with poor cancellation is worse than
|
|
56
|
+
one well-maintained dependency.
|
|
57
|
+
|
|
58
|
+
The conformance runner, by contrast, is **stdlib only** — its fake server is
|
|
59
|
+
`http.server` on a thread — so checking the SDK installs nothing beyond `httpx`.
|
|
60
|
+
|
|
61
|
+
## Running conformance
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
python -m venv .venv && .venv/bin/pip install -e . && .venv/bin/python -m unittest conformance.test_conformance -v
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
It reads the **same** cases as the other two SDKs, from `../conformance/cases`.
|
|
68
|
+
|
|
69
|
+
`test_runner_detects_a_mismatch` keeps the runner honest: it takes a passing
|
|
70
|
+
case, makes one expectation impossible, and requires the runner to notice. A
|
|
71
|
+
runner that has never failed a case is not a tested runner.
|
|
72
|
+
|
|
73
|
+
- Contract: [`../docs/00-spec.md`](../docs/00-spec.md)
|
|
74
|
+
- Invariant vs idiomatic: [`../docs/01-organization.md`](../docs/01-organization.md) §3
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
chasky_botsmith/__init__.py,sha256=4DX14b-z9OApC0H2EsLIWq9TPd3Lz1F8OHiXgtQ1crM,1830
|
|
2
|
+
chasky_botsmith/bot.py,sha256=UpAaoOPoFZ9d7XOHbhaP0sjsQI7wOVRW5ovkdDsMIHs,6974
|
|
3
|
+
chasky_botsmith/client.py,sha256=HDjhCz95lRGRpd0Cdp6bPPTxgXpX3AGEyRIVmLM1vK8,7285
|
|
4
|
+
chasky_botsmith/errors.py,sha256=gR9qQxWTrlrptfsGeGjAwN9jrKrUIP7EvLs5wRbRX5w,2043
|
|
5
|
+
chasky_botsmith/polling.py,sha256=sW6-Kf1zvwMrMOHzjmky6foPqkTx1AX9gBdu7jTxFWY,4247
|
|
6
|
+
chasky_botsmith/redact.py,sha256=UZNEDdA50lBNJhWOV90IjuaaAIdAu49I2zq4o_T954Y,1543
|
|
7
|
+
chasky_botsmith/types.py,sha256=oU8pi__x54L2Lt-li5gh5LKrcz9U2JxhB74pkUasQEA,3469
|
|
8
|
+
chasky_botsmith_sdk-0.1.0.dist-info/METADATA,sha256=FRJAX0wmDm5KgrfherrRBJIgRyjHAJVJrwa_fXpzqX0,2660
|
|
9
|
+
chasky_botsmith_sdk-0.1.0.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
|
|
10
|
+
chasky_botsmith_sdk-0.1.0.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
|
|
11
|
+
chasky_botsmith_sdk-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|