encapsulate parse_proxy_options
This commit is contained in:
@@ -35,22 +35,6 @@ def pick_random_server():
|
||||
return random.choice( DEFAULT_SERVERS )
|
||||
|
||||
|
||||
def parse_proxy_options(s):
|
||||
if s.lower() == 'none': return None
|
||||
proxy = { "mode":"socks5", "host":"localhost" }
|
||||
args = s.split(':')
|
||||
n = 0
|
||||
if proxy_modes.count(args[n]) == 1:
|
||||
proxy["mode"] = args[n]
|
||||
n += 1
|
||||
if len(args) > n:
|
||||
proxy["host"] = args[n]
|
||||
n += 1
|
||||
if len(args) > n:
|
||||
proxy["port"] = args[n]
|
||||
else:
|
||||
proxy["port"] = "8080" if proxy["mode"] == "http" else "1080"
|
||||
return proxy
|
||||
|
||||
|
||||
|
||||
@@ -324,7 +308,7 @@ class Interface(TcpStratumInterface, HttpStratumInterface):
|
||||
host, port, protocol = s.split(':')
|
||||
port = int(port)
|
||||
|
||||
proxy = config.get('proxy')
|
||||
proxy = self.parse_proxy_options(config.get('proxy','none'))
|
||||
self.server = host + ':%d:%s'%(port, protocol)
|
||||
|
||||
#print protocol, host, port
|
||||
@@ -337,6 +321,25 @@ class Interface(TcpStratumInterface, HttpStratumInterface):
|
||||
TcpStratumInterface.__init__(self, host, port, proxy)
|
||||
|
||||
|
||||
def parse_proxy_options(self, s):
|
||||
if type(s) != type(""): return None
|
||||
if s.lower() == 'none': return None
|
||||
proxy = { "mode":"socks5", "host":"localhost" }
|
||||
args = s.split(':')
|
||||
n = 0
|
||||
if proxy_modes.count(args[n]) == 1:
|
||||
proxy["mode"] = args[n]
|
||||
n += 1
|
||||
if len(args) > n:
|
||||
proxy["host"] = args[n]
|
||||
n += 1
|
||||
if len(args) > n:
|
||||
proxy["port"] = args[n]
|
||||
else:
|
||||
proxy["port"] = "8080" if proxy["mode"] == "http" else "1080"
|
||||
return proxy
|
||||
|
||||
|
||||
def set_server(self, server, proxy=None):
|
||||
# raise an error if the format isnt correct
|
||||
a,b,c = server.split(':')
|
||||
|
||||
@@ -3,7 +3,6 @@ import os, ast
|
||||
from util import user_dir
|
||||
|
||||
from version import ELECTRUM_VERSION, SEED_VERSION
|
||||
from interface import parse_proxy_options
|
||||
|
||||
|
||||
# old stuff.. should be removed at some point
|
||||
@@ -40,7 +39,7 @@ class SimpleConfig:
|
||||
self.options_config = {}
|
||||
|
||||
if options.server: self.options_config['server'] = options.server
|
||||
if options.proxy: self.options_config['proxy'] = parse_proxy_options(options.proxy)
|
||||
if options.proxy: self.options_config['proxy'] = options.proxy
|
||||
if options.gui: self.options_config['gui'] = options.gui
|
||||
|
||||
|
||||
@@ -92,7 +91,6 @@ class SimpleConfig:
|
||||
def read_common_config(self):
|
||||
for name in [ os.path.join( user_dir(), 'electrum.conf') , '/etc/electrum.conf']:
|
||||
if os.path.exists(name):
|
||||
from interface import parse_proxy_options
|
||||
try:
|
||||
import ConfigParser
|
||||
except:
|
||||
@@ -106,7 +104,7 @@ class SimpleConfig:
|
||||
except:
|
||||
pass
|
||||
try:
|
||||
self.common_config['proxy'] = parse_proxy_options(p.get('client','proxy'))
|
||||
self.common_config['proxy'] = p.get('client','proxy')
|
||||
except:
|
||||
pass
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user