catocli 1.0.13__py3-none-any.whl → 1.0.15__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.

Potentially problematic release.


This version of catocli might be problematic. Click here for more details.

Files changed (253) hide show
  1. catocli/Utils/clidriver.py +15 -2
  2. catocli/__init__.py +1 -1
  3. catocli/parsers/custom/customLib.py +3 -1
  4. catocli/parsers/mutation_accountManagement/README.md +7 -0
  5. catocli/parsers/mutation_accountManagement/__init__.py +51 -0
  6. catocli/parsers/mutation_accountManagement_addAccount/README.md +17 -0
  7. catocli/parsers/mutation_accountManagement_removeAccount/README.md +16 -0
  8. catocli/parsers/mutation_accountManagement_updateAccount/README.md +17 -0
  9. catocli/parsers/mutation_admin_addAdmin/README.md +2 -2
  10. catocli/parsers/mutation_admin_updateAdmin/README.md +2 -2
  11. catocli/parsers/mutation_container_delete/README.md +2 -2
  12. catocli/parsers/mutation_policy_internetFirewall_addRule/README.md +3 -3
  13. catocli/parsers/mutation_policy_internetFirewall_addSection/README.md +3 -3
  14. catocli/parsers/mutation_policy_internetFirewall_createPolicyRevision/README.md +3 -3
  15. catocli/parsers/mutation_policy_internetFirewall_discardPolicyRevision/README.md +3 -3
  16. catocli/parsers/mutation_policy_internetFirewall_moveRule/README.md +3 -3
  17. catocli/parsers/mutation_policy_internetFirewall_moveSection/README.md +3 -3
  18. catocli/parsers/mutation_policy_internetFirewall_publishPolicyRevision/README.md +3 -3
  19. catocli/parsers/mutation_policy_internetFirewall_removeRule/README.md +3 -3
  20. catocli/parsers/mutation_policy_internetFirewall_removeSection/README.md +3 -3
  21. catocli/parsers/mutation_policy_internetFirewall_updatePolicy/README.md +3 -3
  22. catocli/parsers/mutation_policy_internetFirewall_updateRule/README.md +3 -3
  23. catocli/parsers/mutation_policy_internetFirewall_updateSection/README.md +3 -3
  24. catocli/parsers/mutation_policy_wanFirewall_addRule/README.md +3 -3
  25. catocli/parsers/mutation_policy_wanFirewall_addSection/README.md +3 -3
  26. catocli/parsers/mutation_policy_wanFirewall_createPolicyRevision/README.md +3 -3
  27. catocli/parsers/mutation_policy_wanFirewall_discardPolicyRevision/README.md +3 -3
  28. catocli/parsers/mutation_policy_wanFirewall_moveRule/README.md +3 -3
  29. catocli/parsers/mutation_policy_wanFirewall_moveSection/README.md +3 -3
  30. catocli/parsers/mutation_policy_wanFirewall_publishPolicyRevision/README.md +3 -3
  31. catocli/parsers/mutation_policy_wanFirewall_removeRule/README.md +3 -3
  32. catocli/parsers/mutation_policy_wanFirewall_removeSection/README.md +3 -3
  33. catocli/parsers/mutation_policy_wanFirewall_updatePolicy/README.md +3 -3
  34. catocli/parsers/mutation_policy_wanFirewall_updateRule/README.md +3 -3
  35. catocli/parsers/mutation_policy_wanFirewall_updateSection/README.md +3 -3
  36. catocli/parsers/mutation_site/__init__.py +14 -0
  37. catocli/parsers/mutation_site_addIpsecIkeV2Site/README.md +2 -2
  38. catocli/parsers/mutation_site_addIpsecIkeV2SiteTunnels/README.md +2 -2
  39. catocli/parsers/mutation_site_addNetworkRange/README.md +2 -2
  40. catocli/parsers/mutation_site_addSocketSite/README.md +2 -2
  41. catocli/parsers/mutation_site_addStaticHost/README.md +2 -2
  42. catocli/parsers/mutation_site_removeIpsecIkeV2SiteTunnels/README.md +18 -0
  43. catocli/parsers/mutation_site_updateHa/README.md +2 -2
  44. catocli/parsers/mutation_site_updateIpsecIkeV2SiteGeneralDetails/README.md +2 -2
  45. catocli/parsers/mutation_site_updateIpsecIkeV2SiteTunnels/README.md +2 -2
  46. catocli/parsers/mutation_site_updateNetworkRange/README.md +2 -2
  47. catocli/parsers/mutation_site_updateSiteGeneralDetails/README.md +2 -2
  48. catocli/parsers/mutation_site_updateSocketInterface/README.md +2 -2
  49. catocli/parsers/mutation_site_updateStaticHost/README.md +2 -2
  50. catocli/parsers/mutation_sites/__init__.py +14 -0
  51. catocli/parsers/mutation_sites_addIpsecIkeV2Site/README.md +2 -2
  52. catocli/parsers/mutation_sites_addIpsecIkeV2SiteTunnels/README.md +2 -2
  53. catocli/parsers/mutation_sites_addNetworkRange/README.md +2 -2
  54. catocli/parsers/mutation_sites_addSocketSite/README.md +2 -2
  55. catocli/parsers/mutation_sites_addStaticHost/README.md +2 -2
  56. catocli/parsers/mutation_sites_removeIpsecIkeV2SiteTunnels/README.md +18 -0
  57. catocli/parsers/mutation_sites_updateHa/README.md +2 -2
  58. catocli/parsers/mutation_sites_updateIpsecIkeV2SiteGeneralDetails/README.md +2 -2
  59. catocli/parsers/mutation_sites_updateIpsecIkeV2SiteTunnels/README.md +2 -2
  60. catocli/parsers/mutation_sites_updateNetworkRange/README.md +2 -2
  61. catocli/parsers/mutation_sites_updateSiteGeneralDetails/README.md +2 -2
  62. catocli/parsers/mutation_sites_updateSocketInterface/README.md +2 -2
  63. catocli/parsers/mutation_sites_updateStaticHost/README.md +2 -2
  64. catocli/parsers/parserApiClient.py +7 -4
  65. catocli/parsers/query_accountManagement/README.md +16 -0
  66. catocli/parsers/query_accountManagement/__init__.py +17 -0
  67. catocli/parsers/query_admins/README.md +2 -2
  68. catocli/parsers/query_appStats/README.md +5 -5
  69. catocli/parsers/query_appStatsTimeSeries/README.md +4 -4
  70. catocli/parsers/query_auditFeed/README.md +2 -2
  71. catocli/parsers/query_container/README.md +8 -8
  72. catocli/parsers/query_entityLookup/README.md +6 -6
  73. catocli/parsers/query_events/README.md +5 -5
  74. catocli/parsers/query_eventsFeed/README.md +2 -2
  75. catocli/parsers/query_eventsTimeSeries/README.md +4 -4
  76. catocli/parsers/query_hardwareManagement/README.md +2 -2
  77. catocli/parsers/query_policy/README.md +3 -3
  78. catocli/parsers/query_xdr_stories/README.md +2 -2
  79. {catocli-1.0.13.dist-info → catocli-1.0.15.dist-info}/METADATA +1 -1
  80. catocli-1.0.15.dist-info/RECORD +275 -0
  81. {catocli-1.0.13.dist-info → catocli-1.0.15.dist-info}/top_level.txt +0 -2
  82. graphql_client/api_client_types.py +4 -0
  83. models/mutation.accountManagement.addAccount.json +908 -0
  84. models/mutation.accountManagement.removeAccount.json +446 -0
  85. models/mutation.accountManagement.updateAccount.json +524 -0
  86. models/mutation.admin.addAdmin.json +103 -103
  87. models/mutation.admin.removeAdmin.json +3 -3
  88. models/mutation.admin.updateAdmin.json +121 -121
  89. models/mutation.container.delete.json +67 -67
  90. models/mutation.policy.internetFirewall.addRule.json +2497 -1889
  91. models/mutation.policy.internetFirewall.addSection.json +92 -92
  92. models/mutation.policy.internetFirewall.createPolicyRevision.json +734 -546
  93. models/mutation.policy.internetFirewall.discardPolicyRevision.json +734 -546
  94. models/mutation.policy.internetFirewall.moveRule.json +723 -535
  95. models/mutation.policy.internetFirewall.moveSection.json +85 -85
  96. models/mutation.policy.internetFirewall.publishPolicyRevision.json +734 -546
  97. models/mutation.policy.internetFirewall.removeRule.json +710 -522
  98. models/mutation.policy.internetFirewall.removeSection.json +72 -72
  99. models/mutation.policy.internetFirewall.updatePolicy.json +734 -546
  100. models/mutation.policy.internetFirewall.updateRule.json +2476 -1885
  101. models/mutation.policy.internetFirewall.updateSection.json +85 -85
  102. models/mutation.policy.wanFirewall.addRule.json +2577 -1225
  103. models/mutation.policy.wanFirewall.addSection.json +92 -92
  104. models/mutation.policy.wanFirewall.createPolicyRevision.json +800 -455
  105. models/mutation.policy.wanFirewall.discardPolicyRevision.json +800 -455
  106. models/mutation.policy.wanFirewall.moveRule.json +789 -444
  107. models/mutation.policy.wanFirewall.moveSection.json +85 -85
  108. models/mutation.policy.wanFirewall.publishPolicyRevision.json +800 -455
  109. models/mutation.policy.wanFirewall.removeRule.json +776 -431
  110. models/mutation.policy.wanFirewall.removeSection.json +72 -72
  111. models/mutation.policy.wanFirewall.updatePolicy.json +800 -455
  112. models/mutation.policy.wanFirewall.updateRule.json +2597 -1265
  113. models/mutation.policy.wanFirewall.updateSection.json +85 -85
  114. models/mutation.site.addIpsecIkeV2Site.json +43 -43
  115. models/mutation.site.addIpsecIkeV2SiteTunnels.json +505 -102
  116. models/mutation.site.addNetworkRange.json +53 -53
  117. models/mutation.site.addSocketSite.json +43 -43
  118. models/mutation.site.addStaticHost.json +33 -33
  119. models/mutation.site.removeIpsecIkeV2SiteTunnels.json +861 -0
  120. models/mutation.site.removeNetworkRange.json +3 -3
  121. models/mutation.site.removeSite.json +3 -3
  122. models/mutation.site.removeStaticHost.json +3 -3
  123. models/mutation.site.updateHa.json +54 -54
  124. models/mutation.site.updateIpsecIkeV2SiteGeneralDetails.json +79 -79
  125. models/mutation.site.updateIpsecIkeV2SiteTunnels.json +123 -123
  126. models/mutation.site.updateNetworkRange.json +74 -74
  127. models/mutation.site.updateSiteGeneralDetails.json +73 -73
  128. models/mutation.site.updateSocketInterface.json +282 -282
  129. models/mutation.site.updateStaticHost.json +54 -54
  130. models/mutation.sites.addIpsecIkeV2Site.json +43 -43
  131. models/mutation.sites.addIpsecIkeV2SiteTunnels.json +505 -102
  132. models/mutation.sites.addNetworkRange.json +53 -53
  133. models/mutation.sites.addSocketSite.json +43 -43
  134. models/mutation.sites.addStaticHost.json +33 -33
  135. models/mutation.sites.removeIpsecIkeV2SiteTunnels.json +861 -0
  136. models/mutation.sites.removeNetworkRange.json +3 -3
  137. models/mutation.sites.removeSite.json +3 -3
  138. models/mutation.sites.removeStaticHost.json +3 -3
  139. models/mutation.sites.updateHa.json +54 -54
  140. models/mutation.sites.updateIpsecIkeV2SiteGeneralDetails.json +79 -79
  141. models/mutation.sites.updateIpsecIkeV2SiteTunnels.json +123 -123
  142. models/mutation.sites.updateNetworkRange.json +74 -74
  143. models/mutation.sites.updateSiteGeneralDetails.json +73 -73
  144. models/mutation.sites.updateSocketInterface.json +282 -282
  145. models/mutation.sites.updateStaticHost.json +54 -54
  146. models/query.accountManagement.json +355 -0
  147. models/query.accountMetrics.json +235 -235
  148. models/query.accountRoles.json +3 -3
  149. models/query.accountSnapshot.json +278 -118
  150. models/query.admin.json +24 -24
  151. models/query.admins.json +138 -138
  152. models/query.appStats.json +92 -92
  153. models/query.appStatsTimeSeries.json +78 -78
  154. models/query.auditFeed.json +77 -77
  155. models/query.container.json +192 -192
  156. models/query.entityLookup.json +154 -154
  157. models/query.events.json +54 -54
  158. models/query.eventsFeed.json +38 -38
  159. models/query.eventsTimeSeries.json +78 -78
  160. models/query.hardwareManagement.json +125 -125
  161. models/query.licensing.json +933 -249
  162. models/query.policy.json +1502 -970
  163. models/query.xdr.stories.json +842 -842
  164. models/query.xdr.story.json +610 -610
  165. schema/catolib.py +12 -13
  166. build/lib/catocli/Utils/clidriver.py +0 -117
  167. build/lib/catocli/__init__.py +0 -2
  168. build/lib/catocli/__main__.py +0 -12
  169. build/lib/catocli/parsers/custom/__init__.py +0 -47
  170. build/lib/catocli/parsers/custom/customLib.py +0 -70
  171. build/lib/catocli/parsers/mutation_admin/__init__.py +0 -51
  172. build/lib/catocli/parsers/mutation_container/__init__.py +0 -23
  173. build/lib/catocli/parsers/mutation_policy/__init__.py +0 -357
  174. build/lib/catocli/parsers/mutation_site/__init__.py +0 -219
  175. build/lib/catocli/parsers/mutation_sites/__init__.py +0 -219
  176. build/lib/catocli/parsers/parserApiClient.py +0 -309
  177. build/lib/catocli/parsers/query_accountBySubdomain/__init__.py +0 -17
  178. build/lib/catocli/parsers/query_accountMetrics/__init__.py +0 -17
  179. build/lib/catocli/parsers/query_accountRoles/__init__.py +0 -17
  180. build/lib/catocli/parsers/query_accountSnapshot/__init__.py +0 -17
  181. build/lib/catocli/parsers/query_admin/__init__.py +0 -17
  182. build/lib/catocli/parsers/query_admins/__init__.py +0 -17
  183. build/lib/catocli/parsers/query_appStats/__init__.py +0 -17
  184. build/lib/catocli/parsers/query_appStatsTimeSeries/__init__.py +0 -17
  185. build/lib/catocli/parsers/query_auditFeed/__init__.py +0 -17
  186. build/lib/catocli/parsers/query_container/__init__.py +0 -17
  187. build/lib/catocli/parsers/query_entityLookup/__init__.py +0 -17
  188. build/lib/catocli/parsers/query_events/__init__.py +0 -17
  189. build/lib/catocli/parsers/query_eventsFeed/__init__.py +0 -17
  190. build/lib/catocli/parsers/query_eventsTimeSeries/__init__.py +0 -17
  191. build/lib/catocli/parsers/query_hardwareManagement/__init__.py +0 -17
  192. build/lib/catocli/parsers/query_licensing/__init__.py +0 -17
  193. build/lib/catocli/parsers/query_policy/__init__.py +0 -17
  194. build/lib/catocli/parsers/query_siteLocation/__init__.py +0 -17
  195. build/lib/catocli/parsers/query_subDomains/__init__.py +0 -17
  196. build/lib/catocli/parsers/query_xdr/__init__.py +0 -37
  197. build/lib/catocli/parsers/raw/__init__.py +0 -9
  198. build/lib/graphql_client/__init__.py +0 -11
  199. build/lib/graphql_client/api/__init__.py +0 -3
  200. build/lib/graphql_client/api/call_api.py +0 -73
  201. build/lib/graphql_client/api_client.py +0 -192
  202. build/lib/graphql_client/api_client_types.py +0 -404
  203. build/lib/graphql_client/configuration.py +0 -230
  204. build/lib/graphql_client/models/__init__.py +0 -13
  205. build/lib/graphql_client/models/no_schema.py +0 -71
  206. build/lib/schema/catolib.py +0 -1016
  207. build/lib/schema/importSchema.py +0 -60
  208. build/lib/vendor/certifi/__init__.py +0 -4
  209. build/lib/vendor/certifi/__main__.py +0 -12
  210. build/lib/vendor/certifi/core.py +0 -114
  211. build/lib/vendor/certifi/py.typed +0 -0
  212. build/lib/vendor/six.py +0 -998
  213. build/lib/vendor/urllib3/__init__.py +0 -211
  214. build/lib/vendor/urllib3/_base_connection.py +0 -172
  215. build/lib/vendor/urllib3/_collections.py +0 -483
  216. build/lib/vendor/urllib3/_request_methods.py +0 -278
  217. build/lib/vendor/urllib3/_version.py +0 -16
  218. build/lib/vendor/urllib3/connection.py +0 -1033
  219. build/lib/vendor/urllib3/connectionpool.py +0 -1182
  220. build/lib/vendor/urllib3/contrib/__init__.py +0 -0
  221. build/lib/vendor/urllib3/contrib/emscripten/__init__.py +0 -18
  222. build/lib/vendor/urllib3/contrib/emscripten/connection.py +0 -254
  223. build/lib/vendor/urllib3/contrib/emscripten/fetch.py +0 -418
  224. build/lib/vendor/urllib3/contrib/emscripten/request.py +0 -22
  225. build/lib/vendor/urllib3/contrib/emscripten/response.py +0 -285
  226. build/lib/vendor/urllib3/contrib/pyopenssl.py +0 -552
  227. build/lib/vendor/urllib3/contrib/socks.py +0 -228
  228. build/lib/vendor/urllib3/exceptions.py +0 -321
  229. build/lib/vendor/urllib3/fields.py +0 -341
  230. build/lib/vendor/urllib3/filepost.py +0 -89
  231. build/lib/vendor/urllib3/http2/__init__.py +0 -53
  232. build/lib/vendor/urllib3/http2/connection.py +0 -356
  233. build/lib/vendor/urllib3/http2/probe.py +0 -87
  234. build/lib/vendor/urllib3/poolmanager.py +0 -637
  235. build/lib/vendor/urllib3/py.typed +0 -2
  236. build/lib/vendor/urllib3/response.py +0 -1265
  237. build/lib/vendor/urllib3/util/__init__.py +0 -42
  238. build/lib/vendor/urllib3/util/connection.py +0 -137
  239. build/lib/vendor/urllib3/util/proxy.py +0 -43
  240. build/lib/vendor/urllib3/util/request.py +0 -256
  241. build/lib/vendor/urllib3/util/response.py +0 -101
  242. build/lib/vendor/urllib3/util/retry.py +0 -533
  243. build/lib/vendor/urllib3/util/ssl_.py +0 -513
  244. build/lib/vendor/urllib3/util/ssl_match_hostname.py +0 -159
  245. build/lib/vendor/urllib3/util/ssltransport.py +0 -276
  246. build/lib/vendor/urllib3/util/timeout.py +0 -275
  247. build/lib/vendor/urllib3/util/url.py +0 -471
  248. build/lib/vendor/urllib3/util/util.py +0 -42
  249. build/lib/vendor/urllib3/util/wait.py +0 -124
  250. catocli-1.0.13.dist-info/RECORD +0 -344
  251. {catocli-1.0.13.dist-info → catocli-1.0.15.dist-info}/LICENSE +0 -0
  252. {catocli-1.0.13.dist-info → catocli-1.0.15.dist-info}/WHEEL +0 -0
  253. {catocli-1.0.13.dist-info → catocli-1.0.15.dist-info}/entry_points.txt +0 -0
