[Pkg-privacy-commits] [txtorcon] 30/96: left over from pypy-testing branch merge; needs fixup

Jérémy Bobbio lunar at moszumanska.debian.org
Sun Sep 6 18:33:35 UTC 2015


This is an automated email from the git hooks/post-receive script.

lunar pushed a commit to branch master
in repository txtorcon.

commit 7e1ce8d06519e61de558156431f7cc6ec326775a
Author: meejah <meejah at meejah.ca>
Date:   Sat Jan 17 00:47:05 2015 -0700

    left over from pypy-testing branch merge; needs fixup
---
 txtorcon/torconfig.py | 50 ++++++++++++++++++++++++++++++++------------------
 txtorcon/torinfo.py   | 22 ++++++++++++++++++++--
 txtorcon/torstate.py  |  4 ++--
 3 files changed, 54 insertions(+), 22 deletions(-)

diff --git a/txtorcon/torconfig.py b/txtorcon/torconfig.py
index ae15a37..577446f 100644
--- a/txtorcon/torconfig.py
+++ b/txtorcon/torconfig.py
@@ -12,6 +12,7 @@ if sys.platform in ('linux2', 'darwin'):
     import pwd
 
 from twisted.python import log
+from twisted.python.failure import Failure
 from twisted.internet import defer, error, protocol
 from twisted.internet.interfaces import IReactorTime
 from twisted.internet.endpoints import TCP4ClientEndpoint
@@ -378,7 +379,7 @@ def launch_tor(config, reactor,
     # make sure we got things that have write() for stderr, stdout
     # kwargs
     for arg in [stderr, stdout]:
-        if arg and not getattr(arg, "write"):
+        if arg and not getattr(arg, "write", None):
             raise RuntimeError(
                 'File-like object needed for stdout or stderr args.')
 
@@ -550,6 +551,12 @@ class CommaList(TorConfigType):
         return map(string.strip, s.split(','))
 
 
+# FIXME: in latest master; what is it?
+# Tor source says "A list of strings, separated by commas and optional
+# whitespace, representing intervals in seconds, with optional units"
+class TimeIntervalCommaList(CommaList):
+    pass
+
 ## FIXME: is this really a comma-list?
 class RouterList(CommaList):
     pass
@@ -578,9 +585,12 @@ class LineList(TorConfigType):
 config_types = [Boolean, Boolean_Auto, LineList, Integer, SignedInteger, Port,
                 TimeInterval, TimeMsecInterval,
                 DataSize, Float, Time, CommaList, String, LineList, Filename,
-                RouterList]
+                RouterList, TimeIntervalCommaList]
 
 
+def is_list_config_type(klass):
+    return 'List' in klass.__name__ or klass.__name__ in ['HiddenServices']
+
 def _wrapture(orig):
     """
     Returns a new method that wraps orig (the original method) with
@@ -638,7 +648,7 @@ class HiddenService(object):
     127.0.0.1:1234']))
     """
 
-    def __init__(self, config, thedir, ports, auth=None, ver=2):
+    def __init__(self, config, thedir, ports, auth=None, ver=2, group_readable=0):
         """
         config is the TorConfig to which this will belong (FIXME,
         can't we make this automatic somehow?), thedir corresponds to
@@ -760,8 +770,6 @@ class TorConfig(object):
         if control is None:
             self._protocol = None
             self.__dict__['_slutty_'] = None
-            self.__dict__['config']['HiddenServices'] = _ListWrapper(
-                [], functools.partial(self.mark_unsaved, 'HiddenServices'))
 
         else:
             self._protocol = ITorControlProtocol(control)
@@ -772,6 +780,9 @@ class TorConfig(object):
         self.parsers = {}
         '''Instances of the parser classes, subclasses of TorConfigType'''
 
+        self.list_parsers = set(['hiddenservices'])
+        '''All the names (keys from .parsers) that are a List of something.'''
+
         self.post_bootstrap = defer.Deferred()
         if self.protocol:
             if self.protocol.post_bootstrap:
@@ -846,6 +857,11 @@ class TorConfig(object):
         else:
             super(TorConfig, self).__setattr__(name, value)
 
+    def _maybe_create_listwrapper(self, rn):
+        if rn.lower() in self.list_parsers and rn not in self.config:
+            self.config[rn] = _ListWrapper([], functools.partial(
+                self.mark_unsaved, rn))
+
     def __getattr__(self, name):
         """
         on purpose, we don't return self.saved if the key is in there
