xtr-http-message 6.2.0__tar.gz → 6.3.1__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.
Files changed (27) hide show
  1. {xtr_http_message-6.2.0 → xtr_http_message-6.3.1}/PKG-INFO +7 -5
  2. {xtr_http_message-6.2.0 → xtr_http_message-6.3.1}/README.md +6 -4
  3. {xtr_http_message-6.2.0 → xtr_http_message-6.3.1}/pyproject.toml +1 -1
  4. {xtr_http_message-6.2.0 → xtr_http_message-6.3.1}/pyproject.toml.orig +1 -1
  5. {xtr_http_message-6.2.0 → xtr_http_message-6.3.1}/src/xtr_http_message/.agents/skills/xtr-http-message/SKILL.md +9 -6
  6. {xtr_http_message-6.2.0 → xtr_http_message-6.3.1}/src/xtr_http_message/_connected_trait.py +14 -10
  7. {xtr_http_message-6.2.0 → xtr_http_message-6.3.1}/src/xtr_http_message/server_request.py +40 -15
  8. {xtr_http_message-6.2.0 → xtr_http_message-6.3.1}/LICENSE +0 -0
  9. {xtr_http_message-6.2.0 → xtr_http_message-6.3.1}/src/xtr_http_message/__init__.py +0 -0
  10. {xtr_http_message-6.2.0 → xtr_http_message-6.3.1}/src/xtr_http_message/_ascii.py +0 -0
  11. {xtr_http_message-6.2.0 → xtr_http_message-6.3.1}/src/xtr_http_message/_message_trait.py +0 -0
  12. {xtr_http_message-6.2.0 → xtr_http_message-6.3.1}/src/xtr_http_message/_request_trait.py +0 -0
  13. {xtr_http_message-6.2.0 → xtr_http_message-6.3.1}/src/xtr_http_message/exception/__init__.py +0 -0
  14. {xtr_http_message-6.2.0 → xtr_http_message-6.3.1}/src/xtr_http_message/exception/http_message_error.py +0 -0
  15. {xtr_http_message-6.2.0 → xtr_http_message-6.3.1}/src/xtr_http_message/exception/invalid_argument_error.py +0 -0
  16. {xtr_http_message-6.2.0 → xtr_http_message-6.3.1}/src/xtr_http_message/exception/stream_error.py +0 -0
  17. {xtr_http_message-6.2.0 → xtr_http_message-6.3.1}/src/xtr_http_message/exception/uploaded_file_error.py +0 -0
  18. {xtr_http_message-6.2.0 → xtr_http_message-6.3.1}/src/xtr_http_message/factory/__init__.py +0 -0
  19. {xtr_http_message-6.2.0 → xtr_http_message-6.3.1}/src/xtr_http_message/factory/http_factory.py +0 -0
  20. {xtr_http_message-6.2.0 → xtr_http_message-6.3.1}/src/xtr_http_message/lazy_stream.py +0 -0
  21. {xtr_http_message-6.2.0 → xtr_http_message-6.3.1}/src/xtr_http_message/py.typed +0 -0
  22. {xtr_http_message-6.2.0 → xtr_http_message-6.3.1}/src/xtr_http_message/request.py +0 -0
  23. {xtr_http_message-6.2.0 → xtr_http_message-6.3.1}/src/xtr_http_message/request_source.py +0 -0
  24. {xtr_http_message-6.2.0 → xtr_http_message-6.3.1}/src/xtr_http_message/response.py +0 -0
  25. {xtr_http_message-6.2.0 → xtr_http_message-6.3.1}/src/xtr_http_message/stream.py +0 -0
  26. {xtr_http_message-6.2.0 → xtr_http_message-6.3.1}/src/xtr_http_message/uploaded_file.py +0 -0
  27. {xtr_http_message-6.2.0 → xtr_http_message-6.3.1}/src/xtr_http_message/uri.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: xtr-http-message
3
- Version: 6.2.0
3
+ Version: 6.3.1
4
4
  Summary: A strict, framework-free implementation of the HTTP message contract: requests, responses, streams, URIs, uploaded files and one factory for all six.
5
5
  Keywords: http,http-message,request,response,stream,uri,uploaded-file
6
6
  Author: Xterr
@@ -213,10 +213,12 @@ side comes from the source:
213
213
  materialises it at the one seam that can still await, before the message is handed on.
214
214
  - **The attributes are live**, read off the source each time: the named parameters a matched
215
215
  route fills in are there as soon as routing has filled them.
