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,22 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from dataclasses import dataclass, field
4
-
5
- from ..._base_connection import _TYPE_BODY
6
-
7
-
8
- @dataclass
9
- class EmscriptenRequest:
10
- method: str
11
- url: str
12
- params: dict[str, str] | None = None
13
- body: _TYPE_BODY | None = None
14
- headers: dict[str, str] = field(default_factory=dict)
15
- timeout: float = 0
16
- decode_content: bool = True
17
-
18
- def set_header(self, name: str, value: str) -> None:
19
- self.headers[name.capitalize()] = value
20
-
21
- def set_body(self, body: _TYPE_BODY | None) -> None:
22
- self.body = body
@@ -1,285 +0,0 @@
1
- from __future__ import annotations
2
-
3
- import json as _json
4
- import logging
5
- import typing
6
- from contextlib import contextmanager
7
- from dataclasses import dataclass
8
- from http.client import HTTPException as HTTPException
9
- from io import BytesIO, IOBase
10
-
11
- from ...exceptions import InvalidHeader, TimeoutError
12
- from ...response import BaseHTTPResponse
13
- from ...util.retry import Retry
14
- from .request import EmscriptenRequest
15
-
16
- if typing.TYPE_CHECKING:
17
- from ..._base_connection import BaseHTTPConnection, BaseHTTPSConnection
18
-
19
- log = logging.getLogger(__name__)
20
-
21
-
22
- @dataclass
23
- class EmscriptenResponse:
24
- status_code: int
25
- headers: dict[str, str]
26
- body: IOBase | bytes
27
- request: EmscriptenRequest
28
-
29
-
30
- class EmscriptenHttpResponseWrapper(BaseHTTPResponse):
31
- def __init__(
32
- self,
33
- internal_response: EmscriptenResponse,
34
- url: str | None = None,
35
- connection: BaseHTTPConnection | BaseHTTPSConnection | None = None,
36
- ):
37
- self._pool = None # set by pool class
38
- self._body = None
39
- self._response = internal_response
40
- self._url = url
41
- self._connection = connection
42
- self._closed = False
43
- super().__init__(
44
- headers=internal_response.headers,
45
- status=internal_response.status_code,
46
- request_url=url,
47
- version=0,
48
- version_string="HTTP/?",
49
- reason="",
50
- decode_content=True,
51
- )
52
- self.length_remaining = self._init_length(self._response.request.method)
53
- self.length_is_certain = False
54
-
55
- @property
56
- def url(self) -> str | None:
57
- return self._url
58
-
59
- @url.setter
60
- def url(self, url: str | None) -> None:
61
- self._url = url
62
-
63
- @property
64
- def connection(self) -> BaseHTTPConnection | BaseHTTPSConnection | None:
65
- return self._connection
66
-
67
- @property
68
- def retries(self) -> Retry | None:
69
- return self._retries
70
-
71
- @retries.setter
72
- def retries(self, retries: Retry | None) -> None:
73
- # Override the request_url if retries has a redirect location.
74
- self._retries = retries
75
-
76
- def stream(
77
- self, amt: int | None = 2**16, decode_content: bool | None = None
78
- ) -> typing.Generator[bytes, None, None]:
79
- """
80
- A generator wrapper for the read() method. A call will block until
81
- ``amt`` bytes have been read from the connection or until the
82
- connection is closed.
83
-
84
- :param amt:
85
- How much of the content to read. The generator will return up to
86
- much data per iteration, but may return less. This is particularly
87
- likely when using compressed data. However, the empty string will
88
- never be returned.
89
-
90
- :param decode_content:
91
- If True, will attempt to decode the body based on the
92
- 'content-encoding' header.
93
- """
94
- while True:
95
- data = self.read(amt=amt, decode_content=decode_content)
96
-
97
- if data:
98
- yield data
99
- else:
100
- break
101
-
102
- def _init_length(self, request_method: str | None) -> int | None:
103
- length: int | None
104
- content_length: str | None = self.headers.get("content-length")
105
-
106
- if content_length is not None:
107
- try:
108
- # RFC 7230 section 3.3.2 specifies multiple content lengths can
109
- # be sent in a single Content-Length header
110
- # (e.g. Content-Length: 42, 42). This line ensures the values
111
- # are all valid ints and that as long as the `set` length is 1,
112
- # all values are the same. Otherwise, the header is invalid.
113
- lengths = {int(val) for val in content_length.split(",")}
114
- if len(lengths) > 1:
115
- raise InvalidHeader(
116
- "Content-Length contained multiple "
117
- "unmatching values (%s)" % content_length
118
- )
119
- length = lengths.pop()
120
- except ValueError:
121
- length = None
122
- else:
123
- if length < 0:
124
- length = None
125
-
126
- else: # if content_length is None
127
- length = None
128
-
129
- # Check for responses that shouldn't include a body
130
- if (
131
- self.status in (204, 304)
132
- or 100 <= self.status < 200
133
- or request_method == "HEAD"
134
- ):
135
- length = 0
136
-
137
- return length
138
-
139
- def read(
140
- self,
141
- amt: int | None = None,
142
- decode_content: bool | None = None, # ignored because browser decodes always
143
- cache_content: bool = False,
144
- ) -> bytes:
145
- if (
146
- self._closed
147
- or self._response is None
148
- or (isinstance(self._response.body, IOBase) and self._response.body.closed)
149
- ):
150
- return b""
151
-
152
- with self._error_catcher():
153
- # body has been preloaded as a string by XmlHttpRequest
154
- if not isinstance(self._response.body, IOBase):
155
- self.length_remaining = len(self._response.body)
156
- self.length_is_certain = True
157
- # wrap body in IOStream
158
- self._response.body = BytesIO(self._response.body)
159
- if amt is not None and amt >= 0:
160
- # don't cache partial content
161
- cache_content = False
162
- data = self._response.body.read(amt)
163
- if self.length_remaining is not None:
164
- self.length_remaining = max(self.length_remaining - len(data), 0)
165
- if (self.length_is_certain and self.length_remaining == 0) or len(
166
- data
167
- ) < amt:
168
- # definitely finished reading, close response stream
169
- self._response.body.close()
170
- return typing.cast(bytes, data)
171
- else: # read all we can (and cache it)
172
- data = self._response.body.read()
173
- if cache_content:
174
- self._body = data
175
- if self.length_remaining is not None:
176
- self.length_remaining = max(self.length_remaining - len(data), 0)
177
- if len(data) == 0 or (
178
- self.length_is_certain and self.length_remaining == 0
179
- ):
180
- # definitely finished reading, close response stream
181
- self._response.body.close()
182
- return typing.cast(bytes, data)
183
-
184
- def read_chunked(
185
- self,
186
- amt: int | None = None,
187
- decode_content: bool | None = None,
188
- ) -> typing.Generator[bytes, None, None]:
189
- # chunked is handled by browser
190
- while True:
191
- bytes = self.read(amt, decode_content)
192
- if not bytes:
193
- break
194
- yield bytes
195
-
196
- def release_conn(self) -> None:
197
- if not self._pool or not self._connection:
198
- return None
199
-
200
- self._pool._put_conn(self._connection)
201
- self._connection = None
202
-
203
- def drain_conn(self) -> None:
204
- self.close()
205
-
206
- @property
207
- def data(self) -> bytes:
208
- if self._body:
209
- return self._body
210
- else:
211
- return self.read(cache_content=True)
212
-
213
- def json(self) -> typing.Any:
214
- """
215
- Deserializes the body of the HTTP response as a Python object.
216
-
217
- The body of the HTTP response must be encoded using UTF-8, as per
218
- `RFC 8529 Section 8.1 <https://www.rfc-editor.org/rfc/rfc8259#section-8.1>`_.
219
-
220
- To use a custom JSON decoder pass the result of :attr:`HTTPResponse.data` to
221
- your custom decoder instead.
222
-
223
- If the body of the HTTP response is not decodable to UTF-8, a
224
- `UnicodeDecodeError` will be raised. If the body of the HTTP response is not a
225
- valid JSON document, a `json.JSONDecodeError` will be raised.
226
-
227
- Read more :ref:`here <json_content>`.
228
-
229
- :returns: The body of the HTTP response as a Python object.
230
- """
231
- data = self.data.decode("utf-8")
232
- return _json.loads(data)
233
-
234
- def close(self) -> None:
235
- if not self._closed:
236
- if isinstance(self._response.body, IOBase):
237
- self._response.body.close()
238
- if self._connection:
239
- self._connection.close()
240
- self._connection = None
241
- self._closed = True
242
-
243
- @contextmanager
244
- def _error_catcher(self) -> typing.Generator[None, None, None]:
245
- """
246
- Catch Emscripten specific exceptions thrown by fetch.py,
247
- instead re-raising urllib3 variants, so that low-level exceptions
248
- are not leaked in the high-level api.
249
-
250
- On exit, release the connection back to the pool.
251
- """
252
- from .fetch import _RequestError, _TimeoutError # avoid circular import
253
-
254
- clean_exit = False
255
-
256
- try:
257
- yield
258
- # If no exception is thrown, we should avoid cleaning up
259
- # unnecessarily.
260
- clean_exit = True
261
- except _TimeoutError as e:
262
- raise TimeoutError(str(e))
263
- except _RequestError as e:
264
- raise HTTPException(str(e))
265
- finally:
266
- # If we didn't terminate cleanly, we need to throw away our
267
- # connection.
268
- if not clean_exit:
269
- # The response may not be closed but we're not going to use it
270
- # anymore so close it now
271
- if (
272
- isinstance(self._response.body, IOBase)
273
- and not self._response.body.closed
274
- ):
275
- self._response.body.close()
276
- # release the connection back to the pool
277
- self.release_conn()
278
- else:
279
- # If we have read everything from the response stream,
280
- # return the connection back to the pool.
281
- if (
282
- isinstance(self._response.body, IOBase)
283
- and self._response.body.closed
284
- ):
285
- self.release_conn()