oci 2.138.1__py3-none-any.whl → 2.139.0__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.
Files changed (342) hide show
  1. oci/_vendor/idna/__init__.py +45 -2
  2. oci/_vendor/idna/codec.py +47 -43
  3. oci/_vendor/idna/compat.py +10 -7
  4. oci/_vendor/idna/core.py +210 -173
  5. oci/_vendor/idna/idnadata.py +3869 -1676
  6. oci/_vendor/idna/intranges.py +13 -9
  7. oci/_vendor/idna/package_data.py +2 -3
  8. oci/_vendor/idna/uts46data.py +8355 -8031
  9. oci/_vendor/urllib3/__init__.py +1 -1
  10. oci/_vendor/urllib3/_collections.py +19 -1
  11. oci/_vendor/urllib3/_version.py +2 -2
  12. oci/_vendor/urllib3/connection.py +8 -3
  13. oci/_vendor/urllib3/connectionpool.py +45 -13
  14. oci/_vendor/urllib3/contrib/__init__.py +1 -1
  15. oci/_vendor/urllib3/contrib/_appengine_environ.py +1 -1
  16. oci/_vendor/urllib3/contrib/_securetransport/__init__.py +1 -1
  17. oci/_vendor/urllib3/contrib/_securetransport/bindings.py +2 -2
  18. oci/_vendor/urllib3/contrib/_securetransport/low_level.py +1 -1
  19. oci/_vendor/urllib3/contrib/appengine.py +2 -2
  20. oci/_vendor/urllib3/contrib/ntlmpool.py +3 -3
  21. oci/_vendor/urllib3/contrib/pyopenssl.py +14 -7
  22. oci/_vendor/urllib3/contrib/securetransport.py +2 -4
  23. oci/_vendor/urllib3/contrib/socks.py +1 -1
  24. oci/_vendor/urllib3/exceptions.py +1 -1
  25. oci/_vendor/urllib3/fields.py +1 -1
  26. oci/_vendor/urllib3/filepost.py +1 -1
  27. oci/_vendor/urllib3/packages/__init__.py +2 -2
  28. oci/_vendor/urllib3/packages/backports/__init__.py +1 -1
  29. oci/_vendor/urllib3/packages/backports/makefile.py +1 -1
  30. oci/_vendor/urllib3/packages/backports/weakref_finalize.py +160 -0
  31. oci/_vendor/urllib3/packages/six.py +1 -2
  32. oci/_vendor/urllib3/poolmanager.py +7 -4
  33. oci/_vendor/urllib3/request.py +22 -1
  34. oci/_vendor/urllib3/response.py +65 -4
  35. oci/_vendor/urllib3/util/__init__.py +1 -1
  36. oci/_vendor/urllib3/util/connection.py +1 -1
  37. oci/_vendor/urllib3/util/proxy.py +1 -1
  38. oci/_vendor/urllib3/util/queue.py +1 -1
  39. oci/_vendor/urllib3/util/request.py +1 -1
  40. oci/_vendor/urllib3/util/response.py +1 -1
  41. oci/_vendor/urllib3/util/retry.py +5 -3
  42. oci/_vendor/urllib3/util/ssl_.py +14 -5
  43. oci/_vendor/urllib3/util/ssl_match_hostname.py +1 -1
  44. oci/_vendor/urllib3/util/ssltransport.py +1 -1
  45. oci/_vendor/urllib3/util/timeout.py +7 -4
  46. oci/_vendor/urllib3/util/url.py +8 -5
  47. oci/_vendor/urllib3/util/wait.py +1 -2
  48. oci/access_governance_cp/access_governance_cp_client.py +8 -8
  49. oci/adm/application_dependency_management_client.py +36 -36
  50. oci/ai_anomaly_detection/anomaly_detection_client.py +36 -36
  51. oci/ai_document/ai_service_document_client.py +26 -26
  52. oci/ai_language/ai_service_language_client.py +44 -44
  53. oci/ai_speech/ai_service_speech_client.py +19 -19
  54. oci/ai_vision/ai_service_vision_client.py +25 -25
  55. oci/analytics/analytics_client.py +24 -24
  56. oci/announcements_service/announcement_client.py +5 -5
  57. oci/announcements_service/announcement_subscription_client.py +9 -9
  58. oci/announcements_service/announcements_preferences_client.py +4 -4
  59. oci/announcements_service/service_client.py +1 -1
  60. oci/apigateway/api_gateway_client.py +21 -21
  61. oci/apigateway/deployment_client.py +6 -6
  62. oci/apigateway/gateway_client.py +6 -6
  63. oci/apigateway/subscribers_client.py +6 -6
  64. oci/apigateway/usage_plans_client.py +6 -6
  65. oci/apigateway/work_requests_client.py +5 -5
  66. oci/apm_config/config_client.py +9 -9
  67. oci/apm_control_plane/apm_domain_client.py +14 -14
  68. oci/apm_synthetics/apm_synthetic_client.py +28 -28
  69. oci/apm_traces/attributes_client.py +8 -8
  70. oci/apm_traces/query_client.py +2 -2
  71. oci/apm_traces/trace_client.py +4 -4
  72. oci/appmgmt_control/appmgmt_control_client.py +8 -8
  73. oci/artifacts/artifacts_client.py +32 -32
  74. oci/audit/audit_client.py +3 -3
  75. oci/autoscaling/auto_scaling_client.py +11 -11
  76. oci/bastion/bastion_client.py +15 -15
  77. oci/bds/bds_client.py +72 -72
  78. oci/blockchain/blockchain_platform_client.py +27 -27
  79. oci/budget/budget_client.py +10 -10
  80. oci/capacity_management/capacity_management_client.py +32 -32
  81. oci/certificates/certificates_client.py +5 -5
  82. oci/certificates_management/certificates_management_client.py +32 -32
  83. oci/cims/incident_client.py +13 -14
  84. oci/cims/models/__init__.py +4 -2
  85. oci/cims/models/cmos_user_group_info.py +103 -0
  86. oci/cims/models/create_incident.py +33 -2
  87. oci/cims/models/create_limit_item_details.py +2 -57
  88. oci/cims/models/create_user_details.py +4 -4
  89. oci/cims/models/incident.py +188 -0
  90. oci/cims/models/incident_resource_type.py +4 -4
  91. oci/cims/models/incident_summary.py +188 -0
  92. oci/cims/models/limit_item.py +2 -2
  93. oci/cims/models/{service_categories.py → services.py} +27 -27
  94. oci/cims/models/sub_categories.py +15 -15
  95. oci/cims/models/ticket.py +7 -3
  96. oci/cims/models/validation_response.py +33 -2
  97. oci/cloud_bridge/common_client.py +5 -5
  98. oci/cloud_bridge/discovery_client.py +15 -15
  99. oci/cloud_bridge/inventory_client.py +16 -16
  100. oci/cloud_bridge/ocb_agent_svc_client.py +22 -22
  101. oci/cloud_guard/cloud_guard_client.py +155 -155
  102. oci/cloud_migrations/migration_client.py +43 -43
  103. oci/cluster_placement_groups/cluster_placement_groups_cp_client.py +13 -13
  104. oci/compute_cloud_at_customer/compute_cloud_at_customer_client.py +12 -12
  105. oci/compute_instance_agent/compute_instance_agent_client.py +6 -6
  106. oci/compute_instance_agent/plugin_client.py +2 -2
  107. oci/compute_instance_agent/pluginconfig_client.py +1 -1
  108. oci/container_engine/container_engine_client.py +44 -44
  109. oci/container_instances/container_instance_client.py +18 -18
  110. oci/core/blockstorage_client.py +60 -60
  111. oci/core/compute_client.py +102 -102
  112. oci/core/compute_management_client.py +32 -32
  113. oci/core/virtual_network_client.py +247 -247
  114. oci/dashboard_service/dashboard_client.py +6 -6
  115. oci/dashboard_service/dashboard_group_client.py +6 -6
  116. oci/data_catalog/data_catalog_client.py +149 -149
  117. oci/data_flow/data_flow_client.py +44 -44
  118. oci/data_integration/data_integration_client.py +163 -163
  119. oci/data_labeling_service/data_labeling_management_client.py +17 -17
  120. oci/data_labeling_service_dataplane/data_labeling_client.py +15 -15
  121. oci/data_safe/data_safe_client.py +292 -292
  122. oci/data_science/data_science_client.py +92 -92
  123. oci/database/database_client.py +523 -398
  124. oci/database/database_client_composite_operations.py +88 -0
  125. oci/database/models/__init__.py +4 -0
  126. oci/database/models/autonomous_database.py +2 -2
  127. oci/database/models/autonomous_database_summary.py +2 -2
  128. oci/database/models/configure_exascale_exadata_infrastructure_details.py +72 -0
  129. oci/database/models/create_autonomous_database_base.py +2 -2
  130. oci/database/models/create_db_home_details.py +33 -2
  131. oci/database/models/create_db_home_from_backup_details.py +31 -0
  132. oci/database/models/create_db_home_from_database_details.py +31 -0
  133. oci/database/models/create_exascale_db_storage_vault_details.py +37 -2
  134. oci/database/models/create_pluggable_database_creation_type_details.py +2 -2
  135. oci/database/models/create_vm_cluster_details.py +37 -2
  136. oci/database/models/exadata_infrastructure.py +29 -2
  137. oci/database/models/exadata_infrastructure_summary.py +29 -2
  138. oci/database/models/exascale_config_details.py +103 -0
  139. oci/database/models/exascale_db_storage_vault.py +35 -0
  140. oci/database/models/exascale_db_storage_vault_summary.py +37 -2
  141. oci/database/models/update_autonomous_database_details.py +2 -2
  142. oci/database/models/vm_cluster.py +84 -2
  143. oci/database/models/vm_cluster_summary.py +84 -2
  144. oci/database_management/db_management_client.py +211 -211
  145. oci/database_management/diagnosability_client.py +4 -4
  146. oci/database_management/managed_my_sql_databases_client.py +7 -7
  147. oci/database_management/perfhub_client.py +1 -1
  148. oci/database_management/sql_tuning_client.py +17 -17
  149. oci/database_migration/database_migration_client.py +42 -42
  150. oci/database_tools/database_tools_client.py +23 -23
  151. oci/delegate_access_control/delegate_access_control_client.py +26 -26
  152. oci/delegate_access_control/work_request_client.py +4 -4
  153. oci/demand_signal/occ_demand_signal_client.py +7 -7
  154. oci/desktops/desktop_service_client.py +21 -21
  155. oci/devops/devops_client.py +141 -141
  156. oci/disaster_recovery/disaster_recovery_client.py +29 -29
  157. oci/dns/dns_client.py +54 -54
  158. oci/dts/appliance_export_job_client.py +6 -6
  159. oci/dts/shipping_vendors_client.py +1 -1
  160. oci/dts/transfer_appliance_client.py +8 -8
  161. oci/dts/transfer_appliance_entitlement_client.py +3 -3
  162. oci/dts/transfer_device_client.py +5 -5
  163. oci/dts/transfer_job_client.py +6 -6
  164. oci/dts/transfer_package_client.py +7 -7
  165. oci/em_warehouse/em_warehouse_client.py +13 -13
  166. oci/email/email_client.py +31 -31
  167. oci/email_data_plane/email_dp_client.py +1 -1
  168. oci/events/events_client.py +6 -6
  169. oci/file_storage/file_storage_client.py +68 -68
  170. oci/fleet_apps_management/fleet_apps_management_admin_client.py +25 -25
  171. oci/fleet_apps_management/fleet_apps_management_client.py +35 -35
  172. oci/fleet_apps_management/fleet_apps_management_maintenance_window_client.py +5 -5
  173. oci/fleet_apps_management/fleet_apps_management_operations_client.py +26 -26
  174. oci/fleet_apps_management/fleet_apps_management_runbooks_client.py +12 -12
  175. oci/fleet_software_update/fleet_software_update_client.py +46 -46
  176. oci/functions/functions_invoke_client.py +1 -1
  177. oci/functions/functions_management_client.py +16 -16
  178. oci/fusion_apps/fusion_applications_client.py +41 -41
  179. oci/generative_ai/generative_ai_client.py +22 -22
  180. oci/generative_ai_agent/generative_ai_agent_client.py +33 -33
  181. oci/generative_ai_agent_runtime/generative_ai_agent_runtime_client.py +5 -5
  182. oci/generative_ai_inference/generative_ai_inference_client.py +4 -4
  183. oci/generic_artifacts_content/generic_artifacts_content_client.py +3 -3
  184. oci/globally_distributed_database/sharded_database_service_client.py +30 -30
  185. oci/golden_gate/golden_gate_client.py +70 -70
  186. oci/governance_rules_control_plane/governance_rule_client.py +15 -15
  187. oci/governance_rules_control_plane/work_request_client.py +5 -5
  188. oci/healthchecks/health_checks_client.py +17 -17
  189. oci/identity/identity_client.py +145 -145
  190. oci/identity_data_plane/dataplane_client.py +2 -2
  191. oci/identity_domains/identity_domains_client.py +311 -311
  192. oci/integration/integration_instance_client.py +19 -19
  193. oci/jms/java_management_service_client.py +75 -75
  194. oci/jms_java_downloads/java_download_client.py +25 -25
  195. oci/key_management/ekm_client.py +5 -5
  196. oci/key_management/kms_crypto_client.py +6 -6
  197. oci/key_management/kms_hsm_cluster_client.py +12 -12
  198. oci/key_management/kms_management_client.py +21 -21
  199. oci/key_management/kms_vault_client.py +14 -14
  200. oci/license_manager/license_manager_client.py +18 -18
  201. oci/limits/limits_client.py +4 -4
  202. oci/limits/quotas_client.py +7 -7
  203. oci/load_balancer/load_balancer_client.py +61 -61
  204. oci/lockbox/lockbox_client.py +24 -24
  205. oci/log_analytics/log_analytics_client.py +193 -193
  206. oci/logging/logging_management_client.py +30 -30
  207. oci/loggingingestion/logging_client.py +1 -1
  208. oci/loggingsearch/log_search_client.py +1 -1
  209. oci/management_agent/management_agent_client.py +28 -28
  210. oci/management_dashboard/dashx_apis_client.py +14 -14
  211. oci/marketplace/account_client.py +2 -2
  212. oci/marketplace/marketplace_client.py +30 -30
  213. oci/marketplace_private_offer/attachment_client.py +5 -5
  214. oci/marketplace_private_offer/offer_client.py +6 -6
  215. oci/marketplace_publisher/attachment_client.py +5 -5
  216. oci/marketplace_publisher/marketplace_publisher_client.py +71 -71
  217. oci/marketplace_publisher/offer_client.py +6 -6
  218. oci/media_services/media_services_client.py +60 -60
  219. oci/media_services/media_stream_client.py +2 -2
  220. oci/monitoring/monitoring_client.py +18 -18
  221. oci/mysql/channels_client.py +7 -7
  222. oci/mysql/db_backups_client.py +7 -7
  223. oci/mysql/db_system_client.py +17 -17
  224. oci/mysql/mysqlaas_client.py +7 -7
  225. oci/mysql/replicas_client.py +5 -5
  226. oci/mysql/work_requests_client.py +4 -4
  227. oci/network_firewall/network_firewall_client.py +86 -86
  228. oci/network_load_balancer/network_load_balancer_client.py +34 -34
  229. oci/nosql/nosql_client.py +24 -24
  230. oci/object_storage/object_storage_client.py +153 -57
  231. oci/oce/oce_instance_client.py +10 -10
  232. oci/oci_control_center/occ_metrics_client.py +3 -3
  233. oci/ocvp/cluster_client.py +5 -5
  234. oci/ocvp/esxi_host_client.py +8 -8
  235. oci/ocvp/sddc_client.py +14 -14
  236. oci/ocvp/work_request_client.py +4 -4
  237. oci/oda/management_client.py +59 -59
  238. oci/oda/oda_client.py +17 -17
  239. oci/oda/odapackage_client.py +7 -7
  240. oci/onesubscription/billing_schedule_client.py +1 -1
  241. oci/onesubscription/commitment_client.py +2 -2
  242. oci/onesubscription/computed_usage_client.py +3 -3
  243. oci/onesubscription/invoice_summary_client.py +2 -2
  244. oci/onesubscription/organization_subscription_client.py +1 -1
  245. oci/onesubscription/ratecard_client.py +1 -1
  246. oci/onesubscription/subscribed_service_client.py +2 -2
  247. oci/onesubscription/subscription_client.py +1 -1
  248. oci/ons/notification_control_plane_client.py +6 -6
  249. oci/ons/notification_data_plane_client.py +10 -10
  250. oci/opa/opa_instance_client.py +13 -13
  251. oci/opensearch/opensearch_cluster_backup_client.py +4 -4
  252. oci/opensearch/opensearch_cluster_client.py +14 -14
  253. oci/operator_access_control/access_requests_client.py +10 -10
  254. oci/operator_access_control/operator_actions_client.py +2 -2
  255. oci/operator_access_control/operator_control_assignment_client.py +8 -8
  256. oci/operator_access_control/operator_control_client.py +6 -6
  257. oci/opsi/operations_insights_client.py +180 -180
  258. oci/optimizer/optimizer_client.py +26 -26
  259. oci/os_management/event_client.py +8 -8
  260. oci/os_management/os_management_client.py +69 -69
  261. oci/os_management_hub/event_client.py +8 -8
  262. oci/os_management_hub/lifecycle_environment_client.py +12 -12
  263. oci/os_management_hub/managed_instance_client.py +31 -31
  264. oci/os_management_hub/managed_instance_group_client.py +25 -25
  265. oci/os_management_hub/management_station_client.py +10 -10
  266. oci/os_management_hub/onboarding_client.py +6 -6
  267. oci/os_management_hub/reporting_managed_instance_client.py +3 -3
  268. oci/os_management_hub/scheduled_job_client.py +7 -7
  269. oci/os_management_hub/software_source_client.py +27 -27
  270. oci/os_management_hub/work_request_client.py +4 -4
  271. oci/osp_gateway/address_rule_service_client.py +1 -1
  272. oci/osp_gateway/address_service_client.py +2 -2
  273. oci/osp_gateway/invoice_service_client.py +5 -5
  274. oci/osp_gateway/subscription_service_client.py +5 -5
  275. oci/osub_billing_schedule/billing_schedule_client.py +1 -1
  276. oci/osub_organization_subscription/organization_subscription_client.py +1 -1
  277. oci/osub_subscription/commitment_client.py +2 -2
  278. oci/osub_subscription/ratecard_client.py +1 -1
  279. oci/osub_subscription/subscription_client.py +1 -1
  280. oci/osub_usage/computed_usage_client.py +3 -3
  281. oci/psql/models/connection_details.py +29 -2
  282. oci/psql/models/endpoint.py +1 -1
  283. oci/psql/models/network_details.py +33 -2
  284. oci/psql/models/update_network_details.py +33 -2
  285. oci/psql/postgresql_client.py +33 -33
  286. oci/queue/queue_admin_client.py +11 -11
  287. oci/queue/queue_client.py +8 -8
  288. oci/recovery/database_recovery_client.py +26 -26
  289. oci/redis/redis_cluster_client.py +12 -12
  290. oci/resource_manager/resource_manager_client.py +52 -52
  291. oci/resource_scheduler/schedule_client.py +13 -13
  292. oci/resource_search/resource_search_client.py +3 -3
  293. oci/rover/rover_bundle_client.py +8 -8
  294. oci/rover/rover_cluster_client.py +8 -8
  295. oci/rover/rover_entitlement_client.py +6 -6
  296. oci/rover/rover_node_client.py +15 -15
  297. oci/rover/shape_client.py +1 -1
  298. oci/rover/work_requests_client.py +5 -5
  299. oci/sch/connector_plugins_client.py +2 -2
  300. oci/sch/service_connector_client.py +12 -12
  301. oci/secrets/secrets_client.py +3 -3
  302. oci/security_attribute/security_attribute_client.py +18 -18
  303. oci/service_catalog/service_catalog_client.py +26 -26
  304. oci/service_manager_proxy/service_manager_proxy_client.py +2 -2
  305. oci/service_mesh/service_mesh_client.py +48 -48
  306. oci/stack_monitoring/stack_monitoring_client.py +71 -71
  307. oci/streaming/stream_admin_client.py +18 -18
  308. oci/streaming/stream_client.py +8 -8
  309. oci/tenant_manager_control_plane/domain_client.py +5 -5
  310. oci/tenant_manager_control_plane/domain_governance_client.py +5 -5
  311. oci/tenant_manager_control_plane/governance_client.py +2 -2
  312. oci/tenant_manager_control_plane/link_client.py +3 -3
  313. oci/tenant_manager_control_plane/orders_client.py +2 -2
  314. oci/tenant_manager_control_plane/organization_client.py +10 -10
  315. oci/tenant_manager_control_plane/recipient_invitation_client.py +5 -5
  316. oci/tenant_manager_control_plane/sender_invitation_client.py +5 -5
  317. oci/tenant_manager_control_plane/subscription_client.py +11 -11
  318. oci/tenant_manager_control_plane/work_request_client.py +4 -4
  319. oci/threat_intelligence/threatintel_client.py +5 -5
  320. oci/usage/resources_client.py +2 -2
  321. oci/usage/rewards_client.py +6 -6
  322. oci/usage/usagelimits_client.py +1 -1
  323. oci/usage_api/usageapi_client.py +33 -33
  324. oci/vault/vaults_client.py +13 -13
  325. oci/vbs_inst/vbs_instance_client.py +10 -10
  326. oci/version.py +1 -1
  327. oci/visual_builder/vb_instance_client.py +13 -13
  328. oci/vn_monitoring/vn_monitoring_client.py +12 -12
  329. oci/vulnerability_scanning/vulnerability_scanning_client.py +58 -58
  330. oci/waa/waa_client.py +13 -13
  331. oci/waa/work_request_client.py +4 -4
  332. oci/waas/redirect_client.py +6 -6
  333. oci/waas/waas_client.py +66 -66
  334. oci/waf/waf_client.py +24 -24
  335. oci/work_requests/work_request_client.py +4 -4
  336. oci/zpr/zpr_client.py +15 -15
  337. {oci-2.138.1.dist-info → oci-2.139.0.dist-info}/METADATA +1 -1
  338. {oci-2.138.1.dist-info → oci-2.139.0.dist-info}/RECORD +342 -338
  339. {oci-2.138.1.dist-info → oci-2.139.0.dist-info}/THIRD_PARTY_LICENSES.txt +1 -1
  340. {oci-2.138.1.dist-info → oci-2.139.0.dist-info}/LICENSE.txt +0 -0
  341. {oci-2.138.1.dist-info → oci-2.139.0.dist-info}/WHEEL +0 -0
  342. {oci-2.138.1.dist-info → oci-2.139.0.dist-info}/top_level.txt +0 -0
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  # Modified Work: Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved.
3
3
  # This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
