[tor-commits] [bridgedb/develop] Move bridgedb.Main to bridgedb.main.

isis at torproject.org isis at torproject.org
Wed Nov 15 22:24:50 UTC 2017


commit 985923c9fa58a268fd8679f9e0193dd9411c8e59
Author: Isis Lovecruft <isis at torproject.org>
Date:   Wed Nov 1 22:58:39 2017 +0000

    Move bridgedb.Main to bridgedb.main.
---
 bridgedb/configure.py                              |   4 +-
 bridgedb/distributors/https/server.py              |   2 +-
 bridgedb/{Main.py => main.py}                      |   4 +-
 bridgedb/proxy.py                                  |   2 +-
 bridgedb/runner.py                                 |   2 +-
 bridgedb/test/legacy_Tests.py                      |   2 +-
 .../{test_bridgedb.py => test_bridgedb_script.py}  |   0
 bridgedb/test/{test_Main.py => test_main.py}       | 126 ++++++++++-----------
 .../{bridgedb.Main.rst => bridgedb.main.rst}       |   6 +-
 doc/sphinx/source/conf.py                          |   2 +-
 scripts/bridgedb                                   |   2 +-
 11 files changed, 76 insertions(+), 76 deletions(-)

diff --git a/bridgedb/configure.py b/bridgedb/configure.py
index 02eea65..1a5e949 100644
--- a/bridgedb/configure.py
+++ b/bridgedb/configure.py
@@ -47,9 +47,9 @@ def loadConfig(configFile=None, configCls=None):
     .. _faster: http://lucumr.pocoo.org/2011/2/1/exec-in-python/
 
     :ivar bool itsSafeToUseLogging: This is called in
-        :func:`bridgedb.Main.run` before
+        :func:`bridgedb.main.run` before
         :func:`bridgedb.safelog.configureLogging`. When called from
-        :func:`~bridgedb.Main.run`, the **configCls** parameter is not given,
+        :func:`~bridgedb.main.run`, the **configCls** parameter is not given,
         because that is the first time that a
         :class:`config <bridgedb.configure.Conf>` has been created. If a
         :class:`logging.Logger` is created in this function, then logging will
diff --git a/bridgedb/distributors/https/server.py b/bridgedb/distributors/https/server.py
index 85a32b3..b756659 100644
--- a/bridgedb/distributors/https/server.py
+++ b/bridgedb/distributors/https/server.py
@@ -1008,7 +1008,7 @@ def addWebServer(config, distributor):
 
     :type config: :class:`bridgedb.persistent.Conf`
     :param config: A configuration object from
-         :mod:`bridgedb.Main`. Currently, we use these options::
+         :mod:`bridgedb.main`. Currently, we use these options::
              HTTP_UNENCRYPTED_PORT
              HTTP_UNENCRYPTED_BIND_IP
              HTTP_USE_IP_FROM_FORWARDED_HEADER
diff --git a/bridgedb/Main.py b/bridgedb/main.py
similarity index 99%
rename from bridgedb/Main.py
rename to bridgedb/main.py
index edd93cf..f6d16ec 100644
--- a/bridgedb/Main.py
+++ b/bridgedb/main.py
@@ -63,7 +63,7 @@ def load(state, hashring, clear=False):
         hashring before parsing for new ones.
     """
     if not state:
-        logging.fatal("bridgedb.Main.load() could not retrieve state!")
+        logging.fatal("bridgedb.main.load() could not retrieve state!")
         sys.exit(2)
 
     if clear:
@@ -517,7 +517,7 @@ def runSubcommand(options, config):
     :type options: :class:`bridgedb.opt.MainOptions`
     :param options: A pre-parsed options class containing any arguments and
         options given in the commandline we were called with.
-    :type config: :class:`bridgedb.Main.Conf`
+    :type config: :class:`bridgedb.main.Conf`
     :param config: The current configuration.
     :raises: :exc:`SystemExit` when all subCommands and subOptions have
         finished running.
diff --git a/bridgedb/proxy.py b/bridgedb/proxy.py
index 4611cf7..39cd109 100644
--- a/bridgedb/proxy.py
+++ b/bridgedb/proxy.py
@@ -33,7 +33,7 @@ def downloadTorExits(proxyList, ipaddress, port=443, protocol=None):
     """Run a script which downloads a list of Tor exit relays which allow their
     clients to exit to the given **ipaddress** and **port**.
 
-    :param proxyList: The :class:`ProxySet` instance from :mod:`bridgedb.Main`.
+    :param proxyList: The :class:`ProxySet` instance from :mod:`bridgedb.main`.
     :param str ipaddress: The IP address that each Tor exit relay should be
         capable of connecting to for clients, as specified by its ExitPolicy.
     :param int port: The port corresponding to the above **ipaddress** that
