7 """ Gnome via python-gconf """
8 from gconf
import client_get_default
9 gconf_client
= client_get_default()
10 mode
= gconf_client
.get_string("/system/proxy/mode")
13 host
= gconf_client
.get_string("/system/proxy/socks_host")
14 port
= gconf_client
.get_int("/system/proxy/socks_port")
18 """ OS X 10.5 and up via PyObjC """
19 from SystemConfiguration
import SCDynamicStoreCopyProxies
20 osx_proxy
= SCDynamicStoreCopyProxies(None)
21 if osx_proxy
.get("SOCKSEnable"):
22 host
= osx_proxy
.get("SOCKSProxy")
23 port
= int(osx_proxy
.get("SOCKSPort"))
28 """ KDE via command line, why no python bindings for KDE proxy settings? """
29 if os
.environ
.get("KDE_FULL_SESSION") != "true":
42 stdout
=subprocess
.PIPE
,
44 host
, port
= p
.stdout
.readline()[:-1].split(":")
50 """ fallback to environment variables """
51 socks_environ
= os
.environ
.get("SOCKS_SERVER")
54 host
, port
= socks_environ
59 def configure_socks(host
, port
):
60 """ hijack socket.socket using SocksiPy """
64 logging
.error("Failed to use configured SOCKS proxy: %s:%s", host
, port
)
65 logging
.error("Try installing SocksiPy: http://socksipy.sf.net")
68 socket
.socket
= socks
.socksocket
69 socks
.setdefaultproxy(socks
.PROXY_TYPE_SOCKS5
, host
, port
)
80 for func
in functions
:
81 host
, port
= None, None
84 except Exception as e
:
86 if host
is not None and port
is not None:
87 return configure_socks(host
, port
)