@@ -853,10 +869,10 @@ class TorConfig(object):
         ``things which might get into the running Tor if save() were
         to be called''
         """
-
         rn = self._find_real_name(name)
         if '_slutty_' in self.__dict__ and rn in self.unsaved:
             return self.unsaved[rn]
+        self._maybe_create_listwrapper(rn)
         return self.config[rn]
 
     def __contains__(self, item):
@@ -1005,8 +1021,8 @@ class TorConfig(object):
         return self
 
     def _find_real_name(self, name):
-        for x in self.__dict__['config'].keys():
-            if x.lower() == name:
+        for x in self.__dict__['parsers'].keys() + self.__dict__['config'].keys():
+            if x.lower() == name.lower():
                 return x
         return name
 
@@ -1042,18 +1058,16 @@ class TorConfig(object):
             v = yield self.protocol.get_conf(name)
             v = v[name]
 
-            self.parsers[name] = inst
-
-            if value == 'LineList':
-                ## FIXME should move to the parse() method, but it
-                ## doesn't have access to conf object etc.
-                self.config[self._find_real_name(name)] = _ListWrapper(
-                    self.parsers[name].parse(v), functools.partial(
-                        self.mark_unsaved, name))
+            rn = self._find_real_name(name)
+            self.parsers[rn] = inst
+            if is_list_config_type(inst.__class__):
+                self.list_parsers.add(rn)
+                parsed = self.parsers[rn].parse(v)
+                self.config[rn] = _ListWrapper(
+                    parsed, functools.partial(self.mark_unsaved, rn))
 
             else:
-                self.config[
-                    self._find_real_name(name)] = self.parsers[name].parse(v)
+                self.config[rn] = self.parsers[rn].parse(v)
 
         # can't just return in @inlineCallbacks-decorated methods
         defer.returnValue(self)
diff --git a/txtorcon/torinfo.py b/txtorcon/torinfo.py
index 1afbd8f..a2395ed 100644
--- a/txtorcon/torinfo.py
+++ b/txtorcon/torinfo.py
@@ -37,6 +37,9 @@ class MagicContainer(object):
     def __len__(self):
         return len(object.__getattribute__(self, 'attrs'))
 
+    def __dir__(self):
+        return object.__getattribute__(self, 'attrs').keys()
+
     def __getattribute__(self, name):
         sup = super(MagicContainer, self)
         if sup.__getattribute__('_setup') is False:
@@ -47,6 +50,9 @@ class MagicContainer(object):
             return attrs.keys()
 
         else:
+            if name.startswith('__'):
+                return sup.__getattribute__(name)
+
             try:
                 return attrs[name]
             except KeyError:
@@ -157,13 +163,25 @@ class TorInfo(object):
     ## iterator protocol
 
     def __getitem__(self, idx):
-        return object.__getattribute__(self, 'attrs').items()[idx][1]
+        sup = super(TorInfo, self)
+        if sup.__getattribute__('_setup') is True:
+            return object.__getattribute__(self, 'attrs').items()[idx][1]
+        raise TypeError("No __getitem__ until we've setup.")
 
     def __len__(self):
-        return len(object.__getattribute__(self, 'attrs'))
+        sup = super(TorInfo, self)
+        if sup.__getattribute__('_setup') is True:
+            return len(object.__getattribute__(self, 'attrs'))
+        raise TypeError("No length until we're setup.")
 
     ## change our attribute behavior based on the value of _setup
 
+    def __dir__(self):
+        sup = super(TorInfo, self)
+        if sup.__getattribute__('_setup') is True:
+            return sup.__getattribute__('attrs').keys()
+        return sup.__getattribute__('__dict__').keys()
+
     def __getattribute__(self, name):
         sup = super(TorInfo, self)
         if sup.__getattribute__('_setup') is False:
diff --git a/txtorcon/torstate.py b/txtorcon/torstate.py
index f30d0d3..1431b52 100644
--- a/txtorcon/torstate.py
+++ b/txtorcon/torstate.py
@@ -378,9 +378,9 @@ class TorState(object):
             try:
                 pid = parse_keywords(pid)['process/pid']
                 self.tor_pid = int(pid)
-            except KeyError:
+            except:
                 self.tor_pid = 0
-        elif self.protocol.is_owned:
+        if not self.tor_pid and self.protocol.is_owned:
             self.tor_pid = self.protocol.is_owned
 
         self.post_bootstrap.callback(self)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/txtorcon.git



More information about the Pkg-privacy-commits mailing list