summaryrefslogtreecommitdiff
path: root/dev-python/hypercorn/files/hypercorn-0.14.3-tomli.patch
blob: a438680423a9a49d284b0fa00f914d3eb1aae25e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
From 676612c73d3c231f823f88ea0995e80522db6178 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <mgorny@gentoo.org>
Date: Mon, 19 Dec 2022 15:27:41 +0100
Subject: [PATCH] Use tomllib/tomli for .toml support

Replace the unmaintained and non-conformant `toml` library with
the built-in `tomllib` module in Python 3.11+, with fallback to `tomli`
(featuring the same ABI) in Python 3.10 and older.
---
 pyproject.toml           |  2 +-
 src/hypercorn/config.py  | 10 +++++++---
 src/hypercorn/logging.py | 10 +++++++---
 tox.ini                  |  1 -
 4 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/pyproject.toml b/pyproject.toml
index 71ceaff..1334fcf 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -30,7 +30,7 @@ h11 = "*"
 h2 = ">=3.1.0"
 priority = "*"
 pydata_sphinx_theme = { version = "*", optional = true }
-toml = "*"
+tomli = { version = "*", python = "<3.11" }
 trio = { version = ">=0.11.0", optional = true }
 typing_extensions = { version = ">=3.7.4", python = "<3.8" }
 uvloop = { version = "*", markers = "platform_system != 'Windows'", optional = true }
diff --git a/src/hypercorn/config.py b/src/hypercorn/config.py
index f9a9d66..ecfa1bd 100644
--- a/src/hypercorn/config.py
+++ b/src/hypercorn/config.py
@@ -6,6 +6,7 @@ import logging
 import os
 import socket
 import stat
+import sys
 import types
 import warnings
 from dataclasses import dataclass
@@ -22,7 +23,10 @@ from time import time
 from typing import Any, AnyStr, Dict, List, Mapping, Optional, Tuple, Type, Union
 from wsgiref.handlers import format_date_time
 
-import toml
+if sys.version_info >= (3, 11):
+    import tomllib
+else:
+    import tomli as tomllib
 
 from .logging import Logger
 
@@ -355,8 +359,8 @@ class Config:
             filename: The filename which gives the path to the file.
         """
         file_path = os.fspath(filename)
-        with open(file_path) as file_:
-            data = toml.load(file_)
+        with open(file_path, "rb") as file_:
+            data = tomllib.load(file_)
         return cls.from_mapping(data)
 
     @classmethod
diff --git a/src/hypercorn/logging.py b/src/hypercorn/logging.py
index 3c2c657..8ca6105 100644
--- a/src/hypercorn/logging.py
+++ b/src/hypercorn/logging.py
@@ -9,7 +9,11 @@ from http import HTTPStatus
 from logging.config import dictConfig, fileConfig
 from typing import Any, IO, Mapping, Optional, TYPE_CHECKING, Union
 
-import toml
+if sys.version_info >= (3, 11):
+    import tomllib
+else:
+    import tomli as tomllib
+
 
 if TYPE_CHECKING:
     from .config import Config
@@ -65,8 +69,8 @@ class Logger:
                 with open(config.logconfig[5:]) as file_:
                     dictConfig(json.load(file_))
             elif config.logconfig.startswith("toml:"):
-                with open(config.logconfig[5:]) as file_:
-                    dictConfig(toml.load(file_))
+                with open(config.logconfig[5:], "rb") as file_:
+                    dictConfig(tomllib.load(file_))
             else:
                 log_config = {
                     "__file__": config.logconfig,
diff --git a/tox.ini b/tox.ini
index 675992b..0f636fb 100644
--- a/tox.ini
+++ b/tox.ini
@@ -47,7 +47,6 @@ basepython = python3.10
 deps =
     mypy
     pytest
-    types-toml
 commands =
     mypy src/hypercorn/ tests/
 
-- 
2.39.0