1 # vim:ts=4:sts=4:sw=4:noet
8 """ Gnome via python-gconf """
9 from gconf
import client_get_default
10 gconf_client
= client_get_default()
11 mode
= gconf_client
.get_string("/system/proxy/mode")
14 host
= gconf_client
.get_string("/system/proxy/socks_host")
15 port
= gconf_client
.get_int("/system/proxy/socks_port")
19 """ OS X 10.5 and up via PyObjC """
20 from SystemConfiguration
import SCDynamicStoreCopyProxies
21 osx_proxy
= SCDynamicStoreCopyProxies(None)
22 if osx_proxy
.get("SOCKSEnable"):
23 host
= osx_proxy
.get("SOCKSProxy")
24 port
= int(osx_proxy
.get("SOCKSPort"))
29 """ KDE via command line, why no python bindings for KDE proxy settings? """
30 if os
.environ
.get("KDE_FULL_SESSION") != "true":
43 stdout
=subprocess
.PIPE
,
45 host
, port
= p
.stdout
.readline()[:-1].split(":")
51 """ fallback to environment variables """
52 socks_environ
= os
.environ
.get("SOCKS_SERVER")
55 host
, port
= socks_environ
60 def configure_socks(host
, port
):
61 """ hijack socket.socket using SocksiPy """
65 print >>sys
.stderr
, "Failed to use configured SOCKS proxy:", host
, port
66 print >>sys
.stderr
, "Try installing SocksiPy: http://socksipy.sf.net"
69 socket
.socket
= socks
.socksocket
70 socks
.setdefaultproxy(socks
.PROXY_TYPE_SOCKS5
, host
, port
)
81 for func
in functions
:
82 host
, port
= None, None
87 if host
is not None and port
is not None:
88 return configure_socks(host
, port
)