4
- # Copyright 2008-2016 Andrey Petrov and contributors
4
+ # Copyright (c) 2008-2020 Andrey Petrov and contributors
5
5
 
6
6
  """
7
7
  Python HTTP library with thread-safe connection pooling, file post support, user friendly, and more
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  # Modified Work: Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved.
3
3
  # This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
4
- # Copyright 2008-2016 Andrey Petrov and contributors
4
+ # Copyright (c) 2008-2020 Andrey Petrov and contributors
5
5
 
6
6
  from __future__ import absolute_import
7
7
 
@@ -273,6 +273,24 @@ class HTTPHeaderDict(MutableMapping):
273
273
  else:
274
274
  return vals[1:]
275
275
 
276
+ def _prepare_for_method_change(self):
277
+ """
278
+ Remove content-specific header fields before changing the request
279
+ method to GET or HEAD according to RFC 9110, Section 15.4.
280
+ """
281
+ content_specific_headers = [
282
+ "Content-Encoding",
283
+ "Content-Language",
284
+ "Content-Location",
285
+ "Content-Type",
286
+ "Content-Length",
287
+ "Digest",
288
+ "Last-Modified",
289
+ ]
290
+ for header in content_specific_headers:
291
+ self.discard(header)
292
+ return self
293
+
276
294
  # Backwards compatibility for httplib
277
295
  getheaders = getlist
278
296
  getallmatchingheaders = getlist
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  # Modified Work: Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved.
3
3
  # This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
4
- # Copyright 2008-2016 Andrey Petrov and contributors
4
+ # Copyright (c) 2008-2020 Andrey Petrov and contributors
5
5
 
6
6
  # This file is protected via CODEOWNERS
7
- __version__ = "1.26.9"
7
+ __version__ = "1.26.20"
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  # Modified Work: Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved.
3
3
  # This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
4
- # Copyright 2008-2016 Andrey Petrov and contributors
4
+ # Copyright (c) 2008-2020 Andrey Petrov and contributors
5
5
 
6
6
  from __future__ import absolute_import
7
7
 
@@ -73,7 +73,7 @@ port_by_scheme = {"http": 80, "https": 443}
73
73
 
74
74
  # When it comes time to update this value as a part of regular maintenance
75
75
  # (ie test_recent_date is failing) update it to ~6 months before the current date.
76
- RECENT_DATE = datetime.date(2020, 7, 1)
76
+ RECENT_DATE = datetime.date(2024, 1, 1)
77
77
 
78
78
  _CONTAINS_CONTROL_CHAR_RE = re.compile(r"[^-!#$%&'*+.^_`|~0-9a-zA-Z]")
79
79
 
@@ -234,6 +234,11 @@ class HTTPConnection(_HTTPConnection, object):
234
234
  )
235
235
 
236
236
  def request(self, method, url, body=None, headers=None):
237
+ # Update the inner socket's timeout value to send the request.
238
+ # This only triggers if the connection is re-used.
239
+ if getattr(self, "sock", None) is not None:
240
+ self.sock.settimeout(self.timeout)
241
+
237
242
  if headers is None:
238
243
  headers = {}
239
244
  else:
@@ -437,7 +442,7 @@ class HTTPSConnection(HTTPConnection):
437
442
  and self.ssl_version is None
438
443
  and hasattr(self.sock, "version")
439
444
  and self.sock.version() in {"TLSv1", "TLSv1.1"}
440
- ):
445
+ ): # Defensive:
441
446
  warnings.warn(
442
447
  "Negotiating TLSv1/TLSv1.1 by default is deprecated "
443
448
  "and will be disabled in urllib3 v2.0.0. Connecting to "
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  # Modified Work: Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved.
3
3
  # This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
4
- # Copyright 2008-2016 Andrey Petrov and contributors
4
+ # Copyright (c) 2008-2020 Andrey Petrov and contributors
5
5
 
6
6
  from __future__ import absolute_import
7
7
 
@@ -14,6 +14,7 @@ import warnings
14
14
  from socket import error as SocketError
15
15
  from socket import timeout as SocketTimeout
16
16
 
17
+ from ._collections import HTTPHeaderDict
17
18
  from .connection import (
18
19
  BaseSSLError,
19
20
  BrokenPipeError,
@@ -55,6 +56,13 @@ from .util.url import Url, _encode_target
55
56
  from .util.url import _normalize_host as normalize_host
56
57
  from .util.url import get_host, parse_url
57
58
 
59
+ try: # Platform-specific: Python 3
60
+ import weakref
61
+
62
+ weakref_finalize = weakref.finalize
63
+ except AttributeError: # Platform-specific: Python 2
64
+ from .packages.backports.weakref_finalize import weakref_finalize
65
+
58
66
  xrange = six.moves.xrange
59
67
 
60
68
  log = logging.getLogger(__name__)
@@ -225,6 +233,16 @@ class HTTPConnectionPool(ConnectionPool, RequestMethods):
225
233
  self.conn_kw["proxy"] = self.proxy
226
234
  self.conn_kw["proxy_config"] = self.proxy_config
227
235
 
236
+ # Do not pass 'self' as callback to 'finalize'.
237
+ # Then the 'finalize' would keep an endless living (leak) to self.
238
+ # By just passing a reference to the pool allows the garbage collector
239
+ # to free self if nobody else has a reference to it.
240
+ pool = self.pool
241
+
242
+ # Close all the HTTPConnections in the pool before the
243
+ # HTTPConnectionPool object is garbage collected.
244
+ weakref_finalize(self, _close_pool_connections, pool)
245
+
228
246
  def _new_conn(self):
229
247
  """