diff --git a/bridgedb/runner.py b/bridgedb/runner.py
index 4591a3a..57297cb 100644
--- a/bridgedb/runner.py
+++ b/bridgedb/runner.py
@@ -128,7 +128,7 @@ def doDumpBridges(config):
 
     This function handles the commandline '--dump-bridges' option.
 
-    :type config: :class:`bridgedb.Main.Conf`
+    :type config: :class:`bridgedb.main.Conf`
     :param config: The current configuration.
     """
     import bridgedb.Bucket as bucket
diff --git a/bridgedb/test/legacy_Tests.py b/bridgedb/test/legacy_Tests.py
index 77409b4..00e1d12 100644
--- a/bridgedb/test/legacy_Tests.py
+++ b/bridgedb/test/legacy_Tests.py
@@ -18,7 +18,7 @@ import time
 from datetime import datetime
 
 import bridgedb.Bridges
-import bridgedb.Main
+import bridgedb.main
 import bridgedb.schedule
 import bridgedb.Storage
 import re
diff --git a/bridgedb/test/test_bridgedb.py b/bridgedb/test/test_bridgedb_script.py
similarity index 100%
rename from bridgedb/test/test_bridgedb.py
rename to bridgedb/test/test_bridgedb_script.py
diff --git a/bridgedb/test/test_Main.py b/bridgedb/test/test_main.py
similarity index 79%
rename from bridgedb/test/test_Main.py
rename to bridgedb/test/test_main.py
index b157fbf..fddb8a9 100644
--- a/bridgedb/test/test_Main.py
+++ b/bridgedb/test/test_main.py
@@ -9,7 +9,7 @@
 #             (c) 2007-2017, all entities within the AUTHORS file
 # :license: see included LICENSE for information
 
-"""Tests for :mod:`bridgedb.Main`."""
+"""Tests for :mod:`bridgedb.main`."""
 
 from __future__ import print_function
 
@@ -26,7 +26,7 @@ from time import sleep
 from twisted.internet.threads import deferToThread
 from twisted.trial import unittest
 
-from bridgedb import Main
+from bridgedb import main
 from bridgedb.parse.options import parseOptions
 
 
@@ -50,7 +50,7 @@ p reject 1-65535
 def mockUpdateBridgeHistory(bridges, timestamps):
     """A mocked version of :func:`bridgedb.Stability.updateBridgeHistory`
     which doesn't access the database (so that we can test functions which
-    call it, like :func:`bridgedb.Main.load`).
+    call it, like :func:`bridgedb.main.load`).
     """
     for fingerprint, stamps in timestamps.items()[:]:
         for timestamp in stamps:
@@ -71,8 +71,8 @@ class MockHashring(object):
         pass
 
 
-class MainTests(unittest.TestCase):
-    """Integration tests for :func:`bridgedb.Main.load`."""
+class BridgedbTests(unittest.TestCase):
+    """Integration tests for :func:`bridgedb.main.load`."""
 
     def _appendToFile(self, file, data):
         """Append **data** to **file**."""
@@ -117,7 +117,7 @@ class MainTests(unittest.TestCase):
 
     def _cbCallUpdateBridgeHistory(self, d, hashring):
         """Fake some timestamps for the bridges in the hashring, and then call
-        Main.updateBridgeHistory().
+        main.updateBridgeHistory().
         """
         def timestamp():
             return datetime.fromtimestamp(random.randint(1324285117, 1524285117))
@@ -128,7 +128,7 @@ class MainTests(unittest.TestCase):
         for fingerprint, _ in bridges.items():
             timestamps[fingerprint] = [timestamp(), timestamp(), timestamp()]
 
-        return Main.updateBridgeHistory(bridges, timestamps)
+        return main.updateBridgeHistory(bridges, timestamps)
 
     def _eb_Failure(self, failure):
         """If something produces a twisted.python.failure.Failure, fail the