216
- - **The `with_*` members detach.** The copy is a plain eager request — the attributes frozen to
217
- the current snapshot, the parsed body and files to the current peek, the body the one shared
218
- lazy stream — so a change a handler makes never reaches the connection, and the copy never
219
- reads the source again.
216
+ - **The `with_*` members detach.** The copy is a plain request — the head as it was passed, the
217
+ attributes frozen to the current snapshot, the body the one shared lazy stream — so a change a
218
+ handler makes never reaches the connection. Its parsed body and uploaded files stay linked to
219
+ the source until `with_parsed_body()` or `with_uploaded_files()` gives the copy its own: a read
220
+ of the body made after the copy — through it, the request or any other copy — is answered by
221
+ the copy too, and `await copy.ensure_parsed()` materialises the body through the copy.
220
222
 
221
223
  `body=` is refused alongside `source=` — one owner of the body. A header the message grammar
222
224
  refuses is left out rather than refusing the request: a connection let it through.
@@ -190,10 +190,12 @@ side comes from the source:
190
190
  materialises it at the one seam that can still await, before the message is handed on.
191
191
  - **The attributes are live**, read off the source each time: the named parameters a matched
192
192
  route fills in are there as soon as routing has filled them.
193
- - **The `with_*` members detach.** The copy is a plain eager request — the attributes frozen to
194
- the current snapshot, the parsed body and files to the current peek, the body the one shared
195
- lazy stream — so a change a handler makes never reaches the connection, and the copy never
196
- reads the source again.
193
+ - **The `with_*` members detach.** The copy is a plain request — the head as it was passed, the
194
+ attributes frozen to the current snapshot, the body the one shared lazy stream — so a change a
195
+ handler makes never reaches the connection. Its parsed body and uploaded files stay linked to
196
+ the source until `with_parsed_body()` or `with_uploaded_files()` gives the copy its own: a read
197
+ of the body made after the copy — through it, the request or any other copy — is answered by
198
+ the copy too, and `await copy.ensure_parsed()` materialises the body through the copy.
197
199
 
198
200
  `body=` is refused alongside `source=` — one owner of the body. A header the message grammar
199
201
  refuses is left out rather than refusing the request: a connection let it through.
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "xtr-http-message"
3
- version = "6.2.0"
3
+ version = "6.3.1"
4
4
  description = "A strict, framework-free implementation of the HTTP message contract: requests, responses, streams, URIs, uploaded files and one factory for all six."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.11"
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "xtr-http-message"
3
- version = "6.2.0"
3
+ version = "6.3.1"
4
4
  description = "A strict, framework-free implementation of the HTTP message contract: requests, responses, streams, URIs, uploaded files and one factory for all six."
5
5
  readme = "README.md"