230
248
  Return a fresh :class:`HTTPConnection`.
@@ -384,7 +402,7 @@ class HTTPConnectionPool(ConnectionPool, RequestMethods):
384
402
 
385
403
  timeout_obj = self._get_timeout(timeout)
386
404
  timeout_obj.start_connect()
387
- conn.timeout = timeout_obj.connect_timeout
405
+ conn.timeout = Timeout.resolve_default_timeout(timeout_obj.connect_timeout)
388
406
 
389
407
  # Trigger any extra validation we need to do.
390
408
  try:
@@ -410,12 +428,13 @@ class HTTPConnectionPool(ConnectionPool, RequestMethods):
410
428
  pass
411
429
  except IOError as e:
412
430
  # Python 2 and macOS/Linux
413
- # EPIPE and ESHUTDOWN are BrokenPipeError on Python 2, and EPROTOTYPE is needed on macOS
431
+ # EPIPE and ESHUTDOWN are BrokenPipeError on Python 2, and EPROTOTYPE/ECONNRESET are needed on macOS
414
432
  # https://erickt.github.io/blog/2014/11/19/adventures-in-debugging-a-potential-osx-kernel-bug/
415
433
  if e.errno not in {
416
434
  errno.EPIPE,
417
435
  errno.ESHUTDOWN,
418
436
  errno.EPROTOTYPE,
437
+ errno.ECONNRESET,
419
438
  }:
420
439
  raise
421
440
 
@@ -494,14 +513,8 @@ class HTTPConnectionPool(ConnectionPool, RequestMethods):
494
513
  # Disable access to the pool
495
514
  old_pool, self.pool = self.pool, None
496
515
 
497
- try:
498
- while True:
499
- conn = old_pool.get(block=False)
500
- if conn:
501
- conn.close()
502
-
503
- except queue.Empty:
504
- pass # Done.
516
+ # Close all the HTTPConnections in the pool.
517
+ _close_pool_connections(old_pool)
505
518
 
506
519
  def is_same_host(self, url):
507
520
  """
@@ -761,7 +774,9 @@ class HTTPConnectionPool(ConnectionPool, RequestMethods):
761
774
  # so we try to cover our bases here!
762
775
  message = " ".join(re.split("[^a-z]", str(ssl_error).lower()))
763
776
  return (
764
- "wrong version number" in message or "unknown protocol" in message
777
+ "wrong version number" in message
778
+ or "unknown protocol" in message
779
+ or "record layer failure" in message
765
780
  )
766
781
 
767
782
  # Try to detect a common user error with proxies which is to
@@ -772,6 +787,8 @@ class HTTPConnectionPool(ConnectionPool, RequestMethods):
772
787
  isinstance(e, BaseSSLError)
773
788
  and self.proxy
774
789
  and _is_ssl_error_message_from_http_proxy(e)
790
+ and conn.proxy
791
+ and conn.proxy.scheme == "https"
775
792
  ):
776
793
  e = ProxyError(
777
794
  "Your proxy appears to only use HTTP and not HTTPS, "
@@ -835,7 +852,11 @@ class HTTPConnectionPool(ConnectionPool, RequestMethods):
835
852
  redirect_location = redirect and response.get_redirect_location()
836
853
  if redirect_location:
837
854
  if response.status == 303:
855
+ # Change the method according to RFC 9110, Section 15.4.4.
838
856
  method = "GET"
857
+ # And lose the body not to transfer anything sensitive.
858
+ body = None
859
+ headers = HTTPHeaderDict(headers)._prepare_for_method_change()
839
860
 
840
861
  try:
841
862
  retries = retries.increment(method, url, response=response, _pool=self)
@@ -865,7 +886,7 @@ class HTTPConnectionPool(ConnectionPool, RequestMethods):
865
886
  )
866
887
 
867
888
  # Check if we should retry the HTTP response.
868
- has_retry_after = bool(response.getheader("Retry-After"))
889
+ has_retry_after = bool(response.headers.get("Retry-After"))
869
890
  if retries.is_retry(method, response.status, has_retry_after):
870
891
  try:
871
892
  retries = retries.increment(method, url, response=response, _pool=self)
@@ -1111,3 +1132,14 @@ def _normalize_host(host, scheme):
1111
1132
  if host.startswith("[") and host.endswith("]"):
1112
1133
  host = host[1:-1]
1113
1134
  return host
1135
+
1136
+
1137
+ def _close_pool_connections(pool):
1138
+ """Drains a queue of connections and closes each one."""
1139
+ try:
1140
+ while True:
1141
+ conn = pool.get(block=False)
1142
+ if conn:
1143
+ conn.close()
1144
+ except queue.Empty:
1145
+ pass # Done.
@@ -1,5 +1,5 @@
1
1
  # coding: utf-8
2
2
  # Modified Work: Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved.
3
3
  # This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
4
- # Copyright 2008-2016 Andrey Petrov and contributors
4
+ # Copyright (c) 2008-2020 Andrey Petrov and contributors
5
5
 
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  # Modified Work: Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved.
3
3
  # This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
4
- # Copyright 2008-2016 Andrey Petrov and contributors
4
+ # Copyright (c) 2008-2020 Andrey Petrov and contributors
5
5
 
6
6
  """
