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,276 +0,0 @@
1
- from __future__ import annotations
2
-
3
- import io
4
- import socket
5
- import ssl
6
- import typing
7
-
8
- from ..exceptions import ProxySchemeUnsupported
9
-
10
- if typing.TYPE_CHECKING:
11
- from typing_extensions import Self
12
-
13
- from .ssl_ import _TYPE_PEER_CERT_RET, _TYPE_PEER_CERT_RET_DICT
14
-
15
-
16
- _WriteBuffer = typing.Union[bytearray, memoryview]
17
- _ReturnValue = typing.TypeVar("_ReturnValue")
18
-
19
- SSL_BLOCKSIZE = 16384
20
-
21
-
22
- class SSLTransport:
23
- """
24
- The SSLTransport wraps an existing socket and establishes an SSL connection.
25
-
26
- Contrary to Python's implementation of SSLSocket, it allows you to chain
27
- multiple TLS connections together. It's particularly useful if you need to
28
- implement TLS within TLS.
29
-
30
- The class supports most of the socket API operations.
31
- """
32
-
33
- @staticmethod
34
- def _validate_ssl_context_for_tls_in_tls(ssl_context: ssl.SSLContext) -> None:
35
- """
36
- Raises a ProxySchemeUnsupported if the provided ssl_context can't be used
37
- for TLS in TLS.
38
-
39
- The only requirement is that the ssl_context provides the 'wrap_bio'
40
- methods.
41
- """
42
-
43
- if not hasattr(ssl_context, "wrap_bio"):
44
- raise ProxySchemeUnsupported(
45
- "TLS in TLS requires SSLContext.wrap_bio() which isn't "
46
- "available on non-native SSLContext"
47
- )
48
-
49
- def __init__(
50
- self,
51
- socket: socket.socket,
52
- ssl_context: ssl.SSLContext,
53
- server_hostname: str | None = None,
54
- suppress_ragged_eofs: bool = True,
55
- ) -> None:
56
- """
57
- Create an SSLTransport around socket using the provided ssl_context.
58
- """
59
- self.incoming = ssl.MemoryBIO()
60
- self.outgoing = ssl.MemoryBIO()
61
-
62
- self.suppress_ragged_eofs = suppress_ragged_eofs
63
- self.socket = socket
64
-
65
- self.sslobj = ssl_context.wrap_bio(
66
- self.incoming, self.outgoing, server_hostname=server_hostname
67
- )
68
-
69
- # Perform initial handshake.
70
- self._ssl_io_loop(self.sslobj.do_handshake)
71
-
72
- def __enter__(self) -> Self:
73
- return self
74
-
75
- def __exit__(self, *_: typing.Any) -> None:
76
- self.close()
77
-
78
- def fileno(self) -> int:
79
- return self.socket.fileno()
80
-
81
- def read(self, len: int = 1024, buffer: typing.Any | None = None) -> int | bytes:
82
- return self._wrap_ssl_read(len, buffer)
83
-
84
- def recv(self, buflen: int = 1024, flags: int = 0) -> int | bytes:
85
- if flags != 0:
86
- raise ValueError("non-zero flags not allowed in calls to recv")
87
- return self._wrap_ssl_read(buflen)
88
-
89
- def recv_into(
90
- self,
91
- buffer: _WriteBuffer,
92
- nbytes: int | None = None,
93
- flags: int = 0,
94
- ) -> None | int | bytes:
95
- if flags != 0:
96
- raise ValueError("non-zero flags not allowed in calls to recv_into")
97
- if nbytes is None:
98
- nbytes = len(buffer)
99
- return self.read(nbytes, buffer)
100
-
101
- def sendall(self, data: bytes, flags: int = 0) -> None:
102
- if flags != 0:
103
- raise ValueError("non-zero flags not allowed in calls to sendall")
104
- count = 0
105
- with memoryview(data) as view, view.cast("B") as byte_view:
106
- amount = len(byte_view)
107
- while count < amount:
108
- v = self.send(byte_view[count:])
109
- count += v
110
-
111
- def send(self, data: bytes, flags: int = 0) -> int:
112
- if flags != 0:
113
- raise ValueError("non-zero flags not allowed in calls to send")
114
- return self._ssl_io_loop(self.sslobj.write, data)
115
-
116
- def makefile(
117
- self,
118
- mode: str,
119
- buffering: int | None = None,
120
- *,
121
- encoding: str | None = None,
122
- errors: str | None = None,
123
- newline: str | None = None,
124
- ) -> typing.BinaryIO | typing.TextIO | socket.SocketIO:
125
- """
126
- Python's httpclient uses makefile and buffered io when reading HTTP
127
- messages and we need to support it.
128
-
129
- This is unfortunately a copy and paste of socket.py makefile with small
130
- changes to point to the socket directly.
131
- """
132
- if not set(mode) <= {"r", "w", "b"}:
133
- raise ValueError(f"invalid mode {mode!r} (only r, w, b allowed)")
134
-
135
- writing = "w" in mode
136
- reading = "r" in mode or not writing
137
- assert reading or writing
138
- binary = "b" in mode
139
- rawmode = ""
140
- if reading:
141
- rawmode += "r"
142
- if writing:
143
- rawmode += "w"
144
- raw = socket.SocketIO(self, rawmode) # type: ignore[arg-type]
145
- self.socket._io_refs += 1 # type: ignore[attr-defined]
146
- if buffering is None:
147
- buffering = -1
148
- if buffering < 0:
149
- buffering = io.DEFAULT_BUFFER_SIZE
150
- if buffering == 0:
151
- if not binary:
152
- raise ValueError("unbuffered streams must be binary")
153
- return raw
154
- buffer: typing.BinaryIO
155
- if reading and writing:
156
- buffer = io.BufferedRWPair(raw, raw, buffering) # type: ignore[assignment]
157
- elif reading:
158
- buffer = io.BufferedReader(raw, buffering)
159
- else:
160
- assert writing
161
- buffer = io.BufferedWriter(raw, buffering)
162
- if binary:
163
- return buffer
164
- text = io.TextIOWrapper(buffer, encoding, errors, newline)
165
- text.mode = mode # type: ignore[misc]
166
- return text
167
-
168
- def unwrap(self) -> None:
169
- self._ssl_io_loop(self.sslobj.unwrap)
170
-
171
- def close(self) -> None:
172
- self.socket.close()
173
-
174
- @typing.overload
175
- def getpeercert(
176
- self, binary_form: typing.Literal[False] = ...
177
- ) -> _TYPE_PEER_CERT_RET_DICT | None:
178
- ...
179
-
180
- @typing.overload
181
- def getpeercert(self, binary_form: typing.Literal[True]) -> bytes | None:
182
- ...
183
-
184
- def getpeercert(self, binary_form: bool = False) -> _TYPE_PEER_CERT_RET:
185
- return self.sslobj.getpeercert(binary_form) # type: ignore[return-value]
186
-
187
- def version(self) -> str | None:
188
- return self.sslobj.version()
189
-
190
- def cipher(self) -> tuple[str, str, int] | None:
191
- return self.sslobj.cipher()
192
-
193
- def selected_alpn_protocol(self) -> str | None:
194
- return self.sslobj.selected_alpn_protocol()
195
-
196
- def shared_ciphers(self) -> list[tuple[str, str, int]] | None:
197
- return self.sslobj.shared_ciphers()
198
-
199
- def compression(self) -> str | None:
200
- return self.sslobj.compression()
201
-
202
- def settimeout(self, value: float | None) -> None:
203
- self.socket.settimeout(value)
204
-
205
- def gettimeout(self) -> float | None:
206
- return self.socket.gettimeout()
207
-
208
- def _decref_socketios(self) -> None:
209
- self.socket._decref_socketios() # type: ignore[attr-defined]
210
-
211
- def _wrap_ssl_read(self, len: int, buffer: bytearray | None = None) -> int | bytes:
212
- try:
213
- return self._ssl_io_loop(self.sslobj.read, len, buffer)
214
- except ssl.SSLError as e:
215
- if e.errno == ssl.SSL_ERROR_EOF and self.suppress_ragged_eofs:
216
- return 0 # eof, return 0.
217
- else:
218
- raise
219
-
220
- # func is sslobj.do_handshake or sslobj.unwrap
221
- @typing.overload
222
- def _ssl_io_loop(self, func: typing.Callable[[], None]) -> None:
223
- ...
224
-
225
- # func is sslobj.write, arg1 is data
226
- @typing.overload
227
- def _ssl_io_loop(self, func: typing.Callable[[bytes], int], arg1: bytes) -> int:
228
- ...
229
-
230
- # func is sslobj.read, arg1 is len, arg2 is buffer
231
- @typing.overload
232
- def _ssl_io_loop(
233
- self,
234
- func: typing.Callable[[int, bytearray | None], bytes],
235
- arg1: int,
236
- arg2: bytearray | None,
237
- ) -> bytes:
238
- ...
239
-
240
- def _ssl_io_loop(
241
- self,
242
- func: typing.Callable[..., _ReturnValue],
243
- arg1: None | bytes | int = None,
244
- arg2: bytearray | None = None,
245
- ) -> _ReturnValue:
246
- """Performs an I/O loop between incoming/outgoing and the socket."""
247
- should_loop = True
248
- ret = None
249
-
250
- while should_loop:
251
- errno = None
252
- try:
253
- if arg1 is None and arg2 is None:
254
- ret = func()
255
- elif arg2 is None:
256
- ret = func(arg1)
257
- else:
258
- ret = func(arg1, arg2)
259
- except ssl.SSLError as e:
260
- if e.errno not in (ssl.SSL_ERROR_WANT_READ, ssl.SSL_ERROR_WANT_WRITE):
261
- # WANT_READ, and WANT_WRITE are expected, others are not.
262
- raise e
263
- errno = e.errno
264
-
265
- buf = self.outgoing.read()
266
- self.socket.sendall(buf)
267
-
268
- if errno is None:
269
- should_loop = False
270
- elif errno == ssl.SSL_ERROR_WANT_READ:
271
- buf = self.socket.recv(SSL_BLOCKSIZE)
272
- if buf:
273
- self.incoming.write(buf)
274
- else:
275
- self.incoming.write_eof()
276
- return typing.cast(_ReturnValue, ret)
@@ -1,275 +0,0 @@
1
- from __future__ import annotations
2
-
3
- import time
4
- import typing
5
- from enum import Enum
6
- from socket import getdefaulttimeout
7
-
8
- from ..exceptions import TimeoutStateError
9
-
10
- if typing.TYPE_CHECKING:
11
- from typing import Final
12
-
13
-
14
- class _TYPE_DEFAULT(Enum):
15
- # This value should never be passed to socket.settimeout() so for safety we use a -1.
16
- # socket.settimout() raises a ValueError for negative values.
17
- token = -1
18
-
19
-
20
- _DEFAULT_TIMEOUT: Final[_TYPE_DEFAULT] = _TYPE_DEFAULT.token
21
-
22
- _TYPE_TIMEOUT = typing.Optional[typing.Union[float, _TYPE_DEFAULT]]
23
-
24
-
25
- class Timeout:
26
- """Timeout configuration.
27
-
28
- Timeouts can be defined as a default for a pool:
29
-
30
- .. code-block:: python
31
-
32
- import urllib3
33
-
34
- timeout = urllib3.util.Timeout(connect=2.0, read=7.0)
35
-
36
- http = urllib3.PoolManager(timeout=timeout)
37
-
38
- resp = http.request("GET", "https://example.com/")
39
-
40
- print(resp.status)
41
-
42
- Or per-request (which overrides the default for the pool):
43
-
44
- .. code-block:: python
45
-
46
- response = http.request("GET", "https://example.com/", timeout=Timeout(10))
47
-
48
- Timeouts can be disabled by setting all the parameters to ``None``:
49
-
50
- .. code-block:: python
51
-
52
- no_timeout = Timeout(connect=None, read=None)
53
- response = http.request("GET", "https://example.com/", timeout=no_timeout)
54
-
55
-
56
- :param total:
57
- This combines the connect and read timeouts into one; the read timeout
58
- will be set to the time leftover from the connect attempt. In the
59
- event that both a connect timeout and a total are specified, or a read
60
- timeout and a total are specified, the shorter timeout will be applied.
61
-
62
- Defaults to None.
63
-
64
- :type total: int, float, or None
65
-
66
- :param connect:
67
- The maximum amount of time (in seconds) to wait for a connection
68
- attempt to a server to succeed. Omitting the parameter will default the
69
- connect timeout to the system default, probably `the global default
70
- timeout in socket.py
71
- <http://hg.python.org/cpython/file/603b4d593758/Lib/socket.py#l535>`_.
72
- None will set an infinite timeout for connection attempts.
73
-
74
- :type connect: int, float, or None
75
-
76
- :param read:
77
- The maximum amount of time (in seconds) to wait between consecutive
78
- read operations for a response from the server. Omitting the parameter
79
- will default the read timeout to the system default, probably `the
80
- global default timeout in socket.py
81
- <http://hg.python.org/cpython/file/603b4d593758/Lib/socket.py#l535>`_.
82
- None will set an infinite timeout.
83
-
84
- :type read: int, float, or None
85
-
86
- .. note::
87
-
88
- Many factors can affect the total amount of time for urllib3 to return
89
- an HTTP response.
90
-
91
- For example, Python's DNS resolver does not obey the timeout specified
92
- on the socket. Other factors that can affect total request time include
93
- high CPU load, high swap, the program running at a low priority level,
94
- or other behaviors.
95
-
96
- In addition, the read and total timeouts only measure the time between
97
- read operations on the socket connecting the client and the server,
98
- not the total amount of time for the request to return a complete
99
- response. For most requests, the timeout is raised because the server
100
- has not sent the first byte in the specified time. This is not always
101
- the case; if a server streams one byte every fifteen seconds, a timeout
102
- of 20 seconds will not trigger, even though the request will take
103
- several minutes to complete.
104
- """
105
-
106
- #: A sentinel object representing the default timeout value
107
- DEFAULT_TIMEOUT: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT
108
-
109
- def __init__(
110
- self,
111
- total: _TYPE_TIMEOUT = None,
112
- connect: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT,
113
- read: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT,
114
- ) -> None:
115
- self._connect = self._validate_timeout(connect, "connect")
116
- self._read = self._validate_timeout(read, "read")
117
- self.total = self._validate_timeout(total, "total")
118
- self._start_connect: float | None = None
119
-
120
- def __repr__(self) -> str:
121
- return f"{type(self).__name__}(connect={self._connect!r}, read={self._read!r}, total={self.total!r})"
122
-
123
- # __str__ provided for backwards compatibility
124
- __str__ = __repr__
125
-
126
- @staticmethod
127
- def resolve_default_timeout(timeout: _TYPE_TIMEOUT) -> float | None:
128
- return getdefaulttimeout() if timeout is _DEFAULT_TIMEOUT else timeout
129
-
130
- @classmethod
131
- def _validate_timeout(cls, value: _TYPE_TIMEOUT, name: str) -> _TYPE_TIMEOUT:
132
- """Check that a timeout attribute is valid.
133
-
134
- :param value: The timeout value to validate
135
- :param name: The name of the timeout attribute to validate. This is
136
- used to specify in error messages.
137
- :return: The validated and casted version of the given value.
138
- :raises ValueError: If it is a numeric value less than or equal to
139
- zero, or the type is not an integer, float, or None.
140
- """
141
- if value is None or value is _DEFAULT_TIMEOUT:
142
- return value
143
-
144
- if isinstance(value, bool):
145
- raise ValueError(
146
- "Timeout cannot be a boolean value. It must "
147
- "be an int, float or None."
148
- )
149
- try:
150
- float(value)
151
- except (TypeError, ValueError):
152
- raise ValueError(
153
- "Timeout value %s was %s, but it must be an "
154
- "int, float or None." % (name, value)
155
- ) from None
156
-
157
- try:
158
- if value <= 0:
159
- raise ValueError(
160
- "Attempted to set %s timeout to %s, but the "
161
- "timeout cannot be set to a value less "
162
- "than or equal to 0." % (name, value)
163
- )
164
- except TypeError:
165
- raise ValueError(
166
- "Timeout value %s was %s, but it must be an "
167
- "int, float or None." % (name, value)
168
- ) from None
169
-
170
- return value
171
-
172
- @classmethod
173
- def from_float(cls, timeout: _TYPE_TIMEOUT) -> Timeout:
174
- """Create a new Timeout from a legacy timeout value.
175
-
176
- The timeout value used by httplib.py sets the same timeout on the
177
- connect(), and recv() socket requests. This creates a :class:`Timeout`
178
- object that sets the individual timeouts to the ``timeout`` value
179
- passed to this function.
180
-
181
- :param timeout: The legacy timeout value.
182
- :type timeout: integer, float, :attr:`urllib3.util.Timeout.DEFAULT_TIMEOUT`, or None
183
- :return: Timeout object
184
- :rtype: :class:`Timeout`
185
- """
186
- return Timeout(read=timeout, connect=timeout)
187
-
188
- def clone(self) -> Timeout:
189
- """Create a copy of the timeout object
190
-
191
- Timeout properties are stored per-pool but each request needs a fresh
192
- Timeout object to ensure each one has its own start/stop configured.
193
-
194
- :return: a copy of the timeout object
195
- :rtype: :class:`Timeout`
196
- """
197
- # We can't use copy.deepcopy because that will also create a new object
198
- # for _GLOBAL_DEFAULT_TIMEOUT, which socket.py uses as a sentinel to
199
- # detect the user default.
200
- return Timeout(connect=self._connect, read=self._read, total=self.total)
201
-
202
- def start_connect(self) -> float:
203
- """Start the timeout clock, used during a connect() attempt
204
-
205
- :raises urllib3.exceptions.TimeoutStateError: if you attempt
206
- to start a timer that has been started already.
207
- """
208
- if self._start_connect is not None:
209
- raise TimeoutStateError("Timeout timer has already been started.")
210
- self._start_connect = time.monotonic()
211
- return self._start_connect
212
-
213
- def get_connect_duration(self) -> float:
214
- """Gets the time elapsed since the call to :meth:`start_connect`.
215
-
216
- :return: Elapsed time in seconds.
217
- :rtype: float
218
- :raises urllib3.exceptions.TimeoutStateError: if you attempt
219
- to get duration for a timer that hasn't been started.
220
- """
221
- if self._start_connect is None:
222
- raise TimeoutStateError(
223
- "Can't get connect duration for timer that has not started."
224
- )
225
- return time.monotonic() - self._start_connect
226
-
227
- @property
228
- def connect_timeout(self) -> _TYPE_TIMEOUT:
229
- """Get the value to use when setting a connection timeout.
230
-
231
- This will be a positive float or integer, the value None
232
- (never timeout), or the default system timeout.
233
-
234
- :return: Connect timeout.
235
- :rtype: int, float, :attr:`Timeout.DEFAULT_TIMEOUT` or None
236
- """
237
- if self.total is None:
238
- return self._connect
239
-
240
- if self._connect is None or self._connect is _DEFAULT_TIMEOUT:
241
- return self.total
242
-
243
- return min(self._connect, self.total) # type: ignore[type-var]
244
-
245
- @property
246
- def read_timeout(self) -> float | None:
247
- """Get the value for the read timeout.
248
-
249
- This assumes some time has elapsed in the connection timeout and
250
- computes the read timeout appropriately.
251
-
252
- If self.total is set, the read timeout is dependent on the amount of
253
- time taken by the connect timeout. If the connection time has not been
254
- established, a :exc:`~urllib3.exceptions.TimeoutStateError` will be
255
- raised.
256
-
257
- :return: Value to use for the read timeout.
258
- :rtype: int, float or None
259
- :raises urllib3.exceptions.TimeoutStateError: If :meth:`start_connect`
260
- has not yet been called on this object.
261
- """
262
- if (
263
- self.total is not None
264
- and self.total is not _DEFAULT_TIMEOUT
265
- and self._read is not None
266
- and self._read is not _DEFAULT_TIMEOUT
267
- ):
268
- # In case the connect timeout has not yet been established.
269
- if self._start_connect is None:
270
- return self._read
271
- return max(0, min(self.total - self.get_connect_duration(), self._read))
272
- elif self.total is not None and self.total is not _DEFAULT_TIMEOUT:
273
- return max(0, self.total - self.get_connect_duration())
274
- else:
275
- return self.resolve_default_timeout(self._read)