[Pkg-privacy-commits] [txtorcon] 28/49: Improved get_info() parsing and add added descriptor get_info() test

Ximin Luo infinity0 at debian.org
Mon Oct 19 13:49:52 UTC 2015


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

infinity0 pushed a commit to branch master
in repository txtorcon.

commit f766b94a6a60b2c9527ef7f1c07fb5819201d68b
Author: Sambuddha Basu <sambuddhabasu1 at gmail.com>
Date:   Sun Jun 14 05:19:38 2015 +0400

    Improved get_info() parsing and add added descriptor get_info() test
    
    Basic parse_get_info() method added
    
    Added get_info() under defer.inlineCallbacks
    
    getinfo keys are now looked up in args
    
    Fixed test_notify_after_getinfo
---
 test/test_torcontrolprotocol.py | 45 ++++++++++++++++++++++++++++++++++++++++-
 txtorcon/torcontrolprotocol.py  | 15 +++++++++++---
 2 files changed, 56 insertions(+), 4 deletions(-)

diff --git a/test/test_torcontrolprotocol.py b/test/test_torcontrolprotocol.py
index 9a03bde..9b9e5fa 100644
--- a/test/test_torcontrolprotocol.py
+++ b/test/test_torcontrolprotocol.py
@@ -583,7 +583,7 @@ OK''' % cookietmp.name)
         )
         self.send("250 OK")
 
-        d = self.protocol.get_info("FOO")
+        d = self.protocol.get_info("a")
         d.addCallback(CallbackChecker({'a': 'one'})).addErrback(self.fail)
         self.send("250-a=one")
         self.send("250 OK")
@@ -605,6 +605,49 @@ OK''' % cookietmp.name)
         self.assertEqual(self.transport.value(), "GETINFO version\r\n")
         return d
 
+    def test_getinfo_for_descriptor(self):
+        descriptor_info = """250+desc/name/moria1=
+router moria1 128.31.0.34 9101 0 9131
+platform Tor 0.2.5.0-alpha-dev on Linux
+protocols Link 1 2 Circuit 1
+published 2013-07-05 23:48:52
+fingerprint 9695 DFC3 5FFE B861 329B 9F1A B04C 4639 7020 CE31
+uptime 1818933
+bandwidth 512000 62914560 1307929
+extra-info-digest 17D0142F6EBCDF60160EB1794FA6C9717D581F8C
+caches-extra-info
+onion-key
+-----BEGIN RSA PUBLIC KEY-----
+MIGJAoGBALzd4bhz1usB7wpoaAvP+BBOnNIk7mByAKV6zvyQ0p1M09oEmxPMc3qD
+AAm276oJNf0eq6KWC6YprzPWFsXEIdXSqA6RWXCII1JG/jOoy6nt478BkB8TS9I9
+1MJW27ppRaqnLiTmBmM+qzrsgJGwf+onAgUKKH2GxlVgahqz8x6xAgMBAAE=
+-----END RSA PUBLIC KEY-----
+signing-key
+-----BEGIN RSA PUBLIC KEY-----
+MIGJAoGBALtJ9uD7cD7iHjqNA3AgsX9prES5QN+yFQyr2uOkxzhvunnaf6SNhzWW
+bkfylnMrRm/qCz/czcjZO6N6EKHcXmypehvP566B7gAQ9vDsb+l7VZVWgXvzNc2s
+tl3P7qpC08rgyJh1GqmtQTCesIDqkEyWxwToympCt09ZQRq+fIttAgMBAAE=
+-----END RSA PUBLIC KEY-----
+hidden-service-dir
+contact 1024D/28988BF5 arma mit edu
+ntor-onion-key 9ZVjNkf/iLEnD685SpC5kcDytQ7u5ViiI9JOftdbE0k=
+reject *:*
+router-signature
+-----BEGIN SIGNATURE-----
+Y8Tj2e7mPbFJbguulkPEBVYzyO57p4btpWEXvRMD6vxIh/eyn25pehg5dUVBtZlL
+iO3EUE0AEYah2W9gdz8t+i3Dtr0zgqLS841GC/TyDKCm+MKmN8d098qnwK0NGF9q
+01NZPuSqXM1b6hnl2espFzL7XL8XEGRU+aeg+f/ukw4=
+-----END SIGNATURE-----
+.
+250 OK"""
+        d = self.protocol.get_info("desc/name/moria1")
+        d.addCallback(CallbackChecker({'desc/name/moria1': '\n' + '\n'.join(descriptor_info.split('\n')[1:-2])}))
+        d.addErrback(self.fail)
+
+        for line in descriptor_info.split('\n'):
+            self.send(line)
+        return d
+
     def test_addevent(self):
         self.protocol._set_valid_events('FOO BAR')
 
diff --git a/txtorcon/torcontrolprotocol.py b/txtorcon/torcontrolprotocol.py
index eec7d13..557dfe4 100644
--- a/txtorcon/torcontrolprotocol.py
+++ b/txtorcon/torcontrolprotocol.py
@@ -342,6 +342,7 @@ class TorControlProtocol(LineOnlyReceiver):
     # The following methods are the main TorController API and
     # probably the most interesting for users.
 
+    @defer.inlineCallbacks
     def get_info(self, *args):
         """
         Uses GETINFO to obtain informatoin from Tor.
@@ -356,11 +357,19 @@ class TorControlProtocol(LineOnlyReceiver):
 
         :return:
             a ``Deferred`` which will callback with a dict containing
-            the keys you asked for. This just inserts ``parse_keywords``
-            in the callback chain; if you want to avoid the parsing
+            the keys you asked for. If you want to avoid the parsing
             into a dict, you can use get_info_raw instead.
         """
-        return self.get_info_raw(*args).addCallback(parse_keywords)
+        lines = yield self.get_info_raw(*args)
+        rtn = {}
+        key = None
+        for line in lines.split('\n'):
+            if line.split('=', 1)[0] in args:
+                key = line.split('=', 1)[0]
+                rtn[key] = line.split('=', 1)[1]
+            else:
+                rtn[key] = rtn[key] + '\n' + line
+        defer.returnValue(rtn)
 
     def get_conf(self, *args):
         """

-- 
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