7
7
  This module provides means to detect the App Engine environment.
@@ -1,5 +1,5 @@
1
1
  # coding: utf-8
2
2
  # Modified Work: Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved.
3
3
  # This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
4
- # Copyright 2008-2016 Andrey Petrov and contributors
4
+ # Copyright (c) 2008-2020 Andrey Petrov and contributors
5
5
 
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  # Modified Work: Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved.
3
3
  # This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
4
- # Copyright 2008-2016 Andrey Petrov and contributors
4
+ # Copyright (c) 2008-2020 Andrey Petrov and contributors
5
5
 
6
6
  """
7
7
  This module uses ctypes to bind a whole bunch of functions and constants from
@@ -53,7 +53,7 @@ from ctypes import (
53
53
  )
54
54
  from ctypes.util import find_library
55
55
 
56
- from oci._vendor.urllib3.packages.six import raise_from
56
+ from ...packages.six import raise_from
57
57
 
58
58
  if platform.system() != "Darwin":
59
59
  raise ImportError("Only macOS is supported")
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  # Modified Work: Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved.
3
3
  # This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
4
- # Copyright 2008-2016 Andrey Petrov and contributors
4
+ # Copyright (c) 2008-2020 Andrey Petrov and contributors
5
5
 
6
6
  """
7
7
  Low-level helpers for the SecureTransport bindings.
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  # Modified Work: Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved.
3
3
  # This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