@@ -159,7 +159,7 @@ class MainTests(unittest.TestCase):
         """
         # Get the bridgedb.conf file in the top-level directory of this repo:
         self.configFile = os.path.join(TOPDIR, 'bridgedb.conf')
-        self.config = Main.loadConfig(self.configFile)
+        self.config = main.loadConfig(self.configFile)
 
         # Copy the referenced descriptor files from bridgedb/run/ to CWD:
         self.config.STATUS_FILE = self._copyDescFilesHere([self.config.STATUS_FILE])[0]
@@ -167,7 +167,7 @@ class MainTests(unittest.TestCase):
         self.config.EXTRA_INFO_FILES = self._copyDescFilesHere(self.config.EXTRA_INFO_FILES)
 
         # Initialise the state
-        self.state = Main.persistent.State(**self.config.__dict__)
+        self.state = main.persistent.State(**self.config.__dict__)
         self.key = base64.b64decode('TvPS1y36BFguBmSOvhChgtXB2Lt+BOw0mGfz9SZe12Y=')
 
         # Create a pseudo hashring
@@ -175,104 +175,104 @@ class MainTests(unittest.TestCase):
 
         # Functions which some tests mock, which we'll need to re-replace
         # later in tearDown():
-        self._orig_updateBridgeHistory = Main.updateBridgeHistory
+        self._orig_updateBridgeHistory = main.updateBridgeHistory
         self._orig_sys_argv = sys.argv
 
     def tearDown(self):
         """Replace the mocked mockUpdateBridgeHistory() function with the
         real function, Stability.updateBridgeHistory().
         """
-        Main.updateBridgeHistory = self._orig_updateBridgeHistory
+        main.updateBridgeHistory = self._orig_updateBridgeHistory
         sys.argv = self._orig_sys_argv
 
-    def test_Main_updateBridgeHistory(self):
-        """Main.updateBridgeHistory should update some timestamps for some
+    def test_main_updateBridgeHistory(self):
+        """main.updateBridgeHistory should update some timestamps for some
         bridges.
         """
         # Mock the updateBridgeHistory() function so that we don't try to
         # access the database:
-        Main.updateBridgeHistory = mockUpdateBridgeHistory
+        main.updateBridgeHistory = mockUpdateBridgeHistory
 
         # Get the bridges into the mocked hashring
-        d = deferToThread(Main.load, self.state, self.hashring)
+        d = deferToThread(main.load, self.state, self.hashring)
         d.addCallback(self._cbAssertFingerprints)
         d.addErrback(self._eb_Failure)
         d.addCallback(self._cbCallUpdateBridgeHistory, self.hashring)
         d.addErrback(self._eb_Failure)
         return d
 
-    def test_Main_load(self):
-        """Main.load() should run without error."""
-        d = deferToThread(Main.load, self.state, self.hashring)
+    def test_main_load(self):
+        """main.load() should run without error."""
+        d = deferToThread(main.load, self.state, self.hashring)
         d.addCallback(self._cbAssertFingerprints)
         d.addErrback(self._eb_Failure)
         return d
 
-    def test_Main_load_no_state(self):
-        """Main.load() should raise SystemExit without a state object."""
-        self.assertRaises(SystemExit, Main.load, None, self.hashring)
+    def test_main_load_no_state(self):
+        """main.load() should raise SystemExit without a state object."""
+        self.assertRaises(SystemExit, main.load, None, self.hashring)
 
-    def test_Main_load_clear(self):
+    def test_main_load_clear(self):
         """When called with clear=True, load() should run and clear the
         hashrings.
         """
-        d = deferToThread(Main.load, self.state, self.hashring, clear=True)
+        d = deferToThread(main.load, self.state, self.hashring, clear=True)
         d.addCallback(self._cbAssertFingerprints)
         d.addErrback(self._eb_Failure)
         return d
 
-    def test_Main_load_collect_timestamps(self):
-        """When COLLECT_TIMESTAMPS=True, Main.load() should call
-        Main.updateBridgeHistory().
+    def test_main_load_collect_timestamps(self):
+        """When COLLECT_TIMESTAMPS=True, main.load() should call
+        main.updateBridgeHistory().
         """
         # Mock the addOrUpdateBridgeHistory() function so that we don't try to
         # access the database:
-        Main.updateBridgeHistory = mockUpdateBridgeHistory
+        main.updateBridgeHistory = mockUpdateBridgeHistory
         state = self.state
         state.COLLECT_TIMESTAMPS = True
 
         # The reactor is deferring this to a thread, so the test execution
         # here isn't actually covering the Storage.updateBridgeHistory()
         # function:
-        Main.load(state, self.hashring)
+        main.load(state, self.hashring)
 
-    def test_Main_load_malformed_networkstatus(self):
+    def test_main_load_malformed_networkstatus(self):
         """When called with a networkstatus file with an invalid descriptor,
