reorder args to match other method

This commit is contained in:
meejah 2018-03-13 17:11:30 -06:00
parent 045af64c2b
commit 767f4ddd5d
4 changed files with 50 additions and 50 deletions

View File

@ -196,11 +196,11 @@ def read_config(basedir, portnumfile, generated_files=[], _valid_config_sections
return _Config(parser, portnumfile, basedir, config_fname)
# XXX consider re-ordering args to match read_config()
def config_from_string(config_str, portnumfile, basedir):
def config_from_string(basedir, portnumfile, config_str):
"""
load configuration from in-memory string
"""
# load configuration from in-memory string
parser = ConfigParser.SafeConfigParser()
parser.readfp(BytesIO(config_str))
return _Config(parser, portnumfile, basedir, '<in-memory>')

View File

@ -580,7 +580,7 @@ class IntroducerClients(unittest.TestCase):
"[client]\n"
"introducer.furl = None\n"
)
config = config_from_string(cfg, "client.port", "basedir")
config = config_from_string("basedir", "client.port", cfg)
with self.assertRaises(ValueError) as ctx:
client.create_introducer_clients(config, main_tub=None)

View File

@ -14,7 +14,7 @@ from ..util.tor_provider import create as create_tor_provider
class FakeNode(Node):
def __init__(self, config_str):
self.config = config_from_string(config_str, "fake.port", "no-basedir")
self.config = config_from_string("fake.port", "no-basedir", config_str)
self._reveal_ip = True
self.services = []
@ -27,9 +27,9 @@ class TCP(unittest.TestCase):
def test_default(self):
config = config_from_string(
BASECONFIG,
"fake.port",
"no-basedir",
BASECONFIG,
)
_, foolscap_handlers = create_connection_handlers(None, config, mock.Mock(), mock.Mock())
self.assertIsInstance(
@ -42,9 +42,9 @@ class Tor(unittest.TestCase):
def test_disabled(self):
config = config_from_string(
BASECONFIG + "[tor]\nenabled = false\n",
"fake.port",
"no-basedir",
BASECONFIG + "[tor]\nenabled = false\n",
)
tor_provider = create_tor_provider(reactor, config)
h = tor_provider.get_tor_handler()
@ -53,7 +53,7 @@ class Tor(unittest.TestCase):
def test_unimportable(self):
with mock.patch("allmydata.util.tor_provider._import_tor",
return_value=None):
config = config_from_string(BASECONFIG, "fake.port", "no-basedir")
config = config_from_string("fake.port", "no-basedir", BASECONFIG)
tor_provider = create_tor_provider(reactor, config)
h = tor_provider.get_tor_handler()
self.assertEqual(h, None)
@ -63,7 +63,7 @@ class Tor(unittest.TestCase):
with mock.patch("foolscap.connections.tor.default_socks",
return_value=h1) as f:
config = config_from_string(BASECONFIG, "fake.port", "no-basedir")
config = config_from_string("fake.port", "no-basedir", BASECONFIG)
tor_provider = create_tor_provider(reactor, config)
h = tor_provider.get_tor_handler()
self.assertEqual(f.mock_calls, [mock.call()])
@ -78,7 +78,7 @@ class Tor(unittest.TestCase):
with mock.patch("foolscap.connections.tor.control_endpoint_maker",
return_value=h1) as f:
config = config_from_string(config, "fake.port", ".")
config = config_from_string("fake.port", ".", config)
tp = create_tor_provider("reactor", config)
h = tp.get_tor_handler()
@ -116,9 +116,9 @@ class Tor(unittest.TestCase):
with mock.patch("foolscap.connections.tor.socks_endpoint",
return_value=h1) as f:
config = config_from_string(
BASECONFIG + "[tor]\nsocks.port = unix:/var/lib/fw-daemon/tor_socks.socket\n",
"fake.port",
"no-basedir",
BASECONFIG + "[tor]\nsocks.port = unix:/var/lib/fw-daemon/tor_socks.socket\n",
)
tor_provider = create_tor_provider(reactor, config)
h = tor_provider.get_tor_handler()
@ -130,9 +130,9 @@ class Tor(unittest.TestCase):
with mock.patch("foolscap.connections.tor.socks_endpoint",
return_value=h1) as f:
config = config_from_string(
BASECONFIG + "[tor]\nsocks.port = tcp:127.0.0.1:1234\n",
"fake.port",
"no-basedir",
BASECONFIG + "[tor]\nsocks.port = tcp:127.0.0.1:1234\n",
)
tor_provider = create_tor_provider(reactor, config)
h = tor_provider.get_tor_handler()
@ -144,9 +144,9 @@ class Tor(unittest.TestCase):
with mock.patch("foolscap.connections.tor.socks_endpoint",
return_value=h1) as f:
config = config_from_string(
BASECONFIG + "[tor]\nsocks.port = tcp:otherhost:1234\n",
"fake.port",
"no-basedir",
"fake.port",
BASECONFIG + "[tor]\nsocks.port = tcp:otherhost:1234\n",
)
tor_provider = create_tor_provider(reactor, config)
h = tor_provider.get_tor_handler()
@ -155,9 +155,9 @@ class Tor(unittest.TestCase):
def test_socksport_bad_endpoint(self):
config = config_from_string(
BASECONFIG + "[tor]\nsocks.port = meow:unsupported\n",
"fake.port",
"no-basedir",
BASECONFIG + "[tor]\nsocks.port = meow:unsupported\n",
)
with self.assertRaises(ValueError) as ctx:
tor_provider = create_tor_provider(reactor, config)
@ -169,9 +169,9 @@ class Tor(unittest.TestCase):
def test_socksport_not_integer(self):
config = config_from_string(
BASECONFIG + "[tor]\nsocks.port = tcp:localhost:kumquat\n",
"fake.port",
"no-basedir",
BASECONFIG + "[tor]\nsocks.port = tcp:localhost:kumquat\n",
)
with self.assertRaises(ValueError) as ctx:
tor_provider = create_tor_provider(reactor, config)
@ -186,9 +186,9 @@ class Tor(unittest.TestCase):
with mock.patch("foolscap.connections.tor.control_endpoint",
return_value=h1) as f:
config = config_from_string(
BASECONFIG + "[tor]\ncontrol.port = tcp:localhost:1234\n",
"fake.port",
"no-basedir",
BASECONFIG + "[tor]\ncontrol.port = tcp:localhost:1234\n",
)
tor_provider = create_tor_provider(reactor, config)
h = tor_provider.get_tor_handler()
@ -201,9 +201,9 @@ class I2P(unittest.TestCase):
def test_disabled(self):
config = config_from_string(
BASECONFIG + "[i2p]\nenabled = false\n",
"fake.port",
"no-basedir",
BASECONFIG + "[i2p]\nenabled = false\n",
)
i2p_provider = create_i2p_provider(None, config)
h = i2p_provider.get_i2p_handler()
@ -211,9 +211,9 @@ class I2P(unittest.TestCase):
def test_unimportable(self):
config = config_from_string(
BASECONFIG,
"fake.port",
"no-basedir",
BASECONFIG,
)
with mock.patch("allmydata.util.i2p_provider._import_i2p",
return_value=None):
@ -222,7 +222,7 @@ class I2P(unittest.TestCase):
self.assertEqual(h, None)
def test_default(self):
config = config_from_string(BASECONFIG, "fake.port", "no-basedir")
config = config_from_string("fake.port", "no-basedir", BASECONFIG)
h1 = mock.Mock()
with mock.patch("foolscap.connections.i2p.default",
return_value=h1) as f:
@ -233,9 +233,9 @@ class I2P(unittest.TestCase):
def test_samport(self):
config = config_from_string(
BASECONFIG + "[i2p]\nsam.port = tcp:localhost:1234\n",
"fake.port",
"no-basedir",
BASECONFIG + "[i2p]\nsam.port = tcp:localhost:1234\n",
)
h1 = mock.Mock()
with mock.patch("foolscap.connections.i2p.sam_endpoint",
@ -250,10 +250,10 @@ class I2P(unittest.TestCase):
def test_samport_and_launch(self):
config = config_from_string(
"no-basedir",
"fake.port",
BASECONFIG + "[i2p]\n" +
"sam.port = tcp:localhost:1234\n" + "launch = true\n",
"fake.port",
"no-basedir",
)
with self.assertRaises(ValueError) as ctx:
i2p_provider = create_i2p_provider(reactor, config)
@ -265,9 +265,9 @@ class I2P(unittest.TestCase):
def test_launch(self):
config = config_from_string(
BASECONFIG + "[i2p]\nlaunch = true\n",
"fake.port",
"no-basedir",
BASECONFIG + "[i2p]\nlaunch = true\n",
)
h1 = mock.Mock()
with mock.patch("foolscap.connections.i2p.launch",
@ -280,9 +280,9 @@ class I2P(unittest.TestCase):
def test_launch_executable(self):
config = config_from_string(
BASECONFIG + "[i2p]\nlaunch = true\n" + "i2p.executable = i2p\n",
"fake.port",
"no-basedir",
BASECONFIG + "[i2p]\nlaunch = true\n" + "i2p.executable = i2p\n",
)
h1 = mock.Mock()
with mock.patch("foolscap.connections.i2p.launch",
@ -295,9 +295,9 @@ class I2P(unittest.TestCase):
def test_launch_configdir(self):
config = config_from_string(
BASECONFIG + "[i2p]\nlaunch = true\n" + "i2p.configdir = cfg\n",
"fake.port",
"no-basedir",
BASECONFIG + "[i2p]\nlaunch = true\n" + "i2p.configdir = cfg\n",
)
h1 = mock.Mock()
with mock.patch("foolscap.connections.i2p.launch",
@ -310,10 +310,10 @@ class I2P(unittest.TestCase):
def test_launch_configdir_and_executable(self):
config = config_from_string(
"no-basedir",
"fake.port",
BASECONFIG + "[i2p]\nlaunch = true\n" +
"i2p.executable = i2p\n" + "i2p.configdir = cfg\n",
"fake.port",
"no-basedir",
)
h1 = mock.Mock()
with mock.patch("foolscap.connections.i2p.launch",
@ -326,9 +326,9 @@ class I2P(unittest.TestCase):
def test_configdir(self):
config = config_from_string(
BASECONFIG + "[i2p]\ni2p.configdir = cfg\n",
"fake.port",
"no-basedir",
BASECONFIG + "[i2p]\ni2p.configdir = cfg\n",
)
h1 = mock.Mock()
with mock.patch("foolscap.connections.i2p.local_i2p",
@ -343,7 +343,7 @@ class Connections(unittest.TestCase):
def setUp(self):
self.basedir = 'BASEDIR'
self.config = config_from_string(BASECONFIG, "fake.port", self.basedir)
self.config = config_from_string("fake.port", self.basedir, BASECONFIG)
def test_default(self):
default_connection_handlers, _ = create_connection_handlers(None, self.config, mock.Mock(), mock.Mock())
@ -353,9 +353,9 @@ class Connections(unittest.TestCase):
def test_tor(self):
config = config_from_string(
BASECONFIG + "[connections]\ntcp = tor\n",
"fake.port",
"no-basedir",
BASECONFIG + "[connections]\ntcp = tor\n",
)
default_connection_handlers, _ = create_connection_handlers(None, config, mock.Mock(), mock.Mock())
@ -367,9 +367,9 @@ class Connections(unittest.TestCase):
with mock.patch("allmydata.util.tor_provider._import_tor",
return_value=None):
self.config = config_from_string(
BASECONFIG + "[connections]\ntcp = tor\n",
"fake.port",
"no-basedir",
BASECONFIG + "[connections]\ntcp = tor\n",
)
with self.assertRaises(ValueError) as ctx:
tor_provider = create_tor_provider(reactor, self.config)
@ -383,9 +383,9 @@ class Connections(unittest.TestCase):
def test_unknown(self):
config = config_from_string(
BASECONFIG + "[connections]\ntcp = unknown\n",
"fake.port",
"no-basedir",
BASECONFIG + "[connections]\ntcp = unknown\n",
)
with self.assertRaises(ValueError) as ctx:
create_connection_handlers(None, config, mock.Mock(), mock.Mock())
@ -394,9 +394,9 @@ class Connections(unittest.TestCase):
def test_tcp_disabled(self):
config = config_from_string(
BASECONFIG + "[connections]\ntcp = disabled\n",
"fake.port",
"no-basedir",
BASECONFIG + "[connections]\ntcp = disabled\n",
)
default_connection_handlers, _ = create_connection_handlers(None, config, mock.Mock(), mock.Mock())
self.assertEqual(default_connection_handlers["tcp"], None)
@ -407,9 +407,9 @@ class Privacy(unittest.TestCase):
def test_connections(self):
config = config_from_string(
BASECONFIG + "[node]\nreveal-IP-address = false\n",
"fake.port",
"no-basedir",
BASECONFIG + "[node]\nreveal-IP-address = false\n",
)
with self.assertRaises(PrivacyError) as ctx:
@ -422,19 +422,19 @@ class Privacy(unittest.TestCase):
def test_connections_tcp_disabled(self):
config = config_from_string(
"no-basedir",
"fake.port",
BASECONFIG + "[connections]\ntcp = disabled\n" +
"[node]\nreveal-IP-address = false\n",
"fake.port",
"no-basedir",
)
default_connection_handlers, _ = create_connection_handlers(None, config, mock.Mock(), mock.Mock())
self.assertEqual(default_connection_handlers["tcp"], None)
def test_tub_location_auto(self):
config = config_from_string(
BASECONFIG + "[node]\nreveal-IP-address = false\n",
"fake.port",
"no-basedir",
BASECONFIG + "[node]\nreveal-IP-address = false\n",
)
with self.assertRaises(PrivacyError) as ctx:
@ -446,9 +446,9 @@ class Privacy(unittest.TestCase):
def test_tub_location_tcp(self):
config = config_from_string(
BASECONFIG + "[node]\nreveal-IP-address = false\ntub.location=tcp:hostname:1234\n",
"fake.port",
"no-basedir",
BASECONFIG + "[node]\nreveal-IP-address = false\ntub.location=tcp:hostname:1234\n",
)
with self.assertRaises(PrivacyError) as ctx:
_tub_portlocation(config)
@ -459,9 +459,9 @@ class Privacy(unittest.TestCase):
def test_tub_location_legacy_tcp(self):
config = config_from_string(
BASECONFIG + "[node]\nreveal-IP-address = false\ntub.location=hostname:1234\n",
"fake.port",
"no-basedir",
BASECONFIG + "[node]\nreveal-IP-address = false\ntub.location=hostname:1234\n",
)
with self.assertRaises(PrivacyError) as ctx:

View File

@ -43,7 +43,7 @@ class LoggingMultiService(service.MultiService):
def testing_tub(config_data=''):
from twisted.internet import reactor
basedir = 'dummy_basedir'
config = config_from_string(config_data, 'DEFAULT_PORTNUMFILE_BLANK', basedir)
config = config_from_string(basedir, 'DEFAULT_PORTNUMFILE_BLANK', config_data)
fileutil.make_dirs(os.path.join(basedir, 'private'))
i2p_provider = create_i2p_provider(reactor, config)
@ -226,7 +226,7 @@ class TestCase(testutil.SignalMixin, unittest.TestCase):
f.close()
basedir = fileutil.abspath_expanduser_unicode(basedir)
config = config_from_string("", "", basedir)
config = config_from_string(basedir, "", "")
self.assertEqual(config.get_private_config("already"), "secret")
self.assertEqual(config.get_private_config("not", "default"), "default")
@ -255,7 +255,7 @@ class TestCase(testutil.SignalMixin, unittest.TestCase):
"""
basedir = "test_node/configdir"
fileutil.make_dirs(basedir)
config = config_from_string("", "", basedir)
config = config_from_string(basedir, "", "")
with open(os.path.join(basedir, "bad"), "w") as f:
f.write("bad")
os.chmod(os.path.join(basedir, "bad"), 0o000)
@ -337,7 +337,7 @@ class TestMissingPorts(unittest.TestCase):
"tub.port = tcp:777\n"
"tub.location = AUTO\n"
)
config = config_from_string(config_data, self.basedir, "portnum")
config = config_from_string(self.basedir, "portnum", config_data)
with get_addr, alloc_port:
tubport, tublocation = _tub_portlocation(config)
@ -359,7 +359,7 @@ class TestMissingPorts(unittest.TestCase):
config_data = (
"[node]\n"
)
config = config_from_string(config_data, "portnum", self.basedir)
config = config_from_string(self.basedir, "portnum", config_data)
with get_addr, alloc_port:
tubport, tublocation = _tub_portlocation(config)
@ -382,7 +382,7 @@ class TestMissingPorts(unittest.TestCase):
"[node]\n"
"tub.location = tcp:HOST:888,AUTO\n"
)
config = config_from_string(config_data, "portnum", self.basedir)
config = config_from_string(self.basedir, "portnum", config_data)
with get_addr, alloc_port:
tubport, tublocation = _tub_portlocation(config)
@ -406,7 +406,7 @@ class TestMissingPorts(unittest.TestCase):
"tub.port = disabled\n"
"tub.location = disabled\n"
)
config = config_from_string(config_data, "portnum", self.basedir)
config = config_from_string(self.basedir, "portnum", config_data)
with get_addr, alloc_port:
res = _tub_portlocation(config)
@ -420,7 +420,7 @@ class TestMissingPorts(unittest.TestCase):
"[node]\n"
"tub.port = \n"
)
config = config_from_string(config_data, "portnum", self.basedir)
config = config_from_string(self.basedir, "portnum", config_data)
with self.assertRaises(ValueError) as ctx:
_tub_portlocation(config)
@ -437,7 +437,7 @@ class TestMissingPorts(unittest.TestCase):
"[node]\n"
"tub.location = \n"
)
config = config_from_string(config_data, "portnum", self.basedir)
config = config_from_string(self.basedir, "portnum", config_data)
with self.assertRaises(ValueError) as ctx:
_tub_portlocation(config)
@ -455,7 +455,7 @@ class TestMissingPorts(unittest.TestCase):
"tub.port = disabled\n"
"tub.location = not_disabled\n"
)
config = config_from_string(config_data, "portnum", self.basedir)
config = config_from_string(self.basedir, "portnum", config_data)
with self.assertRaises(ValueError) as ctx:
_tub_portlocation(config)
@ -473,7 +473,7 @@ class TestMissingPorts(unittest.TestCase):
"tub.port = not_disabled\n"
"tub.location = disabled\n"
)
config = config_from_string(config_data, "portnum", self.basedir)
config = config_from_string(self.basedir, "portnum", config_data)
with self.assertRaises(ValueError) as ctx:
_tub_portlocation(config)