commit 3a0b98dd0231d4e635fd7cb693b628bbb0e7a77a Author: Isis Lovecruft isis@torproject.org Date: Fri Nov 15 14:09:27 2013 +0000
Move Main.Conf → persistent.Conf.
In order to store `Conf` config objects persistently, the Conf class must be accessible in the bridgedb.persistent module. However, the bridgedb.persistent module must be importable into bridgedb.Main in order to use it. This creates a circular import dependency. To fix it, I moved Main.Conf to persistent.Conf.
Also, there were bugs in the Conf class which caused Conf instances to store __builtin__ classes. To fix this, I changed:
for key, value in attrs.items(): if key.upper() == key: self.__dict__[key] = value
to
for key, value in attrs.items(): if key == key.upper(): if not key.startswith('__'): self.__dict__[key] = value
* FIXES a bug in Conf class causing Python's __builtin__ classes to be reloaded into the global scope. --- lib/bridgedb/Main.py | 9 +-------- lib/bridgedb/persistent.py | 9 +++++++++ 2 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/lib/bridgedb/Main.py b/lib/bridgedb/Main.py index 6fe82f1..7c28492 100644 --- a/lib/bridgedb/Main.py +++ b/lib/bridgedb/Main.py @@ -21,6 +21,7 @@ from pprint import pprint from twisted.internet import reactor
from bridgedb import crypto +from bridgedb import persistent from bridgedb.parse import options
import bridgedb.Bridges as Bridges @@ -30,14 +31,6 @@ import bridgedb.Storage import bridgedb.Util as Util
-class Conf: - """A configuration object. Holds unvalidated attributes.""" - def __init__(self, **attrs): - for key, value in attrs.items(): - if key.upper() == key: - self.__dict__[key] = value - - def configureLogging(cfg): """Set up Python's logging subsystem based on the configuratino. """ diff --git a/lib/bridgedb/persistent.py b/lib/bridgedb/persistent.py index 89e9ff4..c008627 100644 --- a/lib/bridgedb/persistent.py +++ b/lib/bridgedb/persistent.py @@ -76,6 +76,15 @@ def load(stateCls=None): return loaded
+class Conf(object): + """A configuration object. Holds unvalidated attributes.""" + def __init__(self, **attrs): + for key, value in attrs.items(): + if key == key.upper(): + if not key.startswith('__'): + self.__dict__[key] = value + + class State(jelly.Jellyable): """Pickled, jellied storage container for persistent state."""