about summary refs log tree commit diff stats
path: root/crates/yt_dlp/src/package_hacks/urllib3.rs
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-06-28 15:56:44 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-06-28 15:58:30 +0200
commit8c6565295986b704f36a9174d05deacc6925b7e4 (patch)
treeffc9348520ff59a642981d41b8897b57cf1a3811 /crates/yt_dlp/src/package_hacks/urllib3.rs
parentbuild({nix,flake}): Add missing buildInputs (diff)
downloadyt-8c6565295986b704f36a9174d05deacc6925b7e4.zip
fix(yt_dlp): Polyfill missing rustpython features used in urllib3
Otherwise, anything that depends on urllib3 just fails to initialize.
Diffstat (limited to 'crates/yt_dlp/src/package_hacks/urllib3.rs')
-rw-r--r--crates/yt_dlp/src/package_hacks/urllib3.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/crates/yt_dlp/src/package_hacks/urllib3.rs b/crates/yt_dlp/src/package_hacks/urllib3.rs
new file mode 100644
index 0000000..68a94aa
--- /dev/null
+++ b/crates/yt_dlp/src/package_hacks/urllib3.rs
@@ -0,0 +1,25 @@
+use rustpython::vm::{PyResult, VirtualMachine};
+
+// NOTE(@bpeetz): Remove this, once rust-python supports these features. <2025-06-27>
+pub(crate) fn apply_hacks(vm: &VirtualMachine) -> PyResult<()> {
+    {
+        // Urllib3 tries to import this value, regardless if it is set.
+        let ssl_module = vm.import("ssl", 0)?;
+        ssl_module.set_attr("VERIFY_X509_STRICT", vm.ctx.new_int(0x20), vm)?;
+    }
+
+    {
+        // Urllib3 tries to set the SSLContext.verify_flags value, regardless if it exists or not.
+        // So we need to provide a polyfill.
+
+        let scope = vm.new_scope_with_builtins();
+
+        vm.run_code_string(
+            scope,
+            include_str!("urllib3_polyfill.py"),
+            "<embedded urllib3 polyfill workaround code>".to_owned(),
+        )?;
+    }
+
+    Ok(())
+}