(vm: &VirtualMachine)
| 68 | |
| 69 | #[pyfunction] |
| 70 | fn _get_proxies(vm: &VirtualMachine) -> PyResult<Option<PyDictRef>> { |
| 71 | let Some(proxy_dict) = proxy_dict() else { |
| 72 | return Ok(None); |
| 73 | }; |
| 74 | |
| 75 | let result = vm.ctx.new_dict(); |
| 76 | |
| 77 | let set_proxy = |result: &Py<PyDict>, |
| 78 | proto: &str, |
| 79 | enabled_key: CFStringRef, |
| 80 | host_key: CFStringRef, |
| 81 | port_key: CFStringRef| |
| 82 | -> PyResult<()> { |
| 83 | let enabled = 0 |
| 84 | != proxy_dict |
| 85 | .find(enabled_key) |
| 86 | .and_then(|v| v.downcast::<CFNumber>()) |
| 87 | .and_then(|v| v.to_i32()) |
| 88 | .unwrap_or(0); |
| 89 | if enabled |
| 90 | && let Some(host) = proxy_dict |
| 91 | .find(host_key) |
| 92 | .and_then(|v| v.downcast::<CFString>()) |
| 93 | { |
| 94 | let h = alloc::borrow::Cow::<str>::from(&host); |
| 95 | let v = if let Some(port) = proxy_dict |
| 96 | .find(port_key) |
| 97 | .and_then(|v| v.downcast::<CFNumber>()) |
| 98 | .and_then(|v| v.to_i32()) |
| 99 | { |
| 100 | format!("http://{h}:{port}") |
| 101 | } else { |
| 102 | format!("http://{h}") |
| 103 | }; |
| 104 | result.set_item(proto, vm.new_pyobj(v), vm)?; |
| 105 | } |
| 106 | Ok(()) |
| 107 | }; |
| 108 | |
| 109 | unsafe { |
| 110 | set_proxy( |
| 111 | &result, |
| 112 | "http", |
| 113 | kSCPropNetProxiesHTTPEnable, |
| 114 | kSCPropNetProxiesHTTPProxy, |
| 115 | kSCPropNetProxiesHTTPPort, |
| 116 | )?; |
| 117 | set_proxy( |
| 118 | &result, |
| 119 | "https", |
| 120 | kSCPropNetProxiesHTTPSEnable, |
| 121 | kSCPropNetProxiesHTTPSProxy, |
| 122 | kSCPropNetProxiesHTTPSPort, |
| 123 | )?; |
| 124 | set_proxy( |
| 125 | &result, |
| 126 | "ftp", |
| 127 | kSCPropNetProxiesFTPEnable, |
no test coverage detected