catocli 2.0.3__py3-none-any.whl → 2.0.5__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.
- build/lib/catocli/Utils/clidriver.py +268 -0
- build/lib/catocli/Utils/profile_manager.py +188 -0
- build/lib/catocli/Utils/version_checker.py +192 -0
- build/lib/catocli/__init__.py +2 -0
- build/lib/catocli/__main__.py +12 -0
- build/lib/catocli/parsers/configure/__init__.py +115 -0
- build/lib/catocli/parsers/configure/configure.py +307 -0
- build/lib/catocli/parsers/custom/__init__.py +57 -0
- build/lib/catocli/parsers/custom/customLib.py +561 -0
- build/lib/catocli/parsers/custom/export_rules/__init__.py +42 -0
- build/lib/catocli/parsers/custom/export_rules/export_rules.py +234 -0
- build/lib/catocli/parsers/custom/export_sites/__init__.py +21 -0
- build/lib/catocli/parsers/custom/export_sites/export_sites.py +372 -0
- build/lib/catocli/parsers/custom/import_rules_to_tf/__init__.py +58 -0
- build/lib/catocli/parsers/custom/import_rules_to_tf/import_rules_to_tf.py +451 -0
- build/lib/catocli/parsers/custom/import_sites_to_tf/__init__.py +45 -0
- build/lib/catocli/parsers/custom/import_sites_to_tf/import_sites_to_tf.py +891 -0
- build/lib/catocli/parsers/mutation_accountManagement/__init__.py +48 -0
- build/lib/catocli/parsers/mutation_admin/__init__.py +48 -0
- build/lib/catocli/parsers/mutation_container/__init__.py +138 -0
- build/lib/catocli/parsers/mutation_hardware/__init__.py +22 -0
- build/lib/catocli/parsers/mutation_policy/__init__.py +1305 -0
- build/lib/catocli/parsers/mutation_sandbox/__init__.py +35 -0
- build/lib/catocli/parsers/mutation_site/__init__.py +373 -0
- build/lib/catocli/parsers/mutation_sites/__init__.py +373 -0
- build/lib/catocli/parsers/mutation_xdr/__init__.py +48 -0
- build/lib/catocli/parsers/parserApiClient.py +513 -0
- build/lib/catocli/parsers/query_accountBySubdomain/__init__.py +16 -0
- build/lib/catocli/parsers/query_accountManagement/__init__.py +16 -0
- build/lib/catocli/parsers/query_accountMetrics/__init__.py +16 -0
- build/lib/catocli/parsers/query_accountRoles/__init__.py +16 -0
- build/lib/catocli/parsers/query_accountSnapshot/__init__.py +16 -0
- build/lib/catocli/parsers/query_admin/__init__.py +16 -0
- build/lib/catocli/parsers/query_admins/__init__.py +16 -0
- build/lib/catocli/parsers/query_appStats/__init__.py +16 -0
- build/lib/catocli/parsers/query_appStatsTimeSeries/__init__.py +16 -0
- build/lib/catocli/parsers/query_auditFeed/__init__.py +16 -0
- build/lib/catocli/parsers/query_catalogs/__init__.py +16 -0
- build/lib/catocli/parsers/query_container/__init__.py +16 -0
- build/lib/catocli/parsers/query_devices/__init__.py +16 -0
- build/lib/catocli/parsers/query_entityLookup/__init__.py +16 -0
- build/lib/catocli/parsers/query_events/__init__.py +16 -0
- build/lib/catocli/parsers/query_eventsFeed/__init__.py +16 -0
- build/lib/catocli/parsers/query_eventsTimeSeries/__init__.py +16 -0
- build/lib/catocli/parsers/query_hardware/__init__.py +16 -0
- build/lib/catocli/parsers/query_hardwareManagement/__init__.py +16 -0
- build/lib/catocli/parsers/query_licensing/__init__.py +16 -0
- build/lib/catocli/parsers/query_policy/__init__.py +161 -0
- build/lib/catocli/parsers/query_sandbox/__init__.py +16 -0
- build/lib/catocli/parsers/query_site/__init__.py +100 -0
- build/lib/catocli/parsers/query_siteLocation/__init__.py +13 -0
- build/lib/catocli/parsers/query_subDomains/__init__.py +16 -0
- build/lib/catocli/parsers/query_xdr/__init__.py +35 -0
- build/lib/catocli/parsers/raw/__init__.py +12 -0
- build/lib/graphql_client/__init__.py +11 -0
- build/lib/graphql_client/api/__init__.py +3 -0
- build/lib/graphql_client/api/call_api.py +84 -0
- build/lib/graphql_client/api_client.py +192 -0
- build/lib/graphql_client/api_client_types.py +409 -0
- build/lib/graphql_client/configuration.py +232 -0
- build/lib/graphql_client/models/__init__.py +13 -0
- build/lib/graphql_client/models/no_schema.py +71 -0
- build/lib/schema/catolib.py +1141 -0
- build/lib/schema/importSchema.py +60 -0
- build/lib/schema/remove_policyid.py +89 -0
- build/lib/schema/remove_policyid_mutations.py +89 -0
- build/lib/scripts/catolib.py +62 -0
- build/lib/scripts/export_if_rules_to_json.py +188 -0
- build/lib/scripts/export_wf_rules_to_json.py +111 -0
- build/lib/scripts/import_wf_rules_to_tfstate.py +331 -0
- build/lib/vendor/certifi/__init__.py +4 -0
- build/lib/vendor/certifi/__main__.py +12 -0
- build/lib/vendor/certifi/core.py +114 -0
- build/lib/vendor/certifi/py.typed +0 -0
- build/lib/vendor/six.py +998 -0
- build/lib/vendor/urllib3/__init__.py +211 -0
- build/lib/vendor/urllib3/_base_connection.py +172 -0
- build/lib/vendor/urllib3/_collections.py +483 -0
- build/lib/vendor/urllib3/_request_methods.py +278 -0
- build/lib/vendor/urllib3/_version.py +16 -0
- build/lib/vendor/urllib3/connection.py +1033 -0
- build/lib/vendor/urllib3/connectionpool.py +1182 -0
- build/lib/vendor/urllib3/contrib/__init__.py +0 -0
- build/lib/vendor/urllib3/contrib/emscripten/__init__.py +18 -0
- build/lib/vendor/urllib3/contrib/emscripten/connection.py +254 -0
- build/lib/vendor/urllib3/contrib/emscripten/fetch.py +418 -0
- build/lib/vendor/urllib3/contrib/emscripten/request.py +22 -0
- build/lib/vendor/urllib3/contrib/emscripten/response.py +285 -0
- build/lib/vendor/urllib3/contrib/pyopenssl.py +552 -0
- build/lib/vendor/urllib3/contrib/socks.py +228 -0
- build/lib/vendor/urllib3/exceptions.py +321 -0
- build/lib/vendor/urllib3/fields.py +341 -0
- build/lib/vendor/urllib3/filepost.py +89 -0
- build/lib/vendor/urllib3/http2/__init__.py +53 -0
- build/lib/vendor/urllib3/http2/connection.py +356 -0
- build/lib/vendor/urllib3/http2/probe.py +87 -0
- build/lib/vendor/urllib3/poolmanager.py +637 -0
- build/lib/vendor/urllib3/py.typed +2 -0
- build/lib/vendor/urllib3/response.py +1265 -0
- build/lib/vendor/urllib3/util/__init__.py +42 -0
- build/lib/vendor/urllib3/util/connection.py +137 -0
- build/lib/vendor/urllib3/util/proxy.py +43 -0
- build/lib/vendor/urllib3/util/request.py +256 -0
- build/lib/vendor/urllib3/util/response.py +101 -0
- build/lib/vendor/urllib3/util/retry.py +533 -0
- build/lib/vendor/urllib3/util/ssl_.py +513 -0
- build/lib/vendor/urllib3/util/ssl_match_hostname.py +159 -0
- build/lib/vendor/urllib3/util/ssltransport.py +276 -0
- build/lib/vendor/urllib3/util/timeout.py +275 -0
- build/lib/vendor/urllib3/util/url.py +471 -0
- build/lib/vendor/urllib3/util/util.py +42 -0
- build/lib/vendor/urllib3/util/wait.py +124 -0
- catocli/Utils/clidriver.py +1 -4
- catocli/__init__.py +1 -1
- catocli/parsers/custom/export_rules/__init__.py +2 -0
- catocli/parsers/custom/export_rules/export_rules.py +29 -5
- catocli/parsers/custom/export_sites/__init__.py +1 -0
- catocli/parsers/custom/export_sites/export_sites.py +10 -3
- catocli/parsers/mutation_container/__init__.py +116 -0
- catocli/parsers/mutation_container_fqdn/README.md +7 -0
- catocli/parsers/mutation_container_fqdn_addValues/README.md +17 -0
- catocli/parsers/mutation_container_fqdn_createFromFile/README.md +17 -0
- catocli/parsers/mutation_container_fqdn_removeValues/README.md +17 -0
- catocli/parsers/mutation_container_fqdn_updateFromFile/README.md +17 -0
- catocli/parsers/mutation_container_ipAddressRange/README.md +7 -0
- catocli/parsers/mutation_container_ipAddressRange_addValues/README.md +17 -0
- catocli/parsers/mutation_container_ipAddressRange_createFromFile/README.md +17 -0
- catocli/parsers/mutation_container_ipAddressRange_removeValues/README.md +17 -0
- catocli/parsers/mutation_container_ipAddressRange_updateFromFile/README.md +17 -0
- catocli/parsers/mutation_policy_internetFirewall_addRule/README.md +1 -1
- catocli/parsers/mutation_policy_internetFirewall_updateRule/README.md +1 -1
- catocli/parsers/mutation_policy_wanFirewall_addRule/README.md +1 -1
- catocli/parsers/mutation_policy_wanFirewall_updateRule/README.md +1 -1
- catocli/parsers/parserApiClient.py +183 -7
- catocli/parsers/query_policy/README.md +0 -17
- catocli/parsers/query_policy/__init__.py +153 -8
- catocli/parsers/query_policy_appTenantRestriction/README.md +7 -0
- catocli/parsers/query_policy_appTenantRestriction_policy/README.md +17 -0
- catocli/parsers/query_policy_dynamicIpAllocation/README.md +7 -0
- catocli/parsers/query_policy_dynamicIpAllocation_policy/README.md +17 -0
- catocli/parsers/query_policy_internetFirewall/README.md +7 -0
- catocli/parsers/query_policy_internetFirewall_policy/README.md +17 -0
- catocli/parsers/query_policy_remotePortFwd/README.md +7 -0
- catocli/parsers/query_policy_remotePortFwd_policy/README.md +17 -0
- catocli/parsers/query_policy_socketLan/README.md +7 -0
- catocli/parsers/query_policy_socketLan_policy/README.md +17 -0
- catocli/parsers/query_policy_terminalServer/README.md +7 -0
- catocli/parsers/query_policy_terminalServer_policy/README.md +17 -0
- catocli/parsers/query_policy_wanFirewall/README.md +7 -0
- catocli/parsers/query_policy_wanFirewall_policy/README.md +17 -0
- catocli/parsers/query_policy_wanNetwork/README.md +7 -0
- catocli/parsers/query_policy_wanNetwork_policy/README.md +17 -0
- catocli/parsers/query_site/README.md +0 -16
- catocli/parsers/query_site/__init__.py +92 -8
- catocli/parsers/query_site_availableVersionList/README.md +17 -0
- catocli/parsers/query_site_bgpPeer/README.md +17 -0
- catocli/parsers/query_site_bgpPeerList/README.md +17 -0
- catocli/parsers/query_site_cloudInterconnectConnectionConnectivity/README.md +17 -0
- catocli/parsers/query_site_cloudInterconnectPhysicalConnection/README.md +17 -0
- catocli/parsers/query_site_cloudInterconnectPhysicalConnectionId/README.md +17 -0
- catocli/parsers/query_site_siteBgpStatus/README.md +17 -0
- {catocli-2.0.3.dist-info → catocli-2.0.5.dist-info}/METADATA +1 -1
- {catocli-2.0.3.dist-info → catocli-2.0.5.dist-info}/RECORD +291 -121
- {catocli-2.0.3.dist-info → catocli-2.0.5.dist-info}/top_level.txt +1 -0
- graphql_client/api/call_api.py +4 -3
- models/mutation.container.fqdn.addValues.json +866 -0
- models/mutation.container.fqdn.createFromFile.json +819 -0
- models/mutation.container.fqdn.removeValues.json +866 -0
- models/mutation.container.fqdn.updateFromFile.json +1045 -0
- models/mutation.container.ipAddressRange.addValues.json +1020 -0
- models/mutation.container.ipAddressRange.createFromFile.json +819 -0
- models/mutation.container.ipAddressRange.removeValues.json +1020 -0
- models/mutation.container.ipAddressRange.updateFromFile.json +1045 -0
- models/mutation.policy.appTenantRestriction.addRule.json +8 -8
- models/mutation.policy.appTenantRestriction.addSection.json +1 -1
- models/mutation.policy.appTenantRestriction.createPolicyRevision.json +2 -2
- models/mutation.policy.appTenantRestriction.discardPolicyRevision.json +2 -2
- models/mutation.policy.appTenantRestriction.moveRule.json +2 -2
- models/mutation.policy.appTenantRestriction.moveSection.json +1 -1
- models/mutation.policy.appTenantRestriction.publishPolicyRevision.json +2 -2
- models/mutation.policy.appTenantRestriction.removeRule.json +2 -2
- models/mutation.policy.appTenantRestriction.removeSection.json +1 -1
- models/mutation.policy.appTenantRestriction.updatePolicy.json +2 -2
- models/mutation.policy.appTenantRestriction.updateRule.json +8 -8
- models/mutation.policy.appTenantRestriction.updateSection.json +1 -1
- models/mutation.policy.dynamicIpAllocation.addRule.json +1 -1
- models/mutation.policy.dynamicIpAllocation.addSection.json +1 -1
- models/mutation.policy.dynamicIpAllocation.createPolicyRevision.json +1 -1
- models/mutation.policy.dynamicIpAllocation.discardPolicyRevision.json +1 -1
- models/mutation.policy.dynamicIpAllocation.moveRule.json +1 -1
- models/mutation.policy.dynamicIpAllocation.moveSection.json +1 -1
- models/mutation.policy.dynamicIpAllocation.publishPolicyRevision.json +1 -1
- models/mutation.policy.dynamicIpAllocation.removeRule.json +1 -1
- models/mutation.policy.dynamicIpAllocation.removeSection.json +1 -1
- models/mutation.policy.dynamicIpAllocation.updatePolicy.json +1 -1
- models/mutation.policy.dynamicIpAllocation.updateRule.json +1 -1
- models/mutation.policy.dynamicIpAllocation.updateSection.json +1 -1
- models/mutation.policy.internetFirewall.addRule.json +502 -55
- models/mutation.policy.internetFirewall.addSection.json +1 -1
- models/mutation.policy.internetFirewall.createPolicyRevision.json +127 -10
- models/mutation.policy.internetFirewall.discardPolicyRevision.json +127 -10
- models/mutation.policy.internetFirewall.moveRule.json +127 -10
- models/mutation.policy.internetFirewall.moveSection.json +1 -1
- models/mutation.policy.internetFirewall.publishPolicyRevision.json +127 -10
- models/mutation.policy.internetFirewall.removeRule.json +127 -10
- models/mutation.policy.internetFirewall.removeSection.json +1 -1
- models/mutation.policy.internetFirewall.updatePolicy.json +127 -10
- models/mutation.policy.internetFirewall.updateRule.json +493 -55
- models/mutation.policy.internetFirewall.updateSection.json +1 -1
- models/mutation.policy.remotePortFwd.addRule.json +5 -5
- models/mutation.policy.remotePortFwd.addSection.json +1 -1
- models/mutation.policy.remotePortFwd.createPolicyRevision.json +2 -2
- models/mutation.policy.remotePortFwd.discardPolicyRevision.json +2 -2
- models/mutation.policy.remotePortFwd.moveRule.json +2 -2
- models/mutation.policy.remotePortFwd.moveSection.json +1 -1
- models/mutation.policy.remotePortFwd.publishPolicyRevision.json +2 -2
- models/mutation.policy.remotePortFwd.removeRule.json +2 -2
- models/mutation.policy.remotePortFwd.removeSection.json +1 -1
- models/mutation.policy.remotePortFwd.updatePolicy.json +2 -2
- models/mutation.policy.remotePortFwd.updateRule.json +5 -5
- models/mutation.policy.remotePortFwd.updateSection.json +1 -1
- models/mutation.policy.socketLan.addRule.json +16 -16
- models/mutation.policy.socketLan.addSection.json +1 -1
- models/mutation.policy.socketLan.createPolicyRevision.json +4 -4
- models/mutation.policy.socketLan.discardPolicyRevision.json +4 -4
- models/mutation.policy.socketLan.moveRule.json +4 -4
- models/mutation.policy.socketLan.moveSection.json +1 -1
- models/mutation.policy.socketLan.publishPolicyRevision.json +4 -4
- models/mutation.policy.socketLan.removeRule.json +4 -4
- models/mutation.policy.socketLan.removeSection.json +1 -1
- models/mutation.policy.socketLan.updatePolicy.json +4 -4
- models/mutation.policy.socketLan.updateRule.json +16 -16
- models/mutation.policy.socketLan.updateSection.json +1 -1
- models/mutation.policy.terminalServer.addRule.json +1 -1
- models/mutation.policy.terminalServer.addSection.json +1 -1
- models/mutation.policy.terminalServer.createPolicyRevision.json +1 -1
- models/mutation.policy.terminalServer.discardPolicyRevision.json +1 -1
- models/mutation.policy.terminalServer.moveRule.json +1 -1
- models/mutation.policy.terminalServer.moveSection.json +1 -1
- models/mutation.policy.terminalServer.publishPolicyRevision.json +1 -1
- models/mutation.policy.terminalServer.removeRule.json +1 -1
- models/mutation.policy.terminalServer.removeSection.json +1 -1
- models/mutation.policy.terminalServer.updatePolicy.json +1 -1
- models/mutation.policy.terminalServer.updateRule.json +1 -1
- models/mutation.policy.terminalServer.updateSection.json +1 -1
- models/mutation.policy.wanFirewall.addRule.json +500 -53
- models/mutation.policy.wanFirewall.addSection.json +1 -1
- models/mutation.policy.wanFirewall.createPolicyRevision.json +128 -11
- models/mutation.policy.wanFirewall.discardPolicyRevision.json +128 -11
- models/mutation.policy.wanFirewall.moveRule.json +128 -11
- models/mutation.policy.wanFirewall.moveSection.json +1 -1
- models/mutation.policy.wanFirewall.publishPolicyRevision.json +128 -11
- models/mutation.policy.wanFirewall.removeRule.json +128 -11
- models/mutation.policy.wanFirewall.removeSection.json +1 -1
- models/mutation.policy.wanFirewall.updatePolicy.json +128 -11
- models/mutation.policy.wanFirewall.updateRule.json +491 -53
- models/mutation.policy.wanFirewall.updateSection.json +1 -1
- models/mutation.policy.wanNetwork.addRule.json +13 -13
- models/mutation.policy.wanNetwork.addSection.json +1 -1
- models/mutation.policy.wanNetwork.createPolicyRevision.json +1 -1
- models/mutation.policy.wanNetwork.discardPolicyRevision.json +1 -1
- models/mutation.policy.wanNetwork.moveRule.json +1 -1
- models/mutation.policy.wanNetwork.moveSection.json +1 -1
- models/mutation.policy.wanNetwork.publishPolicyRevision.json +1 -1
- models/mutation.policy.wanNetwork.removeRule.json +1 -1
- models/mutation.policy.wanNetwork.removeSection.json +1 -1
- models/mutation.policy.wanNetwork.updatePolicy.json +1 -1
- models/mutation.policy.wanNetwork.updateRule.json +13 -13
- models/mutation.policy.wanNetwork.updateSection.json +1 -1
- models/query.policy.appTenantRestriction.policy.json +3086 -0
- models/query.policy.dynamicIpAllocation.policy.json +1934 -0
- models/query.policy.internetFirewall.policy.json +7833 -0
- models/query.policy.json +233 -0
- models/query.policy.remotePortFwd.policy.json +2387 -0
- models/query.policy.socketLan.policy.json +7140 -0
- models/query.policy.terminalServer.policy.json +1632 -0
- models/query.policy.wanFirewall.policy.json +9212 -0
- models/query.policy.wanNetwork.policy.json +8010 -0
- models/query.site.availableVersionList.json +365 -0
- models/query.site.bgpPeer.json +1917 -0
- models/query.site.bgpPeerList.json +2076 -0
- models/query.site.cloudInterconnectConnectionConnectivity.json +298 -0
- models/query.site.cloudInterconnectPhysicalConnection.json +728 -0
- models/query.site.cloudInterconnectPhysicalConnectionId.json +660 -0
- models/query.site.siteBgpStatus.json +869 -0
- schema/catolib.py +13 -6
- schema/remove_policyid.py +89 -0
- schema/remove_policyid_mutations.py +89 -0
- {catocli-2.0.3.dist-info → catocli-2.0.5.dist-info}/LICENSE +0 -0
- {catocli-2.0.3.dist-info → catocli-2.0.5.dist-info}/WHEEL +0 -0
- {catocli-2.0.3.dist-info → catocli-2.0.5.dist-info}/entry_points.txt +0 -0
|
@@ -0,0 +1,22 @@
|
|
|
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
|
|
@@ -0,0 +1,285 @@
|
|
|
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()
|