Files
typeshed/stdlib
Philipp Hahn 277202cf7e Xmlrpc: accept data:str|bytes and require method:str (#12734)
Declared <https://github.com/python/cpython/blob/main/Lib/xmlrpc/server.py#L622>

Inside
[`do_POST()`](https://github.com/python/cpython/blob/main/Lib/xmlrpc/server.py#L493)
`data: bytes`, where `decode_request_content()` only handles `gzip`
compression.
The `result` is then written to `self.wfile`, which uses `bytes`.

But for
[CGI](https://github.com/python/cpython/blob/main/Lib/xmlrpc/server.py#L636)
`str` is used: [`handle_xmlrpc(self,
request_text)`](https://github.com/python/cpython/blob/main/Lib/xmlrpc/server.py#L642)
calls the argument `request_text`, which is read from `sys.stdin` as
type `str` and then passed to `_marshaled_dispatch()`, which internally calls
[`xmlrpc.client.loads()`](https://github.com/python/cpython/blob/main/Lib/xmlrpc/server.py#L257)
to parse the XML using Expat, which accepts both `str` and `bytes`; the
later defaults to encoding `utf-8`, but other encodings can be
used when explicitly specified:

>>> xmlrpc.client.loads('<params><param><value><string>ä</string></value></param></params>')
(('ä',), None)
>>> xmlrpc.client.loads('<params><param><value><string>ä</string></value></param></params>'.encode("utf-8"))
(('ä',), None)
>>> xmlrpc.client.loads('<params><param><value><string>ä</string></value></param></params>'.encode("iso-8859-1"))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.11/xmlrpc/client.py", line 1029, in loads
    p.feed(data)
  File "/usr/lib/python3.11/xmlrpc/client.py", line 451, in feed
    self._parser.Parse(data, False)
xml.parsers.expat.ExpatError: not well-formed (invalid token): line 3, column 15
>>> xmlrpc.client.loads('<?xml version="1.0" encoding="utf-8"?><params><param><value><string>ä</string></value></param></params>'.encode("iso-8859-1"))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.11/xmlrpc/client.py", line 1029, in loads
    p.feed(data)
  File "/usr/lib/python3.11/xmlrpc/client.py", line 451, in feed
    self._parser.Parse(data, False)
xml.parsers.expat.ExpatError: not well-formed (invalid token): line 1, column 68
>>> xmlrpc.client.loads('<?xml version="1.0" encoding="iso-8859-1"?><params><param><value><string>ä</string></value></param></params>'.encode("iso-8859-1"))
(('ä',), None)

Signed-off-by: Philipp Hahn <hahn@univention.de>
Reviewed-By: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2024-10-04 07:12:02 -07:00
..
2024-10-03 11:33:56 +02:00
2024-08-04 23:19:28 -07:00
2024-07-11 17:51:53 +02:00
2024-08-17 21:57:56 +02:00
2024-08-04 23:19:28 -07:00
2024-02-04 16:38:55 -08:00
2024-05-18 00:06:55 +02:00
2021-05-06 18:57:33 +03:00
2024-10-03 11:33:56 +02:00
2024-08-09 19:19:19 +02:00
2024-03-09 14:50:16 -08:00
2024-02-16 08:38:49 -08:00
2024-03-09 14:50:16 -08:00
2024-10-01 20:10:51 -07:00
2024-08-17 22:14:45 +02:00
2024-08-17 22:34:16 +02:00
2024-10-01 19:50:10 -07:00
2024-08-10 23:51:19 +03:00
2024-05-18 13:32:53 -07:00
2024-05-21 11:30:11 +02:00
2024-03-09 14:50:16 -08:00
2024-08-17 21:59:49 +02:00
2024-05-18 16:22:22 -04:00
2022-02-19 12:26:45 -08:00
2023-02-06 19:01:02 -08:00
2024-10-03 11:33:56 +02:00
2024-09-08 12:38:13 +02:00
2024-08-05 13:31:12 -07:00
2024-02-04 16:38:55 -08:00
2024-03-09 14:50:16 -08:00
2024-03-09 14:50:16 -08:00
2024-07-10 00:18:18 +02:00
2024-07-20 21:38:30 -07:00
2022-01-30 16:27:06 -08:00
2024-05-18 05:49:06 -04:00
2024-08-04 23:19:28 -07:00
2024-01-05 11:39:39 +01:00
2024-08-10 23:08:03 +03:00
2024-03-09 14:50:16 -08:00
2023-12-12 21:24:27 +01:00
2024-10-02 11:26:44 +02:00
2024-07-11 16:54:12 -07:00
2024-10-01 20:10:51 -07:00
2021-12-22 20:18:19 -08:00
2024-01-05 11:39:39 +01:00
2024-07-20 14:07:00 -07:00
2024-05-27 10:27:23 +01:00
2024-08-04 23:19:28 -07:00
2024-08-04 23:19:28 -07:00
2024-10-01 20:10:51 -07:00
2024-10-01 19:50:10 -07:00