4
- # Copyright 2008-2016 Andrey Petrov and contributors
4
+ # Copyright (c) 2008-2020 Andrey Petrov and contributors
5
5
 
6
6
  """
7
7
  This module provides a pool manager that uses Google App Engine's
@@ -229,7 +229,7 @@ class AppEngineManager(RequestMethods):
229
229
  )
230
230
 
231
231
  # Check if we should retry the HTTP response.
232
- has_retry_after = bool(http_response.getheader("Retry-After"))
232
+ has_retry_after = bool(http_response.headers.get("Retry-After"))
233
233
  if retries.is_retry(method, http_response.status, has_retry_after):
234
234
  retries = retries.increment(method, url, response=http_response, _pool=self)
235
235
  log.debug("Retry: %s", url)
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  # Modified Work: Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved.
3
3
  # This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
4
- # Copyright 2008-2016 Andrey Petrov and contributors
4
+ # Copyright (c) 2008-2020 Andrey Petrov and contributors
5
5
 
6
6
  """
7
7
  NTLM authenticating pool, contributed by erikcederstran
@@ -74,7 +74,7 @@ class NTLMConnectionPool(HTTPSConnectionPool):
74
74
  log.debug("Request headers: %s", headers)
75
75
  conn.request("GET", self.authurl, None, headers)
76
76
  res = conn.getresponse()
77
- reshdr = dict(res.getheaders())
77
+ reshdr = dict(res.headers)
78
78
  log.debug("Response status: %s %s", res.status, res.reason)
79
79
  log.debug("Response headers: %s", reshdr)
80
80
  log.debug("Response data: %s [...]", res.read(100))
@@ -106,7 +106,7 @@ class NTLMConnectionPool(HTTPSConnectionPool):
106
106
  conn.request("GET", self.authurl, None, headers)
