omnipython-applibs 0.1.2.dev16__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.
Files changed (143) hide show
  1. appkit/__init__.py +52 -0
  2. appkit/__init__.pyi +17 -0
  3. appkit/data.py +149 -0
  4. appkit/data.pyi +25 -0
  5. appkit/foreground.py +357 -0
  6. appkit/foreground.pyi +45 -0
  7. appkit/home.py +19 -0
  8. appkit/home.pyi +8 -0
  9. appkit/hover.py +59 -0
  10. appkit/hover.pyi +13 -0
  11. appkit/index.py +199 -0
  12. appkit/index.pyi +30 -0
  13. appkit/launcher.py +1075 -0
  14. appkit/launcher.pyi +96 -0
  15. appkit/manifest.py +75 -0
  16. appkit/manifest.pyi +8 -0
  17. appkit/net.py +167 -0
  18. appkit/net.pyi +34 -0
  19. appkit/places.py +202 -0
  20. appkit/places.pyi +39 -0
  21. appkit/py.typed +0 -0
  22. appkit/scope.py +636 -0
  23. appkit/scope.pyi +110 -0
  24. appkit/shell.py +121 -0
  25. appkit/shell.pyi +32 -0
  26. appkit/worker.py +409 -0
  27. appkit/worker.pyi +83 -0
  28. controlkit/__init__.py +19 -0
  29. controlkit/__init__.pyi +10 -0
  30. controlkit/_draw.py +88 -0
  31. controlkit/_safe.py +29 -0
  32. controlkit/dotmatrix.py +101 -0
  33. controlkit/dotmatrix.pyi +23 -0
  34. controlkit/encoder.py +297 -0
  35. controlkit/encoder.pyi +55 -0
  36. controlkit/font5x7.py +22 -0
  37. controlkit/font5x7.pyi +11 -0
  38. controlkit/lamp_button.py +92 -0
  39. controlkit/lamp_button.pyi +40 -0
  40. controlkit/meter.py +86 -0
  41. controlkit/meter.pyi +30 -0
  42. controlkit/mock.py +116 -0
  43. controlkit/mock.pyi +35 -0
  44. controlkit/pad_grid.py +113 -0
  45. controlkit/pad_grid.pyi +41 -0
  46. controlkit/py.typed +0 -0
  47. controlkit/slider.py +185 -0
  48. controlkit/slider.pyi +49 -0
  49. controlkit/sprites.py +279 -0
  50. controlkit/sprites.pyi +22 -0
  51. controlkit/theme.py +120 -0
  52. controlkit/theme.pyi +15 -0
  53. deskkit/__init__.py +74 -0
  54. deskkit/__init__.pyi +18 -0
  55. deskkit/forecast.py +261 -0
  56. deskkit/forecast.pyi +40 -0
  57. deskkit/localtime.py +215 -0
  58. deskkit/localtime.pyi +33 -0
  59. deskkit/py.typed +0 -0
  60. deskkit/shell.py +113 -0
  61. deskkit/shell.pyi +33 -0
  62. omnipython_applibs-0.1.2.dev16.dist-info/METADATA +90 -0
  63. omnipython_applibs-0.1.2.dev16.dist-info/RECORD +143 -0
  64. omnipython_applibs-0.1.2.dev16.dist-info/WHEEL +5 -0
  65. omnipython_applibs-0.1.2.dev16.dist-info/licenses/LICENSE +21 -0
  66. omnipython_applibs-0.1.2.dev16.dist-info/top_level.txt +9 -0
  67. programkit/__init__.py +27 -0
  68. programkit/__init__.pyi +8 -0
  69. programkit/board.py +56 -0
  70. programkit/board.pyi +20 -0
  71. programkit/press.py +63 -0
  72. programkit/press.pyi +17 -0
  73. programkit/py.typed +0 -0
  74. programkit/rows.py +149 -0
  75. programkit/rows.pyi +34 -0
  76. sayso/__init__.py +109 -0
  77. sayso/__init__.pyi +124 -0
  78. sayso/auth.py +811 -0
  79. sayso/auth.pyi +102 -0
  80. sayso/client.py +1286 -0
  81. sayso/client.pyi +138 -0
  82. sayso/keepalive.py +371 -0
  83. sayso/keepalive.pyi +53 -0
  84. sayso/local.py +85 -0
  85. sayso/local.pyi +28 -0
  86. sayso/object_specs.py +706 -0
  87. sayso/object_specs.pyi +8 -0
  88. sayso/objects.py +411 -0
  89. sayso/objects.pyi +854 -0
  90. sayso/py.typed +0 -0
  91. sayso/schema_coverage.py +210 -0
  92. sayso/schema_coverage.pyi +13 -0
  93. sayso/transport.py +426 -0
  94. sayso/transport.pyi +47 -0
  95. songmodel/__init__.py +30 -0
  96. songmodel/__init__.pyi +9 -0
  97. songmodel/link.py +189 -0
  98. songmodel/link.pyi +53 -0
  99. songmodel/model.py +238 -0
  100. songmodel/model.pyi +40 -0
  101. songmodel/page.html +225 -0
  102. songmodel/page_data.py +236 -0
  103. songmodel/page_data.pyi +6 -0
  104. songmodel/py.typed +0 -0
  105. soundmodule/__init__.py +7 -0
  106. soundmodule/__init__.pyi +6 -0
  107. soundmodule/engine.py +1001 -0
  108. soundmodule/engine.pyi +196 -0
  109. soundmodule/names.py +298 -0
  110. soundmodule/names.pyi +30 -0
  111. soundmodule/pipes.py +105 -0
  112. soundmodule/pipes.pyi +31 -0
  113. soundmodule/py.typed +0 -0
  114. soundmodule/run.py +249 -0
  115. soundmodule/run.pyi +49 -0
  116. spectrum/__init__.py +72 -0
  117. spectrum/__init__.pyi +30 -0
  118. spectrum/analyzer.py +231 -0
  119. spectrum/analyzer.pyi +67 -0
  120. spectrum/fake_music.py +201 -0
  121. spectrum/fake_music.pyi +36 -0
  122. spectrum/pump_levels.py +126 -0
  123. spectrum/pump_levels.pyi +46 -0
  124. spectrum/py.typed +0 -0
  125. spectrum/spectrum_view.py +403 -0
  126. spectrum/spectrum_view.pyi +80 -0
  127. touchkit/__init__.py +4 -0
  128. touchkit/__init__.pyi +4 -0
  129. touchkit/cam.py +146 -0
  130. touchkit/cam.pyi +35 -0
  131. touchkit/clock.py +18 -0
  132. touchkit/clock.pyi +6 -0
  133. touchkit/ecp.py +134 -0
  134. touchkit/ecp.pyi +28 -0
  135. touchkit/net.py +347 -0
  136. touchkit/net.pyi +27 -0
  137. touchkit/py.typed +0 -0
  138. touchkit/settings.py +85 -0
  139. touchkit/settings.pyi +17 -0
  140. touchkit/shell.py +268 -0
  141. touchkit/shell.pyi +42 -0
  142. touchkit/ui.py +167 -0
  143. touchkit/ui.pyi +53 -0
