[tor-commits] [stem/master] Don't provide man's '--encoding' argument on OSX

atagar at torproject.org atagar at torproject.org
Sun Mar 27 19:38:06 UTC 2016


commit 878f90cc3aba39fe86f762ef15bac9f848938f4b
Author: Damian Johnson <atagar at torproject.org>
Date:   Sun Mar 27 12:33:02 2016 -0700

    Don't provide man's '--encoding' argument on OSX
    
    Turns out the argument isn't available on OSX. Caught by Sebastian...
    
      https://trac.torproject.org/projects/tor/ticket/18660
---
 stem/cached_tor_manual.cfg |  6 +++---
 stem/manual.py             | 10 ++++++++--
 test/integ/manual.py       |  3 ++-
 test/unit/manual.py        |  1 +
 4 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/stem/cached_tor_manual.cfg b/stem/cached_tor_manual.cfg
index 835024c..fade04b 100644
--- a/stem/cached_tor_manual.cfg
+++ b/stem/cached_tor_manual.cfg
@@ -6,8 +6,8 @@ description
 |Basically, Tor provides a distributed network of servers or relays ("onion routers"). Users bounce their TCP streams -- web traffic, ftp, ssh, etc. -- around the network, and recipients, observers, and even the relays themselves have difficulty tracking the source of the stream.
 |
 |By default, tor will only act as a client only. To help the network by providing bandwidth as a relay, change the ORPort configuration option -- see below. Please also consult the documentation on the Tor Project's website.
-man_commit 424af93ded7e1d9d98733ed17b2b6fee143262b9
-stem_commit 7f4fcf8f6da3941e84376ee67747135e7f34462b
+man_commit 94cb8792e8c28e75bc71434fc557ddefa5c03083
+stem_commit 27a654e2e0495c7ac701d792e7db7ed47d4e9753
 commandline_options -f FILE => Specify a new configuration file to contain further Tor configuration options OR pass - to make Tor read its configuration from standard input. (Default: @CONFDIR@/torrc, or $HOME/.torrc if that file is not found)
 commandline_options --ignore-missing-torrc => Specifies that Tor should treat a missing torrc file as though it were empty. Ordinarily, Tor does this for missing default torrc files, but not for those specified on the command line.
 commandline_options --list-fingerprint => Generate your keys and output your nickname and fingerprint.
@@ -110,7 +110,7 @@ config_options.ExcludeNodes.name ExcludeNodes
 config_options.ExcludeNodes.usage node,node,...
 config_options.ExcludeNodes.summary Relays or locales never to be used in circuits
 config_options.ExcludeNodes.description 
-|A list of identity fingerprints, country codes, and address patterns of nodes to avoid when building a circuit. Country codes are 2-letter ISA3166 codes, and must be wrapped in braces; fingerprints may be preceded by a dollar sign. (Example: ExcludeNodes ABCD1234CDEF5678ABCD1234CDEF5678ABCD1234, {cc}, 255.254.0.0/8)
+|A list of identity fingerprints, country codes, and address patterns of nodes to avoid when building a circuit. Country codes are 2-letter ISO3166 codes, and must be wrapped in braces; fingerprints may be preceded by a dollar sign. (Example: ExcludeNodes ABCD1234CDEF5678ABCD1234CDEF5678ABCD1234, {cc}, 255.254.0.0/8)
 |
 |By default, this option is treated as a preference that Tor is allowed to override in order to keep working. For example, if you try to connect to a hidden service, but you have excluded all of the hidden service's introduction points, Tor will connect to one of them anyway. If you do not want this behavior, set the StrictNodes option (documented below).
 |
diff --git a/stem/manual.py b/stem/manual.py
index 31f9ed1..be7b224 100644
--- a/stem/manual.py
+++ b/stem/manual.py
@@ -360,6 +360,10 @@ class Manual(object):
     """
     Reads and parses a given man page.
 
+    On OSX the man command doesn't have an '--encoding' argument so its results
+    may not quite match other platforms. For instance, it normalizes long
+    dashes into '--'.
+
     :param str man_path: path argument for 'man', for example you might want
       '/path/to/tor/doc/tor.1' to read from tor's git repository
 
@@ -368,10 +372,12 @@ class Manual(object):
     :raises: **IOError** if unable to retrieve the manual
     """
 
+    man_cmd = 'man %s -P cat %s' % ('' if stem.util.system.is_mac() else '--encoding=ascii', man_path)
+
     try:
-      man_output = stem.util.system.call('man --encoding=ascii -P cat %s' % man_path, env = {'MANWIDTH': '10000000'})
+      man_output = stem.util.system.call(man_cmd, env = {'MANWIDTH': '10000000'})
     except OSError as exc:
-      raise IOError("Unable to run 'man --encoding=ascii -P cat %s': %s" % (man_path, exc))
+      raise IOError("Unable to run '%s': %s" % (man_cmd, exc))
 
     categories, config_options = _get_categories(man_output), OrderedDict()
 
diff --git a/test/integ/manual.py b/test/integ/manual.py
index d20c407..dbef86a 100644
--- a/test/integ/manual.py
+++ b/test/integ/manual.py
@@ -107,7 +107,8 @@ class TestManual(unittest.TestCase):
           stem.manual.download_man_page(file_handle = tmp)
           self.man_path = tmp.name
 
-        self.man_content = stem.util.system.call('man --encoding=ascii -P cat %s' % self.man_path, env = {'MANWIDTH': '10000000'})
+        man_cmd = 'man %s -P cat %s' % ('' if stem.util.system.is_mac() else '--encoding=ascii', self.man_path)
+        self.man_content = stem.util.system.call(man_cmd, env = {'MANWIDTH': '10000000'})
       except Exception as exc:
         self.download_error = 'Unable to download the man page: %s' % exc
 
diff --git a/test/unit/manual.py b/test/unit/manual.py
index 99628b0..be0ee9c 100644
--- a/test/unit/manual.py
+++ b/test/unit/manual.py
@@ -268,6 +268,7 @@ class TestManual(unittest.TestCase):
     self.assertEqual(b'a2x output', output.getvalue())
     call_mock.assert_called_once_with('a2x -f manpage /no/such/path/tor.1.txt')
 
+  @patch('stem.util.system.is_mac', Mock(return_value = False))
   @patch('stem.util.system.call', Mock(side_effect = OSError('man --encoding=ascii -P cat tor returned exit status 16')))
   def test_from_man_when_manual_is_unavailable(self):
     try:



More information about the tor-commits mailing list