make proxy an optional parameter
authorthomasv <thomasv@gitorious>
Mon, 1 Oct 2012 16:14:50 +0000 (18:14 +0200)
committerthomasv <thomasv@gitorious>
Mon, 1 Oct 2012 16:14:50 +0000 (18:14 +0200)
electrum
lib/interface.py

index 4b379fb..4e42ebb 100755 (executable)
--- a/electrum
+++ b/electrum
@@ -116,11 +116,11 @@ if __name__ == '__main__':
     parser.add_option("-s", "--fromaddr", dest="from_addr", default=None, help="set source address for payto/mktx. if it isn't in the wallet, it will ask for the private key unless supplied in the format public_key:private_key. It's not saved in the wallet.")
     parser.add_option("-c", "--changeaddr", dest="change_addr", default=None, help="set the change address for payto/mktx. default is a spare address, or the source address if it's not in the wallet")
     parser.add_option("-r", "--remote", dest="remote_url", default=None, help="URL of a remote wallet")
-    parser.add_option("-p", "--proxy", dest="proxy", default=simple_config.config["proxy"], help="set proxy [type:]host[:port], where type is socks4,socks5 or http")
+    parser.add_option("-p", "--proxy", dest="proxy", default=None, help="set proxy [type:]host[:port], where type is socks4,socks5 or http")
     options, args = parser.parse_args()
 
-    if type(options.proxy) == type(''):
-               options.proxy = parse_proxy_options(options.proxy)
+    if options.proxy:
+        options.proxy = parse_proxy_options(options.proxy)
 
     wallet = Wallet()
     wallet.set_path(options.wallet_path)
index 1097831..0d7fbbc 100644 (file)
@@ -28,7 +28,7 @@ DEFAULT_SERVERS = [ 'ecdsa.org:50001:t',
                     'electrum.novit.ro:50001:t', 
                     'electrum.bytesized-hosting.com:50001:t']  # list of default servers
 
-proxy_modes = ['none', 'socks4', 'socks5', 'http' ]
+proxy_modes = ['socks4', 'socks5', 'http']
 
 def replace_keys(obj, old_key, new_key):
     if isinstance(obj, dict):
@@ -65,7 +65,7 @@ def parse_proxy_options(s):
     return proxy
 
 class Interface(threading.Thread):
-    def __init__(self, host, port, proxy):
+    def __init__(self, host, port, proxy=None):
         threading.Thread.__init__(self)
         self.daemon = True
         self.host = host
@@ -136,7 +136,7 @@ class Interface(threading.Thread):
 class PollingInterface(Interface):
     """ non-persistent connection. synchronous calls"""
 
-    def __init__(self, host, port, proxy):
+    def __init__(self, host, port, proxy=None):
         Interface.__init__(self, host, port, proxy)
         self.session_id = None
 
@@ -188,7 +188,7 @@ class HttpStratumInterface(PollingInterface):
     def send(self, messages):
         import urllib2, json, time, cookielib
         
-        if self.proxy["mode"] != "none":
+        if self.proxy:
             import socks
             socks.setdefaultproxy(proxy_modes.index(self.proxy["mode"]), self.proxy["host"], int(self.proxy["port"]) )
             socks.wrapmodule(urllib2)
@@ -250,12 +250,12 @@ class HttpStratumInterface(PollingInterface):
 class TcpStratumInterface(Interface):
     """json-rpc over persistent TCP connection, asynchronous"""
 
-    def __init__(self, host, port, proxy):
+    def __init__(self, host, port, proxy=None):
         Interface.__init__(self, host, port, proxy)
 
     def init_socket(self):
         global proxy_modes
-        if self.proxy["mode"] == "none":
+        if self.proxy is None:
             self.s = socket.socket( socket.AF_INET, socket.SOCK_STREAM )
         else:
             import socks