psytricks 2.2.0a22__tar.gz → 2.3.0__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.
- {psytricks-2.2.0a22 → psytricks-2.3.0}/PKG-INFO +1 -1
- {psytricks-2.2.0a22 → psytricks-2.3.0}/pyproject.toml +1 -1
- {psytricks-2.2.0a22 → psytricks-2.3.0}/src/psytricks/__init__.py +1 -1
- {psytricks-2.2.0a22 → psytricks-2.3.0}/src/psytricks/__ps1__/psytricks-lib.ps1 +1 -1
- {psytricks-2.2.0a22 → psytricks-2.3.0}/src/psytricks/wrapper.py +67 -4
- {psytricks-2.2.0a22 → psytricks-2.3.0}/INSTALLATION.md +0 -0
- {psytricks-2.2.0a22 → psytricks-2.3.0}/LICENSE +0 -0
- {psytricks-2.2.0a22 → psytricks-2.3.0}/README.md +0 -0
- {psytricks-2.2.0a22 → psytricks-2.3.0}/src/psytricks/__ps1__/psytricks-wrapper.ps1 +0 -0
- {psytricks-2.2.0a22 → psytricks-2.3.0}/src/psytricks/__ps1__/restricks-server.example.xml +0 -0
- {psytricks-2.2.0a22 → psytricks-2.3.0}/src/psytricks/__ps1__/restricks-server.ps1 +0 -0
- {psytricks-2.2.0a22 → psytricks-2.3.0}/src/psytricks/__ps1__/sampledata/GetAccessUsers.json +0 -0
- {psytricks-2.2.0a22 → psytricks-2.3.0}/src/psytricks/__ps1__/sampledata/GetMachineStatus.json +0 -0
- {psytricks-2.2.0a22 → psytricks-2.3.0}/src/psytricks/__ps1__/sampledata/GetSessions.json +0 -0
- {psytricks-2.2.0a22 → psytricks-2.3.0}/src/psytricks/cli.py +0 -0
- {psytricks-2.2.0a22 → psytricks-2.3.0}/src/psytricks/decoder.py +0 -0
- {psytricks-2.2.0a22 → psytricks-2.3.0}/src/psytricks/literals.py +0 -0
- {psytricks-2.2.0a22 → psytricks-2.3.0}/src/psytricks/mappings.py +0 -0
|
@@ -63,6 +63,7 @@ class ResTricksWrapper:
|
|
|
63
63
|
self._connected = False
|
|
64
64
|
self._verify = verify
|
|
65
65
|
self._read_only = False
|
|
66
|
+
self._dump_responses_to = None
|
|
66
67
|
|
|
67
68
|
if not lazy:
|
|
68
69
|
self.connect()
|
|
@@ -91,6 +92,44 @@ class ResTricksWrapper:
|
|
|
91
92
|
log.debug(f"{verb} 'read-only' mode.")
|
|
92
93
|
self._read_only = value
|
|
93
94
|
|
|
95
|
+
@property
|
|
96
|
+
def dump_responses_to(self) -> Path | None:
|
|
97
|
+
"""Path to dump responses to - **DO NOT USE IN PRODUCTION**.
|
|
98
|
+
|
|
99
|
+
Default: `None`, meaning responses will **not** be written to disk.
|
|
100
|
+
|
|
101
|
+
If `dump_responses_to` is set to a valid path, any response returned
|
|
102
|
+
from a request will be dumped to a file in that path. Each dump is
|
|
103
|
+
placed in a single file with the following naming pattern with the
|
|
104
|
+
components described below:
|
|
105
|
+
|
|
106
|
+
`<command>-<method>-<status>-<timestamp>.txt`
|
|
107
|
+
|
|
108
|
+
* `<command>`: e.g. `GetSessions`, `SetMaintenanceMode`
|
|
109
|
+
* `<method>`: one of [`GET`, `POST`]
|
|
110
|
+
* `<status>`: the HTTP status of the response
|
|
111
|
+
* `<timestamp>`: milliseconds since the epoch
|
|
112
|
+
|
|
113
|
+
This is intended for debugging and may also be used to craft data mocks
|
|
114
|
+
based on real data that can be used for testing.
|
|
115
|
+
|
|
116
|
+
Notes
|
|
117
|
+
-----
|
|
118
|
+
Existing files will **NOT** be overwritten, no matter how unlikely this
|
|
119
|
+
is given the above naming scheme.
|
|
120
|
+
"""
|
|
121
|
+
return self._dump_responses_to
|
|
122
|
+
|
|
123
|
+
@dump_responses_to.setter
|
|
124
|
+
def dump_responses_to(self, value: Path | None) -> None:
|
|
125
|
+
if value and not (value.is_dir() and value.exists()):
|
|
126
|
+
log.error(f"Path needs to be an existing directory: {value}")
|
|
127
|
+
return
|
|
128
|
+
|
|
129
|
+
target = str(value) if value else "<INACTIVE>"
|
|
130
|
+
log.debug(f"Setting 'dump-responses' path: {target}")
|
|
131
|
+
self._dump_responses_to = value
|
|
132
|
+
|
|
94
133
|
def connect(self) -> None:
|
|
95
134
|
"""Connect to the ResTricks service unless already connected.
|
|
96
135
|
|
|
@@ -186,9 +225,10 @@ class ResTricksWrapper:
|
|
|
186
225
|
log.error("Version mismatch! 🧨")
|
|
187
226
|
return False
|
|
188
227
|
|
|
189
|
-
|
|
190
|
-
def _check_response(response) -> None:
|
|
228
|
+
def _check_response(self, response: requests.Response) -> None:
|
|
191
229
|
"""Check the HTTP response code and JSON status attributes."""
|
|
230
|
+
self._write_response_dump(response)
|
|
231
|
+
|
|
192
232
|
if response.status_code == 200:
|
|
193
233
|
return
|
|
194
234
|
|
|
@@ -209,6 +249,29 @@ class ResTricksWrapper:
|
|
|
209
249
|
log.warning(response.text)
|
|
210
250
|
raise ValueError(f"Malformed response: {response.text}") from ex
|
|
211
251
|
|
|
252
|
+
def _write_response_dump(self, response: requests.Response) -> Path | None:
|
|
253
|
+
"""Dump the response to disk if `dump_responses_to` is set."""
|
|
254
|
+
if not self.dump_responses_to:
|
|
255
|
+
return
|
|
256
|
+
|
|
257
|
+
try:
|
|
258
|
+
timestamp = int(time.time_ns() / 1000000)
|
|
259
|
+
method = response.request.method
|
|
260
|
+
url = str(response.request.url)
|
|
261
|
+
log.trace(f"🌐 Request URL: {url}")
|
|
262
|
+
command = url.removeprefix(self.base_url).replace("/", "-")
|
|
263
|
+
status = str(response.status_code)
|
|
264
|
+
filename = f"{command}-{method}-{status}-{timestamp}.txt"
|
|
265
|
+
full_path = self.dump_responses_to / filename
|
|
266
|
+
log.warning(f"🚚 Dumping response to 🗃️: {full_path}")
|
|
267
|
+
if full_path.exists():
|
|
268
|
+
raise FileExistsError(f"File already exists: {full_path}")
|
|
269
|
+
|
|
270
|
+
with open(full_path, "w", encoding="utf8") as outfile:
|
|
271
|
+
outfile.write(response.text)
|
|
272
|
+
except Exception as ex:
|
|
273
|
+
log.error(f"🔥 Error dumping response: {ex}")
|
|
274
|
+
|
|
212
275
|
def send_get_request(
|
|
213
276
|
self, raw_url: str, auto_conn: bool = True
|
|
214
277
|
) -> list[dict] | dict | None:
|
|
@@ -258,7 +321,7 @@ class ResTricksWrapper:
|
|
|
258
321
|
log.error(f"{msg}\n== STATUS CODE:{response.status_code}")
|
|
259
322
|
raise json.JSONDecodeError(msg, doc=response.text, pos=0)
|
|
260
323
|
|
|
261
|
-
|
|
324
|
+
self._check_response(response)
|
|
262
325
|
|
|
263
326
|
return data
|
|
264
327
|
|
|
@@ -319,7 +382,7 @@ class ResTricksWrapper:
|
|
|
319
382
|
log.error(f"POST request [{raw_url}] failed: {ex}")
|
|
320
383
|
raise ex
|
|
321
384
|
|
|
322
|
-
|
|
385
|
+
self._check_response(response)
|
|
323
386
|
|
|
324
387
|
if no_json:
|
|
325
388
|
log.debug(f"No-payload response status code: {response.status_code}")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{psytricks-2.2.0a22 → psytricks-2.3.0}/src/psytricks/__ps1__/sampledata/GetMachineStatus.json
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|