commit 6d1f3625710eb382a810907a49b481ca14762783 Author: Damian Johnson atagar@torproject.org Date: Thu Aug 23 21:32:36 2012 -0700
Minor revisions for USEFEATURE
Few very minor tweaks...
* 'GETINFO orconn-status' provides empty results when we don't have a connection, causing the test to fail.
* Making is_feature_enabled() case insensitive.
* Short circuiting is_feature_enabled() checks if it's in enabled_features.
* The enabled_features attribute is simply used for an existance check, so we don't need to be too careful about deduplicaion. That said, we *do* need to be careful about the case of its entries.
* Renamed the version constants since I'm trying to list their category at the start, to make a sort of namespace. --- stem/control.py | 29 ++++++++++++++++++----------- stem/version.py | 4 ++-- test/integ/control/controller.py | 11 ++++++++++- 3 files changed, 30 insertions(+), 14 deletions(-)
diff --git a/stem/control.py b/stem/control.py index 84a9df1..7edd7bf 100644 --- a/stem/control.py +++ b/stem/control.py @@ -24,8 +24,8 @@ interacting at a higher level. |- set_options - sets or resets the values of multiple configuration options |- load_conf - loads configuration information as if it was in the torrc |- save_conf - saves configuration information to the torrc - |- is_feature_enabled - returns true if a given control connection feature is enabled - |- enable_feature - enables control protocol features that have been disabled by default + |- is_feature_enabled - checks if a given controller feature is enabled + |- enable_feature - enables a controller feature that has been disabled by default |- get_version - convenience method to get tor version |- authenticate - convenience method to authenticate the controller +- protocolinfo - convenience method to get the protocol info @@ -976,16 +976,22 @@ class Controller(BaseController): :returns: True if feature is enabled, False otherwise """
- defaulted_version = None + feature = feature.upper()
- if feature == "EXTENDED_EVENTS": - defaulted_version = stem.version.Requirement.EXTENDED_EVENTS_DEFAULTED - elif feature == "VERBOSE_NAMES": - defaulted_version = stem.version.Requirement.VERBOSE_NAMES_DEFAULTED - - if defaulted_version and self.get_version().meets_requirements(defaulted_version): + if feature in self.enabled_features: return True else: + # check if this feature is on by default + defaulted_version = None + + if feature == "EXTENDED_EVENTS": + defaulted_version = stem.version.Requirement.FEATURE_EXTENDED_EVENTS + elif feature == "VERBOSE_NAMES": + defaulted_version = stem.version.Requirement.FEATURE_VERBOSE_NAMES + + if defaulted_version and self.get_version().meets_requirements(defaulted_version): + self.enabled_features.append(feature) + return feature in self.enabled_features
def enable_feature(self, features): @@ -1016,9 +1022,10 @@ class Controller(BaseController): if response.message.startswith("Unrecognized feature ""): invalid_feature = [response.message[22:response.message.find(""", 22)]] raise stem.socket.InvalidArguments(response.code, response.message, invalid_feature) - raise stem.socket.ProtocolError("USEFEATURE returned invalid response code") + + raise stem.socket.ProtocolError("USEFEATURE provided an invalid response code: %s" % response.code)
- self.enabled_features = list(set(self.enabled_features).union(features)) + self.enabled_features += [entry.upper() for entry in features]
def _case_insensitive_lookup(entries, key, default = UNDEFINED): """ diff --git a/stem/version.py b/stem/version.py index 90cc997..342c400 100644 --- a/stem/version.py +++ b/stem/version.py @@ -249,7 +249,7 @@ Requirement = stem.util.enum.Enum( ("LOADCONF", Version("0.2.1.1")), ("TORRC_CONTROL_SOCKET", Version("0.2.0.30")), ("TORRC_DISABLE_DEBUGGER_ATTACHMENT", Version("0.2.3.9")), - ("VERBOSE_NAMES_DEFAULTED", Version("0.2.2.1-alpha")), - ("EXTENDED_EVENTS_DEFAULTED", Version("0.2.2.1-alpha")), + ("FEATURE_VERBOSE_NAMES", Version("0.2.2.1-alpha")), + ("FEATURE_EXTENDED_EVENTS", Version("0.2.2.1-alpha")), )
diff --git a/test/integ/control/controller.py b/test/integ/control/controller.py index ea91c8c..2723e27 100644 --- a/test/integ/control/controller.py +++ b/test/integ/control/controller.py @@ -330,8 +330,17 @@ class TestController(unittest.TestCase): with runner.get_tor_controller() as controller: if not test.runner.require_version(self, stem.version.Version("0.1.2.2-alpha")): controller.enable_feature("VERBOSE_NAMES") - self.assertTrue(re.match("$[0-9a-fA-F]{40}[~=].*", controller.get_info('orconn-status').split()[0])) + self.assertTrue(controller.is_feature_enabled("VERBOSE_NAMES")) + + orconn_output = controller.get_info('orconn-status') + + # the orconn-status results will be empty if we don't have a connection + if orconn_output == '': + test.runner.skip(self, "(no tor connections)") + return + + self.assertTrue(re.match("$[0-9a-fA-F]{40}[~=].*", controller.get_info('orconn-status').split()[0])) self.assertTrue("VERBOSE_NAMES" in controller.enabled_features) self.assertRaises(stem.socket.InvalidArguments, controller.enable_feature, ["NOT", "A", "FEATURE"]) try:
tor-commits@lists.torproject.org