107
107
  res = conn.getresponse()
108
108
  log.debug("Response status: %s %s", res.status, res.reason)
109
- log.debug("Response headers: %s", dict(res.getheaders()))
109
+ log.debug("Response headers: %s", dict(res.headers))
110
110
  log.debug("Response data: %s [...]", res.read()[:100])
111
111
  if res.status != 200:
112
112
  if res.status == 401:
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  # Modified Work: Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved.
3
3
  # This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
4
- # Copyright 2008-2016 Andrey Petrov and contributors
4
+ # Copyright (c) 2008-2020 Andrey Petrov and contributors
5
5
 
6
6
  """
7
7
  TLS with SNI_-support for Python 2. Follow these instructions if you would
@@ -52,10 +52,10 @@ compression in Python 2 (see `CRIME attack`_).
52
52
  """
53
53
  from __future__ import absolute_import
54
54
 
55
+ import OpenSSL.crypto
55
56
  import OpenSSL.SSL
56
57
  from cryptography import x509
57
58
  from cryptography.hazmat.backends.openssl import backend as openssl_backend
58
- from cryptography.hazmat.backends.openssl.x509 import _Certificate
59
59
 
60
60
  try:
61
61
  from cryptography.x509 import UnsupportedExtension
@@ -78,10 +78,19 @@ except ImportError: # Platform-specific: Python 3
78
78
  import logging
79
79
  import ssl
80
80
  import sys
81
+ import warnings
81
82
 
82
83
  from .. import util
83
84
  from ..packages import six
84
- from oci._vendor.urllib3.util.ssl_ import PROTOCOL_TLS_CLIENT
85
+ from ..util.ssl_ import PROTOCOL_TLS_CLIENT
86
+
87
+ warnings.warn(
88
+ "'urllib3.contrib.pyopenssl' module is deprecated and will be removed "
89
+ "in a future release of urllib3 2.x. Read more in this issue: "
90
+ "https://github.com/urllib3/urllib3/issues/2680",
91
+ category=DeprecationWarning,
92
+ stacklevel=2,
93
+ )
85
94
 
86
95
  __all__ = ["inject_into_urllib3", "extract_from_urllib3"]
87
96
 
@@ -224,9 +233,8 @@ def get_subj_alt_name(peer_cert):
224
233
  if hasattr(peer_cert, "to_cryptography"):
225
234
  cert = peer_cert.to_cryptography()
226
235
  else:
227
- # This is technically using private APIs, but should work across all
228
- # relevant versions before PyOpenSSL got a proper API for this.
229
- cert = _Certificate(openssl_backend, peer_cert._x509)
236
+ der = OpenSSL.crypto.dump_certificate(OpenSSL.crypto.FILETYPE_ASN1, peer_cert)
237
+ cert = x509.load_der_x509_certificate(der, openssl_backend)
230
238
 
231
239
  # We want to find the SAN extension. Ask Cryptography to locate it (it's
232
240
  # faster than looping in Python)
@@ -411,7 +419,6 @@ if _fileobject: # Platform-specific: Python 2
411
419
  self._makefile_refs += 1
412
420
  return _fileobject(self, mode, bufsize, close=True)
413
421
 
414
-
415
422
  else: # Platform-specific: Python 3
416
423
  makefile = backport_makefile
417
424
 
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  # Modified Work: Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved.
3
3
  # This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
4
- # Copyright 2008-2016 Andrey Petrov and contributors
4
+ # Copyright (c) 2008-2020 Andrey Petrov and contributors
5
5
 
6
6
  """
7
7
  SecureTranport support for urllib3 via ctypes.
@@ -69,9 +69,8 @@ import struct
69
69
  import threading
70
70
  import weakref
71
71
 
72
- import six
73
-
74
72
  from .. import util
73
+ from ..packages import six
75
74
  from ..util.ssl_ import PROTOCOL_TLS_CLIENT
76
75
  from ._securetransport.bindings import CoreFoundation, Security, SecurityConst
77
76
  from ._securetransport.low_level import (
@@ -775,7 +774,6 @@ if _fileobject: # Platform-specific: Python 2
775
774
  self._makefile_refs += 1
776
775
  return _fileobject(self, mode, bufsize, close=True)
777
776
 
778
-
779
777
  else: # Platform-specific: Python 3
780
778
 
781
779
  def makefile(self, mode="r", buffering=None, *args, **kwargs):
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  # Modified Work: Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved.
3
3
  # This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
4
- # Copyright 2008-2016 Andrey Petrov and contributors
4
+ # Copyright (c) 2008-2020 Andrey Petrov and contributors
5
5
 
6
6
  # -*- coding: utf-8 -*-
7
7
  """
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  # Modified Work: Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved.
3
3
  # This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
4
- # Copyright 2008-2016 Andrey Petrov and contributors
4
+ # Copyright (c) 2008-2020 Andrey Petrov and contributors
5
5
 
6
6
  from __future__ import absolute_import
7
7
 
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  # Modified Work: Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved.
3
3
  # This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
4
- # Copyright 2008-2016 Andrey Petrov and contributors
4
+ # Copyright (c) 2008-2020 Andrey Petrov and contributors
5
5
 
6
6
  from __future__ import absolute_import
7
7
 
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  # Modified Work: Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved.
3
3
  # This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
4
- # Copyright 2008-2016 Andrey Petrov and contributors
4
+ # Copyright (c) 2008-2020 Andrey Petrov and contributors
5
5
 
6
6
  from __future__ import absolute_import
7
7
 
@@ -1,6 +1,6 @@
1
1
  # coding: utf-8
2
2
  # Modified Work: Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved.
3
3
  # This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
4
- # Copyright 2008-2016 Andrey Petrov and contributors
4
+ # Copyright (c) 2008-2020 Andrey Petrov and contributors
5
5
 
6
- # Copyright 2008-2016 Andrey Petrov and contributors
6
+ # Copyright 2008-2020 Andrey Petrov and contributors
@@ -1,5 +1,5 @@
1
1
  # coding: utf-8
2
2
  # Modified Work: Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved.
3
3
  # This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