-        Main.load() should raise a ValueError.
+        main.load() should raise a ValueError.
         """
         self._appendToFile(self.state.STATUS_FILE, NETWORKSTATUS_MALFORMED)
-        self.assertRaises(ValueError, Main.load, self.state, self.hashring)
+        self.assertRaises(ValueError, main.load, self.state, self.hashring)
 
-    def test_Main_reloadFn(self):
-        """Main._reloadFn() should return True."""
-        self.assertTrue(Main._reloadFn())
+    def test_main_reloadFn(self):
+        """main._reloadFn() should return True."""
+        self.assertTrue(main._reloadFn())
 
-    def test_Main_handleSIGHUP(self):
-        """Main._handleSIGHUP() should return True."""
+    def test_main_handleSIGHUP(self):
+        """main._handleSIGHUP() should return True."""
         raise unittest.SkipTest("_handleSIGHUP touches the reactor.")
 
-        self.assertTrue(Main._handleSIGHUP())
+        self.assertTrue(main._handleSIGHUP())
 
-    def test_Main_createBridgeRings(self):
-        """Main.createBridgeRings() should add three hashrings to the
+    def test_main_createBridgeRings(self):
+        """main.createBridgeRings() should add three hashrings to the
         hashring.
         """
         proxyList = None
-        (hashring, emailDist, httpsDist) = Main.createBridgeRings(self.config,
+        (hashring, emailDist, httpsDist) = main.createBridgeRings(self.config,
                                                                   proxyList,
                                                                   self.key)
         # Should have an HTTPSDistributor ring, an EmailDistributor ring,
         # and an UnallocatedHolder ring:
         self.assertEqual(len(hashring.ringsByName.keys()), 3)
 
-    def test_Main_createBridgeRings_with_proxyList(self):
-        """Main.createBridgeRings() should add three hashrings to the
+    def test_main_createBridgeRings_with_proxyList(self):
+        """main.createBridgeRings() should add three hashrings to the
         hashring and add the proxyList to the IPBasedDistibutor.
         """
         exitRelays = ['1.1.1.1', '2.2.2.2', '3.3.3.3']
-        proxyList = Main.proxy.ProxySet()
+        proxyList = main.proxy.ProxySet()
         proxyList.addExitRelays(exitRelays)
-        (hashring, emailDist, httpsDist) = Main.createBridgeRings(self.config,
+        (hashring, emailDist, httpsDist) = main.createBridgeRings(self.config,
                                                                   proxyList,
                                                                   self.key)
         # Should have an HTTPSDistributor ring, an EmailDistributor ring,
@@ -281,14 +281,14 @@ class MainTests(unittest.TestCase):
         self.assertGreater(len(httpsDist.proxies), 0)
         self.assertItemsEqual(exitRelays, httpsDist.proxies)
 
-    def test_Main_createBridgeRings_no_https_dist(self):
-        """When HTTPS_DIST=False, Main.createBridgeRings() should add only
+    def test_main_createBridgeRings_no_https_dist(self):
+        """When HTTPS_DIST=False, main.createBridgeRings() should add only
         two hashrings to the hashring.
         """
-        proxyList = Main.proxy.ProxySet()
+        proxyList = main.proxy.ProxySet()
         config = self.config
         config.HTTPS_DIST = False
-        (hashring, emailDist, httpsDist) = Main.createBridgeRings(config,
+        (hashring, emailDist, httpsDist) = main.createBridgeRings(config,
                                                                   proxyList,
                                                                   self.key)
         # Should have an EmailDistributor ring, and an UnallocatedHolder ring:
@@ -296,14 +296,14 @@ class MainTests(unittest.TestCase):
         self.assertNotIn('https', hashring.rings)
         self.assertNotIn(httpsDist, hashring.ringsByName.values())
 
-    def test_Main_createBridgeRings_no_email_dist(self):
-        """When EMAIL_DIST=False, Main.createBridgeRings() should add only
+    def test_main_createBridgeRings_no_email_dist(self):
+        """When EMAIL_DIST=False, main.createBridgeRings() should add only
         two hashrings to the hashring.
         """
-        proxyList = Main.proxy.ProxySet()
+        proxyList = main.proxy.ProxySet()
         config = self.config
         config.EMAIL_DIST = False
-        (hashring, emailDist, httpsDist) = Main.createBridgeRings(config,
+        (hashring, emailDist, httpsDist) = main.createBridgeRings(config,
                                                                proxyList,
                                                                self.key)
         # Should have an HTTPSDistributor ring, and an UnallocatedHolder ring:
@@ -311,32 +311,32 @@ class MainTests(unittest.TestCase):
         self.assertNotIn('email', hashring.rings)
         self.assertNotIn(emailDist, hashring.ringsByName.values())
 
-    def test_Main_createBridgeRings_no_reserved_share(self):
-        """When RESERVED_SHARE=0, Main.createBridgeRings() should add only
+    def test_main_createBridgeRings_no_reserved_share(self):
+        """When RESERVED_SHARE=0, main.createBridgeRings() should add only
         two hashrings to the hashring.
         """
-        proxyList = Main.proxy.ProxySet()
+        proxyList = main.proxy.ProxySet()
         config = self.config
         config.RESERVED_SHARE = 0
-        (hashring, emailDist, httpsDist) = Main.createBridgeRings(config,
+        (hashring, emailDist, httpsDist) = main.createBridgeRings(config,
                                                                   proxyList,
                                                                   self.key)
         # Should have an HTTPSDistributor ring, and an EmailDistributor ring:
         self.assertEqual(len(hashring.ringsByName.keys()), 2)
         self.assertNotIn('unallocated', hashring.rings)
 
-    def test_Main_createBridgeRings_two_file_buckets(self):
-        """When FILE_BUCKETS has two filenames in it, Main.createBridgeRings()
+    def test_main_createBridgeRings_two_file_buckets(self):
+        """When FILE_BUCKETS has two filenames in it, main.createBridgeRings()
         should add three hashrings to the hashring, then add two
         "pseudo-rings".
         """
-        proxyList = Main.proxy.ProxySet()
+        proxyList = main.proxy.ProxySet()
         config = self.config
         config.FILE_BUCKETS = {
             'bridges-for-support-desk': 10,
             'bridges-for-ooni-tests': 10,
         }
-        (hashring, emailDist, httpsDist) = Main.createBridgeRings(config,
+        (hashring, emailDist, httpsDist) = main.createBridgeRings(config,
                                                                   proxyList,
                                                                   self.key)
         # Should have an HTTPSDistributor ring, an EmailDistributor, and an
@@ -348,8 +348,8 @@ class MainTests(unittest.TestCase):
         self.assertIn('pseudo_bridges-for-support-desk', hashring.pseudoRings)
         self.assertIn('pseudo_bridges-for-ooni-tests', hashring.pseudoRings)
 
-    def test_Main_run(self):
-        """Main.run() should run and then finally raise SystemExit."""
+    def test_main_run(self):
+        """main.run() should run and then finally raise SystemExit."""
         config = """
 BRIDGE_FILES = ["../run/bridge-descriptors"]
 EXTRA_INFO_FILES = ["../run/cached-extrainfo", "../run/cached-extrainfo.new"]
@@ -434,4 +434,4 @@ FILE_BUCKETS = {}"""
         sys.argv = ['bridgedb', '-r', os.getcwd(), '-c', configFile]
         options = parseOptions()
 
-        self.assertRaises(SystemExit, Main.run, options, reactor=None)
+        self.assertRaises(SystemExit, main.run, options, reactor=None)
diff --git a/doc/sphinx/source/bridgedb.Main.rst b/doc/sphinx/source/bridgedb.main.rst
similarity index 56%
rename from doc/sphinx/source/bridgedb.Main.rst
rename to doc/sphinx/source/bridgedb.main.rst
index 982b567..cf9f9ec 100644
--- a/doc/sphinx/source/bridgedb.Main.rst
+++ b/doc/sphinx/source/bridgedb.main.rst
@@ -1,7 +1,7 @@
-bridgedb.Main
-----------------
+bridgedb.main
+-----------------
 
-.. automodule:: bridgedb.Main
+.. automodule:: bridgedb.main
     :members:
     :undoc-members:
     :private-members:
diff --git a/doc/sphinx/source/conf.py b/doc/sphinx/source/conf.py
index 906d5fe..8eb0063 100644
--- a/doc/sphinx/source/conf.py
+++ b/doc/sphinx/source/conf.py
@@ -27,6 +27,7 @@ sys.path.insert(0, os.path.abspath(os.path.join(
 
 
 import bridgedb
+import bridgedb.main
 import bridgedb.bridgerequest
 import bridgedb.bridges
 import bridgedb.captcha
@@ -47,7 +48,6 @@ import bridgedb.distributors.https
 import bridgedb.distributors.https.distributor
 import bridgedb.distributors.https.request
 import bridgedb.distributors.https.server
-import bridgedb.Main
 import bridgedb.parse
 import bridgedb.parse.addr
 import bridgedb.parse.descriptors
diff --git a/scripts/bridgedb b/scripts/bridgedb
index 2ec37b1..876fde9 100644
--- a/scripts/bridgedb
+++ b/scripts/bridgedb
@@ -16,7 +16,7 @@ import sys
 
 from os import getcwd
 
-from bridgedb.Main import run
+from bridgedb.main import run
 from bridgedb.parse.options import parseOptions
 
 





More information about the tor-commits mailing list