@@ -1,483 +0,0 @@
1
- from __future__ import annotations
2
-
3
- import typing
4
- from collections import OrderedDict
5
- from enum import Enum, auto
6
- from threading import RLock
7
-
8
- if typing.TYPE_CHECKING:
9
- # We can only import Protocol if TYPE_CHECKING because it's a development
10
- # dependency, and is not available at runtime.
11
- from typing import Protocol
12
-
13
- from typing_extensions import Self
14
-
15
- class HasGettableStringKeys(Protocol):
16
- def keys(self) -> typing.Iterator[str]:
17
- ...
18
-
19
- def __getitem__(self, key: str) -> str:
20
- ...
21
-
22
-
23
- __all__ = ["RecentlyUsedContainer", "HTTPHeaderDict"]
24
-
25
-
26
- # Key type
27
- _KT = typing.TypeVar("_KT")
28
- # Value type
29
- _VT = typing.TypeVar("_VT")
30
- # Default type
31
- _DT = typing.TypeVar("_DT")
32
-
33
- ValidHTTPHeaderSource = typing.Union[
34
- "HTTPHeaderDict",
35
- typing.Mapping[str, str],
36
- typing.Iterable[typing.Tuple[str, str]],
37
- "HasGettableStringKeys",
38
- ]
39
-
40
-
41
- class _Sentinel(Enum):
42
- not_passed = auto()
43
-
44
-
45
- def ensure_can_construct_http_header_dict(
46
- potential: object,
47
- ) -> ValidHTTPHeaderSource | None:
48
- if isinstance(potential, HTTPHeaderDict):
49
- return potential
50
- elif isinstance(potential, typing.Mapping):
51
- # Full runtime checking of the contents of a Mapping is expensive, so for the
52
- # purposes of typechecking, we assume that any Mapping is the right shape.
53
- return typing.cast(typing.Mapping[str, str], potential)
54
- elif isinstance(potential, typing.Iterable):
55
- # Similarly to Mapping, full runtime checking of the contents of an Iterable is
56
- # expensive, so for the purposes of typechecking, we assume that any Iterable
57
- # is the right shape.
58
- return typing.cast(typing.Iterable[typing.Tuple[str, str]], potential)
59
- elif hasattr(potential, "keys") and hasattr(potential, "__getitem__"):
60
- return typing.cast("HasGettableStringKeys", potential)
61
- else:
62
- return None
63
-
64
-
65
- class RecentlyUsedContainer(typing.Generic[_KT, _VT], typing.MutableMapping[_KT, _VT]):
66
- """
67
- Provides a thread-safe dict-like container which maintains up to
68
- ``maxsize`` keys while throwing away the least-recently-used keys beyond
69
- ``maxsize``.
70
-
71
- :param maxsize:
72
- Maximum number of recent elements to retain.
73
-
74
- :param dispose_func:
75
- Every time an item is evicted from the container,
76
- ``dispose_func(value)`` is called. Callback which will get called
77
- """
78
-
79
- _container: typing.OrderedDict[_KT, _VT]
80
- _maxsize: int
81
- dispose_func: typing.Callable[[_VT], None] | None
82
- lock: RLock
83
-
84
- def __init__(
85
- self,
86
- maxsize: int = 10,
87
- dispose_func: typing.Callable[[_VT], None] | None = None,
88
- ) -> None:
89
- super().__init__()
90
- self._maxsize = maxsize
91
- self.dispose_func = dispose_func
92
- self._container = OrderedDict()
93
- self.lock = RLock()
94
-
95
- def __getitem__(self, key: _KT) -> _VT:
96
- # Re-insert the item, moving it to the end of the eviction line.
97
- with self.lock:
98
- item = self._container.pop(key)
99
- self._container[key] = item
100
- return item
101
-
102
- def __setitem__(self, key: _KT, value: _VT) -> None:
103
- evicted_item = None
104
- with self.lock:
105
- # Possibly evict the existing value of 'key'
106
- try:
107
- # If the key exists, we'll overwrite it, which won't change the
108
- # size of the pool. Because accessing a key should move it to
109
- # the end of the eviction line, we pop it out first.
110
- evicted_item = key, self._container.pop(key)
111
- self._container[key] = value
112
- except KeyError:
113
- # When the key does not exist, we insert the value first so that
114
- # evicting works in all cases, including when self._maxsize is 0
115
- self._container[key] = value
116
- if len(self._container) > self._maxsize:
117
- # If we didn't evict an existing value, and we've hit our maximum
118
- # size, then we have to evict the least recently used item from
119
- # the beginning of the container.
120
- evicted_item = self._container.popitem(last=False)
121
-
122
- # After releasing the lock on the pool, dispose of any evicted value.
123
- if evicted_item is not None and self.dispose_func:
124
- _, evicted_value = evicted_item
125
- self.dispose_func(evicted_value)
126
-
127
- def __delitem__(self, key: _KT) -> None:
128
- with self.lock:
129
- value = self._container.pop(key)
130
-
131
- if self.dispose_func:
132
- self.dispose_func(value)
133
-
134
- def __len__(self) -> int:
135
- with self.lock:
136
- return len(self._container)
137
-
138
- def __iter__(self) -> typing.NoReturn:
139
- raise NotImplementedError(
140
- "Iteration over this class is unlikely to be threadsafe."
141
- )
142
-
143
- def clear(self) -> None:
144
- with self.lock:
145
- # Copy pointers to all values, then wipe the mapping
146
- values = list(self._container.values())
147
- self._container.clear()
148
-
149
- if self.dispose_func:
150
- for value in values:
151
- self.dispose_func(value)
152
-
153
- def keys(self) -> set[_KT]: # type: ignore[override]
154
- with self.lock:
155
- return set(self._container.keys())
156
-
157
-
158
- class HTTPHeaderDictItemView(typing.Set[typing.Tuple[str, str]]):
159
- """
160
- HTTPHeaderDict is unusual for a Mapping[str, str] in that it has two modes of
161
- address.
162
-
163
- If we directly try to get an item with a particular name, we will get a string
164
- back that is the concatenated version of all the values:
165
-
166
- >>> d['X-Header-Name']
167
- 'Value1, Value2, Value3'
168
-
169
- However, if we iterate over an HTTPHeaderDict's items, we will optionally combine
170
- these values based on whether combine=True was called when building up the dictionary
171
-
172
- >>> d = HTTPHeaderDict({"A": "1", "B": "foo"})
173
- >>> d.add("A", "2", combine=True)
174
- >>> d.add("B", "bar")
175
- >>> list(d.items())
176
- [
177
- ('A', '1, 2'),
178
- ('B', 'foo'),
179
- ('B', 'bar'),
180
- ]
181
-
182
- This class conforms to the interface required by the MutableMapping ABC while
183
- also giving us the nonstandard iteration behavior we want; items with duplicate
184
- keys, ordered by time of first insertion.
185
- """
186
-
187
- _headers: HTTPHeaderDict
188
-
189
- def __init__(self, headers: HTTPHeaderDict) -> None:
190
- self._headers = headers
191
-
192
- def __len__(self) -> int:
193
- return len(list(self._headers.iteritems()))
194
-
195
- def __iter__(self) -> typing.Iterator[tuple[str, str]]:
196
- return self._headers.iteritems()
197
-
198
- def __contains__(self, item: object) -> bool:
199
- if isinstance(item, tuple) and len(item) == 2:
200
- passed_key, passed_val = item
201
- if isinstance(passed_key, str) and isinstance(passed_val, str):
202
- return self._headers._has_value_for_header(passed_key, passed_val)
203
- return False
204
-
205
-
206
- class HTTPHeaderDict(typing.MutableMapping[str, str]):
207
- """
208
- :param headers:
209
- An iterable of field-value pairs. Must not contain multiple field names
210
- when compared case-insensitively.
211
-
212
- :param kwargs:
213
- Additional field-value pairs to pass in to ``dict.update``.
214
-
215
- A ``dict`` like container for storing HTTP Headers.
216
-
217
- Field names are stored and compared case-insensitively in compliance with
218
- RFC 7230. Iteration provides the first case-sensitive key seen for each
219
- case-insensitive pair.
220
-
221
- Using ``__setitem__`` syntax overwrites fields that compare equal
222
- case-insensitively in order to maintain ``dict``'s api. For fields that
223
- compare equal, instead create a new ``HTTPHeaderDict`` and use ``.add``
224
- in a loop.
225
-
226
- If multiple fields that are equal case-insensitively are passed to the
227
- constructor or ``.update``, the behavior is undefined and some will be
228
- lost.
229
-
230
- >>> headers = HTTPHeaderDict()
231
- >>> headers.add('Set-Cookie', 'foo=bar')
232
- >>> headers.add('set-cookie', 'baz=quxx')
233
- >>> headers['content-length'] = '7'
234
- >>> headers['SET-cookie']
235
- 'foo=bar, baz=quxx'
236
- >>> headers['Content-Length']
237
- '7'
238
- """
239
-
240
- _container: typing.MutableMapping[str, list[str]]
241
-
242
- def __init__(self, headers: ValidHTTPHeaderSource | None = None, **kwargs: str):
243
- super().__init__()
244
- self._container = {} # 'dict' is insert-ordered
245
- if headers is not None:
246
- if isinstance(headers, HTTPHeaderDict):
247
- self._copy_from(headers)
248
- else:
249
- self.extend(headers)
250
- if kwargs:
251
- self.extend(kwargs)
252
-
253
- def __setitem__(self, key: str, val: str) -> None:
254
- # avoid a bytes/str comparison by decoding before httplib
255
- if isinstance(key, bytes):
256
- key = key.decode("latin-1")
257
- self._container[key.lower()] = [key, val]
258
-
259
- def __getitem__(self, key: str) -> str:
260
- val = self._container[key.lower()]
261
- return ", ".join(val[1:])
262
-
263
- def __delitem__(self, key: str) -> None:
264
- del self._container[key.lower()]
265
-
266
- def __contains__(self, key: object) -> bool:
267
- if isinstance(key, str):
268
- return key.lower() in self._container
269
- return False
270
-
271
- def setdefault(self, key: str, default: str = "") -> str:
272
- return super().setdefault(key, default)
273
-
274
- def __eq__(self, other: object) -> bool:
275
- maybe_constructable = ensure_can_construct_http_header_dict(other)
276
- if maybe_constructable is None:
277
- return False
278
- else:
279
- other_as_http_header_dict = type(self)(maybe_constructable)
280
-
281
- return {k.lower(): v for k, v in self.itermerged()} == {
282
- k.lower(): v for k, v in other_as_http_header_dict.itermerged()
283
- }
284
-
285
- def __ne__(self, other: object) -> bool:
286
- return not self.__eq__(other)
287
-
288
- def __len__(self) -> int:
289
- return len(self._container)
290
-
291
- def __iter__(self) -> typing.Iterator[str]:
292
- # Only provide the originally cased names
293
- for vals in self._container.values():
294
- yield vals[0]
295
-
296
- def discard(self, key: str) -> None:
297
- try:
298
- del self[key]
299
- except KeyError:
300
- pass
301
-
302
- def add(self, key: str, val: str, *, combine: bool = False) -> None:
303
- """Adds a (name, value) pair, doesn't overwrite the value if it already
304
- exists.
305
-
306
- If this is called with combine=True, instead of adding a new header value
307
- as a distinct item during iteration, this will instead append the value to
308
- any existing header value with a comma. If no existing header value exists
309
- for the key, then the value will simply be added, ignoring the combine parameter.
310
-
311
- >>> headers = HTTPHeaderDict(foo='bar')
312
- >>> headers.add('Foo', 'baz')
313
- >>> headers['foo']
314
- 'bar, baz'
315
- >>> list(headers.items())
316
- [('foo', 'bar'), ('foo', 'baz')]
317
- >>> headers.add('foo', 'quz', combine=True)
318
- >>> list(headers.items())
319
- [('foo', 'bar, baz, quz')]
320
- """
321
- # avoid a bytes/str comparison by decoding before httplib
322
- if isinstance(key, bytes):
323
- key = key.decode("latin-1")
324
- key_lower = key.lower()
325
- new_vals = [key, val]
326
- # Keep the common case aka no item present as fast as possible
327
- vals = self._container.setdefault(key_lower, new_vals)
328
- if new_vals is not vals:
329
- # if there are values here, then there is at least the initial
330
- # key/value pair
331
- assert len(vals) >= 2
332
- if combine:
333
- vals[-1] = vals[-1] + ", " + val
334
- else:
335
- vals.append(val)
336
-
337
- def extend(self, *args: ValidHTTPHeaderSource, **kwargs: str) -> None:
338
- """Generic import function for any type of header-like object.
339
- Adapted version of MutableMapping.update in order to insert items
340
- with self.add instead of self.__setitem__
341
- """
342
- if len(args) > 1:
343
- raise TypeError(
344
- f"extend() takes at most 1 positional arguments ({len(args)} given)"
345
- )
346
- other = args[0] if len(args) >= 1 else ()
347
-
348
- if isinstance(other, HTTPHeaderDict):
349
- for key, val in other.iteritems():
350
- self.add(key, val)
351
- elif isinstance(other, typing.Mapping):
352
- for key, val in other.items():
353
- self.add(key, val)
354
- elif isinstance(other, typing.Iterable):
355
- other = typing.cast(typing.Iterable[typing.Tuple[str, str]], other)
356
- for key, value in other:
357
- self.add(key, value)
358
- elif hasattr(other, "keys") and hasattr(other, "__getitem__"):
359
- # THIS IS NOT A TYPESAFE BRANCH
360
- # In this branch, the object has a `keys` attr but is not a Mapping or any of
361
- # the other types indicated in the method signature. We do some stuff with
362
- # it as though it partially implements the Mapping interface, but we're not
363
- # doing that stuff safely AT ALL.
364
- for key in other.keys():
365
- self.add(key, other[key])
366
-
367
- for key, value in kwargs.items():
368
- self.add(key, value)
369
-
370
- @typing.overload
371
- def getlist(self, key: str) -> list[str]:
372
- ...
373
-
374
- @typing.overload
375
- def getlist(self, key: str, default: _DT) -> list[str] | _DT:
376
- ...
377
-
378
- def getlist(
379
- self, key: str, default: _Sentinel | _DT = _Sentinel.not_passed
380
- ) -> list[str] | _DT:
381
- """Returns a list of all the values for the named field. Returns an
382
- empty list if the key doesn't exist."""
383
- try:
384
- vals = self._container[key.lower()]
385
- except KeyError:
386
- if default is _Sentinel.not_passed:
387
- # _DT is unbound; empty list is instance of List[str]
388
- return []
389
- # _DT is bound; default is instance of _DT
390
- return default
391
- else:
392
- # _DT may or may not be bound; vals[1:] is instance of List[str], which
393
- # meets our external interface requirement of `Union[List[str], _DT]`.
394
- return vals[1:]
395
-
396
- def _prepare_for_method_change(self) -> Self:
397
- """
398
- Remove content-specific header fields before changing the request
399
- method to GET or HEAD according to RFC 9110, Section 15.4.
400
- """
401
- content_specific_headers = [
402
- "Content-Encoding",
403
- "Content-Language",
404
- "Content-Location",
405
- "Content-Type",
406
- "Content-Length",
407
- "Digest",
408
- "Last-Modified",
409
- ]
410
- for header in content_specific_headers:
411
- self.discard(header)
412
- return self
413
-
414
- # Backwards compatibility for httplib
415
- getheaders = getlist
416
- getallmatchingheaders = getlist
417
- iget = getlist
418
-
419
- # Backwards compatibility for http.cookiejar
420
- get_all = getlist
421
-
422
- def __repr__(self) -> str:
423
- return f"{type(self).__name__}({dict(self.itermerged())})"
424
-
425
- def _copy_from(self, other: HTTPHeaderDict) -> None:
426
- for key in other:
427
- val = other.getlist(key)
428
- self._container[key.lower()] = [key, *val]
429
-
430
- def copy(self) -> Self:
431
- clone = type(self)()
432
- clone._copy_from(self)
433
- return clone
434
-
435
- def iteritems(self) -> typing.Iterator[tuple[str, str]]:
436
- """Iterate over all header lines, including duplicate ones."""
437
- for key in self:
438
- vals = self._container[key.lower()]
439
- for val in vals[1:]:
440
- yield vals[0], val
441
-
442
- def itermerged(self) -> typing.Iterator[tuple[str, str]]:
443
- """Iterate over all headers, merging duplicate ones together."""
444
- for key in self:
445
- val = self._container[key.lower()]
446
- yield val[0], ", ".join(val[1:])
447
-
448
- def items(self) -> HTTPHeaderDictItemView: # type: ignore[override]
449
- return HTTPHeaderDictItemView(self)
450
-
451
- def _has_value_for_header(self, header_name: str, potential_value: str) -> bool:
452
- if header_name in self:
453
- return potential_value in self._container[header_name.lower()][1:]
454
- return False
455
-
456
- def __ior__(self, other: object) -> HTTPHeaderDict:
457
- # Supports extending a header dict in-place using operator |=
458
- # combining items with add instead of __setitem__
459
- maybe_constructable = ensure_can_construct_http_header_dict(other)
460
- if maybe_constructable is None:
461
- return NotImplemented
462
- self.extend(maybe_constructable)
463
- return self
464
-
465
- def __or__(self, other: object) -> Self:
466
- # Supports merging header dicts using operator |
467
- # combining items with add instead of __setitem__
468
- maybe_constructable = ensure_can_construct_http_header_dict(other)
469
- if maybe_constructable is None:
470
- return NotImplemented
471
- result = self.copy()
472
- result.extend(maybe_constructable)
473
- return result
474
-
475
- def __ror__(self, other: object) -> Self:
476
- # Supports merging header dicts using operator | when other is on left side
477
- # combining items with add instead of __setitem__
478
- maybe_constructable = ensure_can_construct_http_header_dict(other)
479
- if maybe_constructable is None:
480
- return NotImplemented
481
- result = type(self)(maybe_constructable)
482
- result.extend(self)
483
- return result