4
- # Copyright 2008-2016 Andrey Petrov and contributors
4
+ # Copyright (c) 2008-2020 Andrey Petrov and contributors
5
5
 
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  # Modified Work: Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved.
3
3
  # This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
4
- # Copyright 2008-2016 Andrey Petrov and contributors
4
+ # Copyright (c) 2008-2020 Andrey Petrov and contributors
5
5
 
6
6
  # -*- coding: utf-8 -*-
7
7
  """
@@ -0,0 +1,160 @@
1
+ # coding: utf-8
2
+ # Modified Work: Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved.
3
+ # This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
4
+ # Copyright (c) 2008-2020 Andrey Petrov and contributors
5
+
6
+ # -*- coding: utf-8 -*-
7
+ """
8
+ backports.weakref_finalize
9
+ ~~~~~~~~~~~~~~~~~~
10
+
11
+ Backports the Python 3 ``weakref.finalize`` method.
12
+ """
13
+ from __future__ import absolute_import
14
+
15
+ import itertools
16
+ import sys
17
+ from weakref import ref
18
+
19
+ __all__ = ["weakref_finalize"]
20
+
21
+
22
+ class weakref_finalize(object):
23
+ """Class for finalization of weakrefable objects
24
+ finalize(obj, func, *args, **kwargs) returns a callable finalizer
25
+ object which will be called when obj is garbage collected. The
26
+ first time the finalizer is called it evaluates func(*arg, **kwargs)
27
+ and returns the result. After this the finalizer is dead, and
28
+ calling it just returns None.
29
+ When the program exits any remaining finalizers for which the
30
+ atexit attribute is true will be run in reverse order of creation.
31
+ By default atexit is true.
32
+ """
33
+
34
+ # Finalizer objects don't have any state of their own. They are
35
+ # just used as keys to lookup _Info objects in the registry. This
36
+ # ensures that they cannot be part of a ref-cycle.
37
+
38
+ __slots__ = ()
39
+ _registry = {}
40
+ _shutdown = False
41
+ _index_iter = itertools.count()
42
+ _dirty = False
43
+ _registered_with_atexit = False
44
+
45
+ class _Info(object):
46
+ __slots__ = ("weakref", "func", "args", "kwargs", "atexit", "index")
47
+
48
+ def __init__(self, obj, func, *args, **kwargs):
49
+ if not self._registered_with_atexit:
50
+ # We may register the exit function more than once because
51
+ # of a thread race, but that is harmless
52
+ import atexit
53
+
54
+ atexit.register(self._exitfunc)
55
+ weakref_finalize._registered_with_atexit = True
56
+ info = self._Info()
57
+ info.weakref = ref(obj, self)
58
+ info.func = func
59
+ info.args = args
60
+ info.kwargs = kwargs or None
61
+ info.atexit = True
62
+ info.index = next(self._index_iter)
63
+ self._registry[self] = info
64
+ weakref_finalize._dirty = True
65
+
66
+ def __call__(self, _=None):
67
+ """If alive then mark as dead and return func(*args, **kwargs);
68
+ otherwise return None"""
69
+ info = self._registry.pop(self, None)
70
+ if info and not self._shutdown:
71
+ return info.func(*info.args, **(info.kwargs or {}))
72
+
73
+ def detach(self):
74
+ """If alive then mark as dead and return (obj, func, args, kwargs);
75
+ otherwise return None"""
76
+ info = self._registry.get(self)
77
+ obj = info and info.weakref()
78
+ if obj is not None and self._registry.pop(self, None):
79
+ return (obj, info.func, info.args, info.kwargs or {})
80
+
81
+ def peek(self):
82
+ """If alive then return (obj, func, args, kwargs);
83
+ otherwise return None"""
84
+ info = self._registry.get(self)
85
+ obj = info and info.weakref()
86
+ if obj is not None:
87
+ return (obj, info.func, info.args, info.kwargs or {})
88
+
89
+ @property
90
+ def alive(self):
91
+ """Whether finalizer is alive"""
92
+ return self in self._registry
93
+
94
+ @property
95
+ def atexit(self):
96
+ """Whether finalizer should be called at exit"""
97
+ info = self._registry.get(self)
98
+ return bool(info) and info.atexit
99
+
100
+ @atexit.setter
101
+ def atexit(self, value):
102
+ info = self._registry.get(self)
103
+ if info:
104
+ info.atexit = bool(value)
105
+
106
+ def __repr__(self):
107
+ info = self._registry.get(self)
108
+ obj = info and info.weakref()
109
+ if obj is None:
110
+ return "<%s object at %#x; dead>" % (type(self).__name__, id(self))
111
+ else:
112
+ return "<%s object at %#x; for %r at %#x>" % (
113
+ type(self).__name__,
114
+ id(self),
115
+ type(obj).__name__,
116
+ id(obj),
117
+ )
118
+
119
+ @classmethod
120
+ def _select_for_exit(cls):
121
+ # Return live finalizers marked for exit, oldest first
122
+ L = [(f, i) for (f, i) in cls._registry.items() if i.atexit]
123
+ L.sort(key=lambda item: item[1].index)
124
+ return [f for (f, i) in L]
125
+
126
+ @classmethod
127
+ def _exitfunc(cls):
128
+ # At shutdown invoke finalizers for which atexit is true.
129
+ # This is called once all other non-daemonic threads have been
130
+ # joined.
131
+ reenable_gc = False
132
+ try:
133
+ if cls._registry:
134
+ import gc
135
+
136
+ if gc.isenabled():
137
+ reenable_gc = True
138
+ gc.disable()
139
+ pending = None
140
+ while True:
141
+ if pending is None or weakref_finalize._dirty:
142
+ pending = cls._select_for_exit()
143
+ weakref_finalize._dirty = False
144
+ if not pending:
145
+ break
146
+ f = pending.pop()
147
+ try:
148
+ # gc is disabled, so (assuming no daemonic
149
+ # threads) the following is the only line in
150
+ # this function which might trigger creation
151
+ # of a new finalizer
152
+ f()
153
+ except Exception:
154
+ sys.excepthook(*sys.exc_info())
155
+ assert f not in cls._registry
156
+ finally:
157
+ # prevent any more finalizers from executing during shutdown
158
+ weakref_finalize._shutdown = True
159
+ if reenable_gc:
160
+ gc.enable()