sayso/py.typed ADDED
File without changes
@@ -0,0 +1,210 @@
1
+ # SPDX-FileCopyrightText: 2026 Brad Barnett
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+
5
+ from .object_specs import SPOTIFY_OBJECT_SPECS
6
+
7
+
8
+ OPENAPI_SCHEMA_NAMES = (
9
+ "LinkedTrackObject",
10
+ "TrackRestrictionObject",
11
+ "AlbumRestrictionObject",
12
+ "EpisodeRestrictionObject",
13
+ "ChapterRestrictionObject",
14
+ "ArtistObject",
15
+ "SimplifiedArtistObject",
16
+ "PlayHistoryObject",
17
+ "PlaylistTrackObject",
18
+ "QueueObject",
19
+ "CurrentlyPlayingContextObject",
20
+ "DisallowsObject",
21
+ "ErrorObject",
22
+ "PrivateUserObject",
23
+ "PublicUserObject",
24
+ "AudioAnalysisObject",
25
+ "TimeIntervalObject",
26
+ "SectionObject",
27
+ "SegmentObject",
28
+ "TimeSignature",
29
+ "Tempo",
30
+ "Loudness",
31
+ "Key",
32
+ "Mode",
33
+ "AudioFeaturesObject",
34
+ "SimplifiedTrackObject",
35
+ "DeviceObject",
36
+ "CursorObject",
37
+ "CursorPagingObject",
38
+ "CursorPagingPlayHistoryObject",
39
+ "CursorPagingSimplifiedArtistObject",
40
+ "PagingObject",
41
+ "PagingPlaylistObject",
42
+ "PagingFeaturedPlaylistObject",
43
+ "PagingArtistDiscographyAlbumObject",
44
+ "PagingSimplifiedAlbumObject",
45
+ "PagingSavedAlbumObject",
46
+ "PagingSimplifiedTrackObject",
47
+ "PagingSavedTrackObject",
48
+ "PagingTrackObject",
49
+ "PagingPlaylistTrackObject",
50
+ "PagingSimplifiedShowObject",
51
+ "PagingSavedShowObject",
52
+ "PagingSimplifiedEpisodeObject",
53
+ "PagingSavedEpisodeObject",
54
+ "PagingSimplifiedAudiobookObject",
55
+ "PagingArtistObject",
56
+ "PagingSimplifiedChapterObject",
57
+ "RecommendationsObject",
58
+ "RecommendationSeedObject",
59
+ "SavedAlbumObject",
60
+ "SavedTrackObject",
61
+ "SavedEpisodeObject",
62
+ "SavedShowObject",
63
+ "PlaylistObject",
64
+ "SimplifiedPlaylistObject",
65
+ "PlaylistItemsRefObject",
66
+ "PlaylistUserObject",
67
+ "PlaylistOwnerObject",
68
+ "CategoryObject",
69
+ "TrackObject",
70
+ "EpisodeObject",
71
+ "SimplifiedEpisodeObject",
72
+ "EpisodeBase",
73
+ "ResumePointObject",
74
+ "ShowBase",
75
+ "ShowObject",
76
+ "SimplifiedShowObject",
77
+ "AudiobookBase",
78
+ "AudiobookObject",
79
+ "SimplifiedAudiobookObject",
80
+ "AlbumBase",
81
+ "SimplifiedAlbumObject",
82
+ "ArtistDiscographyAlbumObject",
83
+ "ChapterObject",
84
+ "SimplifiedChapterObject",
85
+ "ChapterBase",
86
+ "AlbumObject",
87
+ "ContextObject",
88
+ "CopyrightObject",
89
+ "AuthorObject",
90
+ "NarratorObject",
91
+ "ExternalIdObject",
92
+ "ExternalUrlObject",
93
+ "FollowersObject",
94
+ "ImageObject",
95
+ "ExplicitContentSettingsObject",
96
+ )
97
+
98
+
99
+ SCHEMA_TO_SPEC = {
100
+ "AlbumBase": "Album",
101
+ "AlbumObject": "Album",
102
+ "AlbumRestrictionObject": "Restriction",
103
+ "ArtistDiscographyAlbumObject": "Album",
104
+ "ArtistObject": "Artist",
105
+ "AudioAnalysisObject": "AudioAnalysis",
106
+ "AudioFeaturesObject": "AudioFeatures",
107
+ "AuthorObject": "Author",
108
+ "AudiobookBase": "Audiobook",
109
+ "AudiobookObject": "Audiobook",
110
+ "CategoryObject": "Category",
111
+ "ChapterBase": "Chapter",
112
+ "ChapterObject": "Chapter",
113
+ "ChapterRestrictionObject": "Restriction",
114
+ "ContextObject": "Context",
115
+ "CopyrightObject": "Copyright",
116
+ "CursorObject": "Cursor",
117
+ "CurrentlyPlayingContextObject": "CurrentlyPlaying",
118
+ "DeviceObject": "Device",
119
+ "DisallowsObject": "Disallows",
120
+ "ErrorObject": "Error",
121
+ "CursorPagingObject": "CursorPage",
122
+ "CursorPagingPlayHistoryObject": "PlayHistoryCursorPage",
123
+ "CursorPagingSimplifiedArtistObject": "ArtistCursorPage",
124
+ "EpisodeBase": "Episode",
125
+ "EpisodeObject": "Episode",
126
+ "EpisodeRestrictionObject": "Restriction",
127
+ "ExplicitContentSettingsObject": "ExplicitContentSettings",
128
+ "ExternalIdObject": "ExternalId",
129
+ "ExternalUrlObject": "ExternalUrl",
130
+ "FollowersObject": "Followers",
131
+ "ImageObject": "Image",
132
+ "LinkedTrackObject": "LinkedTrack",
133
+ "NarratorObject": "Narrator",
134
+ "PagingArtistDiscographyAlbumObject": "AlbumPage",
135
+ "PagingArtistObject": "ArtistPage",
136
+ "PagingFeaturedPlaylistObject": "FeaturedPlaylists",
137
+ "PagingObject": "Paging",
138
+ "PagingPlaylistObject": "PlaylistPage",
139
+ "PagingPlaylistTrackObject": "PlaylistTrackPage",
140
+ "PagingSavedAlbumObject": "SavedAlbumPage",
141
+ "PagingSavedEpisodeObject": "SavedEpisodePage",
142
+ "PagingSavedShowObject": "SavedShowPage",
143
+ "PagingSavedTrackObject": "SavedTrackPage",
144
+ "PagingSimplifiedAlbumObject": "AlbumPage",
145
+ "PagingSimplifiedAudiobookObject": "AudiobookPage",
146
+ "PagingSimplifiedChapterObject": "ChapterPage",
147
+ "PagingSimplifiedEpisodeObject": "EpisodePage",
148
+ "PagingSimplifiedShowObject": "ShowPage",
149
+ "PagingSimplifiedTrackObject": "TrackPage",
150
+ "PagingTrackObject": "TrackPage",
151
+ "PlayHistoryObject": "PlayHistory",
152
+ "PlaylistObject": "Playlist",
153
+ "PlaylistTrackObject": "PlaylistTrack",
154
+ "PlaylistOwnerObject": "User",
155
+ "PlaylistItemsRefObject": "PlaylistItemsRef",
156
+ "PlaylistUserObject": "User",
157
+ "PrivateUserObject": "PrivateUser",
158
+ "PublicUserObject": "User",
159
+ "QueueObject": "Queue",
160
+ "RecommendationSeedObject": "RecommendationSeed",
161
+ "RecommendationsObject": "Recommendations",
162
+ "ResumePointObject": "ResumePoint",
163
+ "SavedAlbumObject": "SavedAlbum",
164
+ "SavedEpisodeObject": "SavedEpisode",
165
+ "SavedShowObject": "SavedShow",
166
+ "SavedTrackObject": "SavedTrack",
167
+ "SectionObject": "Section",
168
+ "SegmentObject": "Segment",
169
+ "ShowBase": "Show",
170
+ "ShowObject": "Show",
171
+ "SimplifiedAlbumObject": "Album",
172
+ "SimplifiedArtistObject": "Artist",
173
+ "SimplifiedAudiobookObject": "Audiobook",
174
+ "SimplifiedChapterObject": "Chapter",
175
+ "SimplifiedEpisodeObject": "Episode",
176
+ "SimplifiedPlaylistObject": "Playlist",
177
+ "SimplifiedShowObject": "Show",
178
+ "SimplifiedTrackObject": "Track",
179
+ "TimeIntervalObject": "TimeInterval",
180
+ "TrackObject": "Track",
181
+ "TrackRestrictionObject": "Restriction",
182
+ }
183
+
184
+
185
+ SKIPPED_SCHEMA_NAMES = (
186
+ "Key",
187
+ "Loudness",
188
+ "Mode",
189
+ "Tempo",
190
+ "TimeSignature",
191
+ )
192
+
193
+
194
+ def spec_names():
195
+ return tuple(spec["name"] for spec in SPOTIFY_OBJECT_SPECS)
196
+
197
+
198
+ def uncovered_schema_names():
199
+ specs = set(spec_names())
200
+ skipped = set(SKIPPED_SCHEMA_NAMES)
201
+ missing = []
202
+
203
+ for schema_name in OPENAPI_SCHEMA_NAMES:
204
+ mapped = SCHEMA_TO_SPEC.get(schema_name)
205
+ if schema_name in skipped:
206
+ continue
207
+ if mapped not in specs:
208
+ missing.append(schema_name)
209
+
210
+ return tuple(missing)
@@ -0,0 +1,13 @@
1
+ # SPDX-FileCopyrightText: 2026 Brad Barnett
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+ """Checks which Spotify OpenAPI schemas the object specs cover."""
5
+
6
+ from .object_specs import SPOTIFY_OBJECT_SPECS as SPOTIFY_OBJECT_SPECS
7
+
8
+ OPENAPI_SCHEMA_NAMES: tuple[str, ...]
9
+ SCHEMA_TO_SPEC: dict[str, str]
10
+ SKIPPED_SCHEMA_NAMES: tuple[str, ...]
11
+
12
+ def spec_names() -> tuple[str, ...]: ...
13
+ def uncovered_schema_names() -> tuple[str, ...]: ...
sayso/transport.py ADDED
@@ -0,0 +1,426 @@
1
+ # SPDX-FileCopyrightText: 2026 Brad Barnett
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+
5
+ API_BASE_URL = "https://api.spotify.com/v1"
6
+
7
+ # Resolved once here, never inside a function. On MicroPython json is an
8
+ # extensible built-in, so every `import json` searches the filesystem first,
9
+ # and a failing `from urllib.parse import ...` searches all of sys.path: on
10
+ # an ESP32-S3 each cost ~185 ms, several per API call (2026-09-25).
11
+ try:
12
+ import json as _json
13
+ except ImportError: # pragma: no cover
14
+ _json = None
15
+
16
+ try:
17
+ from urllib.parse import quote as _urllib_quote
18
+ from urllib.parse import unquote as _urllib_unquote
19
+ except ImportError:
20
+ _urllib_quote = None
21
+ _urllib_unquote = None
22
+
23
+
24
+ class TransportError(Exception):
25
+ def __init__(self, message, status=None, data=None, retry_after=None):
26
+ self.args = (message,)
27
+ self.status = status
28
+ self.data = data
29
+ # Seconds from a Retry-After header (429, 503), or None. Spotify's can
30
+ # be hours: 38108 s once an app had gone over its limit.
31
+ self.retry_after = retry_after
32
+
33
+
34
+ def _retry_after(response):
35
+ headers = getattr(response, "headers", None)
36
+ if headers is None:
37
+ return None
38
+ try:
39
+ value = headers.get("retry-after")
40
+ if value is None:
41
+ value = headers.get("Retry-After")
42
+ return int(value) if value is not None else None
43
+ except (AttributeError, TypeError, ValueError):
44
+ return None
45
+
46
+
47
+ def _find_requests():
48
+ import sys
49
+
50
+ # MicroPython's requests does a TLS handshake per request; keep the
51
+ # connection open instead (see keepalive.py).
52
+ if sys.implementation.name == "micropython":
53
+ try:
54
+ from .keepalive import Session
55
+
56
+ return Session()
57
+ except ImportError:
58
+ pass
59
+
60
+ try:
61
+ import requests
62
+
63
+ return requests
64
+ except ImportError:
65
+ pass
66
+
67
+ try:
68
+ import ssl
69
+ import wifi
70
+ import socketpool
71
+ import adafruit_requests
72
+
73
+ pool = socketpool.SocketPool(wifi.radio)
74
+ return adafruit_requests.Session(pool, ssl.create_default_context())
75
+ except ImportError:
76
+ pass
77
+
78
+ raise TransportError(
79
+ "No HTTP client is available. Install the requests package, or on "
80
+ "CircuitPython use wifi, socketpool, ssl, and adafruit_requests."
81
+ )
82
+
83
+
84
+ requests = _find_requests()
85
+
86
+
87
+ def get_json(path_or_url, access_token=None, query=None, headers=None, base_url=API_BASE_URL):
88
+ url = build_url(path_or_url, query=query, base_url=base_url)
89
+ request_headers = {}
90
+
91
+ if headers:
92
+ request_headers.update(headers)
93
+ if access_token is not None:
94
+ request_headers["Authorization"] = "Bearer " + access_token
95
+
96
+ response = requests.get(url, headers=request_headers)
97
+ return response_json(response)
98
+
99
+
100
+ def get_bytes(path_or_url, access_token=None, query=None, headers=None, base_url=API_BASE_URL):
101
+ url = build_url(path_or_url, query=query, base_url=base_url)
102
+ request_headers = {}
103
+
104
+ if headers:
105
+ request_headers.update(headers)
106
+ if access_token is not None:
107
+ request_headers["Authorization"] = "Bearer " + access_token
108
+
109
+ response = requests.get(url, headers=request_headers)
110
+ return response_bytes(response)
111
+
112
+
113
+ def post_form_json(url, data, headers=None):
114
+ request_headers = {"Content-Type": "application/x-www-form-urlencoded"}
115
+ if headers:
116
+ request_headers.update(headers)
117
+
118
+ body = query_string(data)
119
+ response = requests.post(url, data=body, headers=request_headers)
120
+ return response_json(response)
121
+
122
+
123
+ def post_json(path_or_url, data=None, access_token=None, query=None, headers=None, base_url=API_BASE_URL):
124
+ return request_json("POST", path_or_url, data, access_token, query, headers, base_url)
125
+
126
+
127
+ def put_json(path_or_url, data=None, access_token=None, query=None, headers=None, base_url=API_BASE_URL):
128
+ return request_json("PUT", path_or_url, data, access_token, query, headers, base_url)
129
+
130
+
131
+ def delete_json(path_or_url, data=None, access_token=None, query=None, headers=None, base_url=API_BASE_URL):
132
+ return request_json("DELETE", path_or_url, data, access_token, query, headers, base_url)
133
+
134
+
135
+ def put_body(path_or_url, body, content_type, access_token=None, query=None, headers=None, base_url=API_BASE_URL):
136
+ return request_body("PUT", path_or_url, body, content_type, access_token, query, headers, base_url)
137
+
138
+
139
+ def request_json(method, path_or_url, data=None, access_token=None, query=None, headers=None, base_url=API_BASE_URL):
140
+ url = build_url(path_or_url, query=query, base_url=base_url)
141
+ request_headers = {}
142
+
143
+ if headers:
144
+ request_headers.update(headers)
145
+ if access_token is not None:
146
+ request_headers["Authorization"] = "Bearer " + access_token
147
+
148
+ body = None
149
+ if data is not None:
150
+ request_headers["Content-Type"] = "application/json"
151
+ body = json_dumps(data)
152
+
153
+ response = http_request(method, url, body, request_headers)
154
+ return response_json(response)
155
+
156
+
157
+ def request_body(method, path_or_url, body, content_type, access_token=None, query=None, headers=None, base_url=API_BASE_URL):
158
+ url = build_url(path_or_url, query=query, base_url=base_url)
159
+ request_headers = {"Content-Type": content_type}
160
+
161
+ if headers:
162
+ request_headers.update(headers)
163
+ if access_token is not None:
164
+ request_headers["Authorization"] = "Bearer " + access_token
165
+
166
+ response = http_request(method, url, body, request_headers)
167
+ return response_json(response)
168
+
169
+
170
+ def http_request(method, url, body, headers):
171
+ method_name = method.lower()
172
+ if body is None and method_name in ("post", "put", "patch", "delete"):
173
+ if "Content-Length" not in headers:
174
+ headers["Content-Length"] = "0"
175
+ body = ""
176
+
177
+ if hasattr(requests, method_name):
178
+ request_method = getattr(requests, method_name)
179
+ if body is None:
180
+ return request_method(url, headers=headers)
181
+ return request_method(url, data=body, headers=headers)
182
+
183
+ if hasattr(requests, "request"):
184
+ return requests.request(method, url, data=body, headers=headers)
185
+
186
+ raise TransportError("HTTP {} is not supported by the current requests backend".format(method))
187
+
188
+
189
+ def response_json(response):
190
+ data = None
191
+ try:
192
+ status = response_status(response)
193
+ if status == 204:
194
+ return None
195
+
196
+ try:
197
+ data = parse_response_json(response, status=status)
198
+ except ValueError:
199
+ if status is not None and (status < 200 or status >= 300):
200
+ data = _response_error_data(response)
201
+ raise TransportError("HTTP status {}".format(status), status, data, _retry_after(response))
202
+ raise
203
+ finally:
204
+ close_response(response)
205
+
206
+ if status is not None and (status < 200 or status >= 300):
207
+ raise TransportError("HTTP status {}".format(status), status, data, _retry_after(response))
208
+
209
+ return data
210
+
211
+
212
+ def response_bytes(response):
213
+ try:
214
+ status = response_status(response)
215
+ data = read_response_bytes(response)
216
+ finally:
217
+ close_response(response)
218
+
219
+ if status is not None and (status < 200 or status >= 300):
220
+ raise TransportError("HTTP status {}".format(status), status, data, _retry_after(response))
221
+
222
+ return data
223
+
224
+
225
+ def response_status(response):
226
+ if hasattr(response, "status_code"):
227
+ return response.status_code
228
+ if hasattr(response, "status"):
229
+ return response.status
230
+ if hasattr(response, "code"):
231
+ return response.code
232
+ if hasattr(response, "getcode"):
233
+ return response.getcode()
234
+ return None
235
+
236
+
237
+ def read_response_text(response):
238
+ if hasattr(response, "text"):
239
+ return response.text
240
+
241
+ if hasattr(response, "content"):
242
+ content = response.content
243
+ if not isinstance(content, str):
244
+ content = content.decode("utf-8")
245
+ return content
246
+
247
+ if hasattr(response, "read"):
248
+ data = response.read()
249
+ if not isinstance(data, str):
250
+ data = data.decode("utf-8")
251
+ return data
252
+
253
+ return ""
254
+
255
+
256
+ def read_response_bytes(response):
257
+ if hasattr(response, "content"):
258
+ content = response.content
259
+ if isinstance(content, str):
260
+ content = content.encode("utf-8")
261
+ return content
262
+
263
+ if hasattr(response, "read"):
264
+ data = response.read()
265
+ if isinstance(data, str):
266
+ data = data.encode("utf-8")
267
+ return data
268
+
269
+ if hasattr(response, "text"):
270
+ return response.text.encode("utf-8")
271
+
272
+ return b""
273
+
274
+
275
+ def parse_response_json(response, status=None):
276
+ if hasattr(response, "json"):
277
+ try:
278
+ return response.json()
279
+ except ValueError:
280
+ if _empty_response_body(response):
281
+ return None
282
+ if _successful_status(status):
283
+ return None
284
+ raise
285
+
286
+ if hasattr(response, "text") or hasattr(response, "content") or hasattr(response, "read"):
287
+ body = read_response_text(response)
288
+ if not body or not body.strip():
289
+ return None
290
+
291
+ try:
292
+ return json_loads(body)
293
+ except ValueError:
294
+ if _successful_status(status):
295
+ return None
296
+ raise
297
+
298
+ return response
299
+
300
+
301
+ def _empty_response_body(response):
302
+ body = read_response_text(response)
303
+ return not body or not body.strip()
304
+
305
+
306
+ def _response_error_data(response):
307
+ body = read_response_text(response)
308
+ if not body or not body.strip():
309
+ return None
310
+
311
+ try:
312
+ return json_loads(body)
313
+ except ValueError:
314
+ return body
315
+
316
+
317
+ def _successful_status(status):
318
+ return status is not None and 200 <= status < 300
319
+
320
+
321
+ def close_connections():
322
+ """Drop the backend's kept-alive connections, if it keeps any; otherwise do nothing."""
323
+ close = getattr(requests, "close", None)
324
+ if close is not None:
325
+ close()
326
+
327
+
328
+ def close_response(response):
329
+ if hasattr(response, "close"):
330
+ response.close()
331
+ elif hasattr(response, "deinit"):
332
+ response.deinit()
333
+
334
+
335
+ def json_loads(data):
336
+ if _json is None:
337
+ raise TransportError("No JSON parser is available on this Python runtime")
338
+
339
+ if not isinstance(data, str):
340
+ data = data.decode("utf-8")
341
+
342
+ return _json.loads(data)
343
+
344
+
345
+ def json_dumps(data):
346
+ if _json is None:
347
+ raise TransportError("No JSON serializer is available on this Python runtime")
348
+
349
+ return _json.dumps(data)
350
+
351
+
352
+ def build_url(path_or_url, query=None, base_url=API_BASE_URL):
353
+ if path_or_url.startswith("http://") or path_or_url.startswith("https://"):
354
+ url = path_or_url
355
+ else:
356
+ url = base_url + path_or_url
357
+
358
+ encoded = query_string(query)
359
+ if encoded:
360
+ return url + "?" + encoded
361
+ return url
362
+
363
+
364
+ def query_string(query):
365
+ if not query:
366
+ return ""
367
+
368
+ parts = []
369
+ for key in query:
370
+ value = query[key]
371
+ if value is not None:
372
+ parts.append(quote(key) + "=" + quote(value))
373
+ return "&".join(parts)
374
+
375
+
376
+ def quote(value):
377
+ value = str(value)
378
+
379
+ if _urllib_quote is not None:
380
+ return _urllib_quote(value, safe="")
381
+ return simple_quote(value)
382
+
383
+
384
+ def unquote_plus(value):
385
+ value = value.replace("+", " ")
386
+
387
+ if _urllib_unquote is not None:
388
+ return _urllib_unquote(value)
389
+ return simple_unquote(value)
390
+
391
+
392
+ def simple_quote(value):
393
+ safe = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.~"
394
+ encoded = []
395
+
396
+ for char in value:
397
+ if char in safe:
398
+ encoded.append(char)
399
+ else:
400
+ for byte in char.encode("utf-8"):
401
+ encoded.append("%{:02X}".format(byte))
402
+
403
+ return "".join(encoded)
404
+
405
+
406
+ def simple_unquote(value):
407
+ chunks = []
408
+ index = 0
409
+ length = len(value)
410
+
411
+ while index < length:
412
+ char = value[index]
413
+ if char == "%" and index + 2 < length:
414
+ hex_value = value[index + 1:index + 3]
415
+ try:
416
+ chunks.append(int(hex_value, 16))
417
+ index += 3
418
+ continue
419
+ except ValueError:
420
+ pass
421
+
422
+ for byte in char.encode("utf-8"):
423
+ chunks.append(byte)
424
+ index += 1
425
+
426
+ return bytes(chunks).decode("utf-8")
sayso/transport.pyi ADDED
@@ -0,0 +1,47 @@
1
+ # SPDX-FileCopyrightText: 2026 Brad Barnett
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+ """HTTP and JSON helpers for the Spotify Web API, on top of whatever HTTP client the runtime has."""
5
+
6
+ from collections.abc import Mapping
7
+ from typing import Any
8
+
9
+ API_BASE_URL: str
10
+
11
+ class TransportError(Exception):
12
+ """An HTTP request failed; `status` and `data` carry the response, `retry_after` the wait in seconds."""
13
+
14
+ args: tuple[str]
15
+ status: int | None
16
+ data: Any
17
+ retry_after: int | None
18
+ def __init__(self, message: str, status: int | None = None, data: Any = None, retry_after: int | None = None) -> None: ...
19
+
20
+ requests: Any
21
+
22
+ def get_json(path_or_url: str, access_token: str | None = None, query: Mapping[str, Any] | None = None, headers: Mapping[str, str] | None = None, base_url: str = ...) -> Any: ...
23
+ def get_bytes(path_or_url: str, access_token: str | None = None, query: Mapping[str, Any] | None = None, headers: Mapping[str, str] | None = None, base_url: str = ...) -> bytes: ...
24
+ def post_form_json(url: str, data: Mapping[str, Any], headers: Mapping[str, str] | None = None) -> Any: ...
25
+ def post_json(path_or_url: str, data: Any = None, access_token: str | None = None, query: Mapping[str, Any] | None = None, headers: Mapping[str, str] | None = None, base_url: str = ...) -> Any: ...
26
+ def put_json(path_or_url: str, data: Any = None, access_token: str | None = None, query: Mapping[str, Any] | None = None, headers: Mapping[str, str] | None = None, base_url: str = ...) -> Any: ...
27
+ def delete_json(path_or_url: str, data: Any = None, access_token: str | None = None, query: Mapping[str, Any] | None = None, headers: Mapping[str, str] | None = None, base_url: str = ...) -> Any: ...
28
+ def put_body(path_or_url: str, body: str | bytes, content_type: str, access_token: str | None = None, query: Mapping[str, Any] | None = None, headers: Mapping[str, str] | None = None, base_url: str = ...) -> Any: ...
29
+ def request_json(method: str, path_or_url: str, data: Any = None, access_token: str | None = None, query: Mapping[str, Any] | None = None, headers: Mapping[str, str] | None = None, base_url: str = ...) -> Any: ...
30
+ def request_body(method: str, path_or_url: str, body: str | bytes, content_type: str, access_token: str | None = None, query: Mapping[str, Any] | None = None, headers: Mapping[str, str] | None = None, base_url: str = ...) -> Any: ...
31
+ def http_request(method: str, url: str, body: str | bytes | None, headers: dict[str, str]) -> Any: ...
32
+ def response_json(response: Any) -> Any: ...
33
+ def response_bytes(response: Any) -> bytes: ...
34
+ def response_status(response: Any) -> int | None: ...
35
+ def read_response_text(response: Any) -> str: ...
36
+ def read_response_bytes(response: Any) -> bytes: ...
37
+ def parse_response_json(response: Any, status: int | None = None) -> Any: ...
38
+ def close_connections() -> None: ...
39
+ def close_response(response: Any) -> None: ...
40
+ def json_loads(data: str | bytes) -> Any: ...
41
+ def json_dumps(data: Any) -> str: ...
42
+ def build_url(path_or_url: str, query: Mapping[str, Any] | None = None, base_url: str = ...) -> str: ...
43
+ def query_string(query: Mapping[str, Any] | None) -> str: ...
44
+ def quote(value: object) -> str: ...
45
+ def unquote_plus(value: str) -> str: ...
46
+ def simple_quote(value: str) -> str: ...
47
+ def simple_unquote(value: str) -> str: ...