6 """ Gnome via python-gconf """
7 from gconf
import client_get_default
8 gconf_client
= client_get_default()
9 mode
= gconf_client
.get_string("/system/proxy/mode")
12 host
= gconf_client
.get_string("/system/proxy/socks_host")
13 port
= gconf_client
.get_int("/system/proxy/socks_port")
17 """ OS X 10.5 and up via PyObjC """
18 from SystemConfiguration
import SCDynamicStoreCopyProxies
19 osx_proxy
= SCDynamicStoreCopyProxies(None)
20 if osx_proxy
.get("SOCKSEnable"):
21 host
= osx_proxy
.get("SOCKSProxy")
22 port
= int(osx_proxy
.get("SOCKSPort"))
27 """ KDE via command line, why no python bindings for KDE proxy settings? """
28 if os
.environ
.get("KDE_FULL_SESSION") != "true":
41 stdout
=subprocess
.PIPE
,
43 host
, port
= p
.stdout
.readline()[:-1].split(":")
49 """ fallback to environment variables """
50 socks_environ
= os
.environ
.get("SOCKS_SERVER")
53 host
, port
= socks_environ
58 def configure_socks(host
, port
):
59 """ hijack socket.socket using SocksiPy """
63 print >>sys
.stderr
, "Failed to use configured SOCKS proxy:", host
, port
64 print >>sys
.stderr
, "Try installing SocksiPy: http://socksipy.sf.net"
67 socket
.socket
= socks
.socksocket
68 socks
.setdefaultproxy(socks
.PROXY_TYPE_SOCKS5
, host
, port
)
79 for func
in functions
:
80 host
, port
= None, None
85 if host
is not None and port
is not None:
86 return configure_socks(host
, port
)