6
6
  authors = [
@@ -130,9 +130,11 @@ served = ServerRequest.over(
130
130
  - `get_parsed_body()` and `get_uploaded_files()` answer what materialisation has yielded so
131
131
  far; `await served.ensure_parsed()` materialises it at the one seam that can still await.
132
132
  - `get_attributes()` reads the source live, each time.
133
- - The `with_*` members detach: plain eager copies — attributes frozen to the snapshot, parsed
134
- body and files to the peek, body the one shared lazy stream — that never read the source
135
- again.
133
+ - The `with_*` members detach: plain copies — attributes frozen to the snapshot, body the one
134
+ shared lazy stream — whose parsed body and files stay linked to the source until
135
+ `with_parsed_body()` / `with_uploaded_files()` gives the copy its own, so a body read after the
136
+ copy was made is answered by the copy too; `await copy.ensure_parsed()` reads it through the
137
+ copy.
136
138
  - `body=` is refused alongside `source=`: one owner of the body.
137
139
 
138
140
  ## Take a URI apart and put one together
@@ -322,9 +324,10 @@ implementation can catch `HttpMessageError` and get only its failures.
322
324
  - Do not expect a `with_*` method to change the message it was called on: it returns a new one,
323
325
  and returns the same one when nothing would change. `request.with_header(...)` on its own does
324
326
  nothing — keep the result.
325
- - Do not expect `get_parsed_body()` or `get_uploaded_files()` on a connected request to answer
326
- before its body has been read: they answer what materialisation has yielded, and
327
- `await served.ensure_parsed()` is the seam that materialises it.
327
+ - Do not expect `get_parsed_body()` or `get_uploaded_files()` on a connected request — or on a
328
+ copy of one — to answer before its body has been read: they answer what materialisation has
329
+ yielded, and `await served.ensure_parsed()`, on the request or on any copy of it, is the seam
330
+ that materialises it.
328
331
  - Do not change a mapping or list one of the getters handed you and expect the message to follow:
329
332
  every one of them hands back a fresh copy.
330
333
  - Do not import these classes in a library that only handles messages — depend on
@@ -31,10 +31,14 @@ class ConnectedTrait(RequestTrait):
31
31
  """The body side of a server request that arrives late, over a source.
32
32
 
33
33
  The ``with_*`` members a connected request answers detach: the copy
34
- is a plain eager request — the live parts frozen to what they answer
35
- at that moment — so a change a listener makes never reaches the
36
- connection. Because the copy is the same class, the ``Self`` the
37
- ``with_*`` members promise is finally the whole truth.
34
+ is a plain request — the head and the attributes frozen to what they
35
+ answer at that moment — so a change a listener makes never reaches the
36
+ connection. The copy shares the one lazy body, and its parsed body and
37
+ uploaded files stay linked to the source until it is given its own, so
38
+ the body may be read before the copy is made or after it, through the
39
+ copy or through the request, and the copy answers the read either way.
40
+ Because the copy is the same class, the ``Self`` the ``with_*`` members
41
+ promise is finally the whole truth.
38
42
  """
39
43
 
40
44
  __slots__: ClassVar[tuple[str, ...]] = ("_source",)
@@ -62,18 +66,18 @@ class ConnectedTrait(RequestTrait):
62
66
  return super().get_body()
63
67
 
64
68
  async def ensure_parsed(self) -> None:
65
- """Materialise the body side, when connected and nothing has read it yet.
69
+ """Materialise the body side, when it is a lazy body nothing has read yet.
66
70
 
67
71
  The seam that can still await calls this before the message is
68
72
  handed on: a consumer written against the contract reads
69
73
  :meth:`~xtr_http_message.server_request.ServerRequest.get_parsed_body`
70
74
  without reading the stream first, and only a body that has been
71
- read can answer it. A no-op for an eager request, and for one
72
- whose body has already been read.
75
+ read can answer it. A copy of a connected request shares its lazy
76
+ body, so materialising through the copy materialises the request's,
77
+ and the copy — its parsed side linked to the source — answers what
78
+ that yields. A no-op for a body that has already been read, and for
79
+ an eager request, which holds no lazy body.
73
80
  """
74
- if self._source is None:
75
- return
76
-
77
81
  body = self.get_body()
78
82
  if isinstance(body, LazyStream) and not body.materialised:
79
83
  _ = await body.get_contents()
@@ -96,13 +96,22 @@ class ServerRequest(ConnectedTrait, ServerRequestInterface):
96
96
  :meth:`over`. Its head is passed eagerly; its body is one lazy stream
97
97
  that materialises on first read; its parsed body, uploaded files and
98
98
  attributes answer what the source has yielded so far, the attributes
99
- live. The ``with_*`` members of such a request detach: plain eager
100
- copies, so a change a handler makes never reaches the connection.
99
+ live. The ``with_*`` members of such a request detach: the copy is
100
+ eager in everything a handler can change — the head as it was passed,
101
+ the attributes a snapshot — so a change a handler makes never reaches
102
+ the connection. Its parsed body and uploaded files stay linked to the
103
+ source until :meth:`with_parsed_body` or :meth:`with_uploaded_files`
104
+ gives the copy its own: a listener is handed a copy before anything has
105
+ read the body, and a read made after the copy — through it, through the
106
+ request or through any other copy — is answered by the copy too.
101
107
  """
102
108
 
103
109
  __slots__ = (
104
110
  "_attributes",
111
+ "_body_source",
105
112
  "_cookie_params",
113
+ "_own_parsed_body",
114
+ "_own_uploaded_files",
106
115
  "_parsed_body",
107
116
  "_query_params",
108
117
  "_server_params",
@@ -144,6 +153,9 @@ class ServerRequest(ConnectedTrait, ServerRequestInterface):
144
153
  self._cookie_params: Mapping[str, str] = {}
145
154
  self._parsed_body: object | None = None
146
155
  self._uploaded_files: Mapping[str, object] = {}
156
+ self._body_source: RequestSource | None = None
157
+ self._own_parsed_body = False
158
+ self._own_uploaded_files = False
147
159
 
148
160
  self._method = method
149
161
  self._uri = Uri(uri) if isinstance(uri, str) else uri
@@ -308,10 +320,13 @@ class ServerRequest(ConnectedTrait, ServerRequestInterface):
308
320
  where nothing can change it, otherwise a fresh one. Empty when no
309
321
  file came with the request. A request built over a connection
310
322
  answers what its body's materialisation has gathered so far:
311
- empty until the body has been read.
323
+ empty until the body has been read — and so does a copy of one,
324
+ until it is given files of its own.
312
325
  """
313
326
  if self._source is not None:
314
327
  return self._source.uploaded_files()
328
+ if self._body_source is not None and not self._own_uploaded_files:
329
+ return self._body_source.uploaded_files()
315
330
 
316
331
  return _held(self._uploaded_files)
317
332
 
@@ -324,10 +339,13 @@ class ServerRequest(ConnectedTrait, ServerRequestInterface):
324
339
  :meth:`get_uploaded_files` describes.
325
340
 
326
341
  Returns:
327
- A new instance; this one is left as it was.
342
+ A new instance answering ``uploaded_files`` from now on, however
343
+ late the body of the connection it was copied from is read; this
344
+ one is left as it was.
328
345
  """
329
346
  new = self._copy()
330
347
  new._uploaded_files = _held(uploaded_files) # noqa: SLF001 — a copy of this class.
348
+ new._own_uploaded_files = True # noqa: SLF001 — a copy of this very class.
331
349
 
332
350
  return new
333
351
 
@@ -339,10 +357,13 @@ class ServerRequest(ConnectedTrait, ServerRequestInterface):
339
357
  Whatever parsing the body yielded, or ``None`` when nothing has
340
358
  been parsed into the request. A request built over a connection
341
359
  answers what its body's materialisation has yielded so far:
342
- ``None`` until the body has been read.
360
+ ``None`` until the body has been read — and so does a copy of
361
+ one, until it is given a parsed body of its own.
343
362
  """
344
363
  if self._source is not None:
345
364
  return self._source.parsed_body()
365
+ if self._body_source is not None and not self._own_parsed_body:
366
+ return self._body_source.parsed_body()
346
367
 
347
368
  return self._parsed_body
348
369
 
@@ -356,7 +377,9 @@ class ServerRequest(ConnectedTrait, ServerRequestInterface):
356
377
  there was nothing to parse.
357
378
 
358
379
  Returns:
359
- A new instance; this one is left as it was.
380
+ A new instance answering ``data`` from now on, however late the
381
+ body of the connection it was copied from is read; this one is
382
+ left as it was.
360
383
 
361
384
  Raises:
362
385
  InvalidArgumentError: When the data is a scalar: parsing a body
@@ -370,6 +393,7 @@ class ServerRequest(ConnectedTrait, ServerRequestInterface):
370
393
 
371
394
  new = self._copy()
372
395
  new._parsed_body = data # noqa: SLF001 — a copy of this very class.
396
+ new._own_parsed_body = True # noqa: SLF001 — a copy of this very class.
373
397
 
374
398
  return new
375
399
 
@@ -466,13 +490,15 @@ class ServerRequest(ConnectedTrait, ServerRequestInterface):
466
490
  def _copy(self) -> Self:
467
491
  """Return a copy to change, leaving this instance as it is.
468
492
 
469
- A connected request's copy detaches: it is a plain eager request,
470
- carrying the head as it was passed and the live parts frozen to
471
- what they answer at this moment — the attributes as a snapshot,
472
- the parsed body and the uploaded files as the source's peeks. The
473
- body is the one lazy stream, shared: one materialisation serves
474
- the request and every copy of it, and the copy never reads the
475
- source again.
493
+ A connected request's copy detaches: it is a plain request, carrying
494
+ the head as it was passed and the attributes frozen to a snapshot of
495
+ what they answer at this moment. The body is the one lazy stream,
496
+ shared: one materialisation serves the request and every copy of it.
497
+ The parsed body and the uploaded files stay linked to the source,
498
+ which is where that materialisation lands them — so a copy made
499
+ before the body was read answers the read all the same — until
500
+ :meth:`with_parsed_body` or :meth:`with_uploaded_files` gives the
501
+ copy its own. A copy of the copy carries the link along.
476
502
  """
477
503
  source = self._source
478
504
  if source is None:
@@ -481,8 +507,7 @@ class ServerRequest(ConnectedTrait, ServerRequestInterface):
481
507
  new = super()._copy()
482
508
  new._stream = self.get_body() # noqa: SLF001 — a copy of this very class.
483
509
  new._attributes = dict(source.attributes()) # noqa: SLF001 — a copy of this class.
484
- new._parsed_body = source.parsed_body() # noqa: SLF001 — a copy of this class.
485
- new._uploaded_files = source.uploaded_files() # noqa: SLF001 — a copy of this class.
486
510
  new._source = None # noqa: SLF001 — a copy of this very class.
511
+ new._body_source = source # noqa: SLF001 — a copy of this very class.
487
512
 
488
513
  return new