[tor-commits] [stem/master] Whitespace checker wasn't checking non-tests

atagar at torproject.org atagar at torproject.org
Tue Jun 12 02:09:41 UTC 2012


commit c1450e440e388295a329e84b3e935bf86f88e673
Author: Damian Johnson <atagar at torproject.org>
Date:   Mon Jun 11 19:01:34 2012 -0700

    Whitespace checker wasn't checking non-tests
    
    The whitespace checker was being ran with its default target, which is the
    directory of that file (in this case, test). Explicitely running over
    everything else, and fixing the issues that it found.
---
 run_tests.py                         |    4 +++-
 stem/connection.py                   |    4 +++-
 stem/control.py                      |    2 ++
 stem/descriptor/reader.py            |    2 ++
 stem/descriptor/server_descriptor.py |    2 +-
 stem/process.py                      |    2 ++
 stem/response/__init__.py            |    2 ++
 stem/socket.py                       |    2 ++
 stem/util/conf.py                    |    2 ++
 stem/util/system.py                  |    6 +++---
 test/check_whitespace.py             |    6 +++++-
 11 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/run_tests.py b/run_tests.py
index 6a6aa09..3029094 100755
--- a/run_tests.py
+++ b/run_tests.py
@@ -369,7 +369,9 @@ if __name__ == '__main__':
     
     # TODO: note unused config options afterward?
   
-  whitespace_issues = test.check_whitespace.get_issues()
+  whitespace_issues = test.check_whitespace.get_issues("stem")
+  whitespace_issues.update(test.check_whitespace.get_issues("test"))
+  whitespace_issues.update(test.check_whitespace.get_issues("run_tests.py"))
   
   if whitespace_issues:
     test.output.print_line("WHITESPACE ISSUES", term.Color.BLUE, term.Attr.BOLD)
diff --git a/stem/connection.py b/stem/connection.py
index ddd4be3..e22a2d0 100644
--- a/stem/connection.py
+++ b/stem/connection.py
@@ -84,6 +84,8 @@ the authentication process. For instance...
        +- NoAuthCookie - Supports cookie auth but doesn't have its path.
 """
 
+from __future__ import with_statement
+
 import os
 import getpass
 import binascii
@@ -549,7 +551,7 @@ def authenticate_safecookie(controller, cookie_path, suppress_ctl_errors = True)
   2. generate a hash digest using the challenge received in the first step, and
      use it to authenticate the controller
   
-  The IncorrectCookieSize and UnreadableCookieFile exceptions take 
+  The IncorrectCookieSize and UnreadableCookieFile exceptions take
   precedence over the other exception types.
   
   The AuthChallengeUnsupported, UnrecognizedAuthChallengeMethod,
diff --git a/stem/control.py b/stem/control.py
index dbad4da..71b81bc 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -26,6 +26,8 @@ interacting at a higher level.
     +- __enter__ / __exit__ - manages socket connection
 """
 
+from __future__ import with_statement
+
 import time
 import Queue
 import threading
diff --git a/stem/descriptor/reader.py b/stem/descriptor/reader.py
index 499ded1..01f77df 100644
--- a/stem/descriptor/reader.py
+++ b/stem/descriptor/reader.py
@@ -71,6 +71,8 @@ again...
        +- FileMissing - File does not exist.
 """
 
+from __future__ import with_statement
+
 import os
 import tarfile
 import threading
diff --git a/stem/descriptor/server_descriptor.py b/stem/descriptor/server_descriptor.py
index ec49a55..99080ab 100644
--- a/stem/descriptor/server_descriptor.py
+++ b/stem/descriptor/server_descriptor.py
@@ -438,7 +438,7 @@ class ServerDescriptor(stem.descriptor.Descriptor):
       elif keyword == "uptime":
         # We need to be tolerant of negative uptimes to accomidate a past tor
         # bug...
-        # 
+        #
         # Changes in version 0.1.2.7-alpha - 2007-02-06
         #  - If our system clock jumps back in time, don't publish a negative
         #    uptime in the descriptor. Also, don't let the global rate limiting
diff --git a/stem/process.py b/stem/process.py
index b0e5015..36ef7b9 100644
--- a/stem/process.py
+++ b/stem/process.py
@@ -15,6 +15,8 @@ Helper functions for working with tor as a process.
   launch_tor_with_config - starts a tor process with a custom torrc
 """
 
+from __future__ import with_statement
+
 import re
 import os
 import signal
diff --git a/stem/response/__init__.py b/stem/response/__init__.py
index a4eac7a..dfae1d3 100644
--- a/stem/response/__init__.py
+++ b/stem/response/__init__.py
@@ -23,6 +23,8 @@ Parses replies from the control socket.
     +- pop_mapping - removes and returns the next entry as a KEY=VALUE mapping
 """
 
+from __future__ import with_statement
+
 __all__ = ["getinfo", "protocolinfo", "authchallenge", "convert", "ControlMessage", "ControlLine"]
 
 import re
diff --git a/stem/socket.py b/stem/socket.py
index 2a9e737..1a14c82 100644
--- a/stem/socket.py
+++ b/stem/socket.py
@@ -32,7 +32,9 @@ as instances of the :class:`stem.response.ControlMessage` class.
        +- SocketClosed - Socket has been shut down.
 """
 
+from __future__ import with_statement
 from __future__ import absolute_import
+
 import re
 import socket
 import threading
diff --git a/stem/util/conf.py b/stem/util/conf.py
index 1c67696..70287c2 100644
--- a/stem/util/conf.py
+++ b/stem/util/conf.py
@@ -64,6 +64,8 @@ There are many ways of using the Config class but the most common ones are...
     +- get_int_csv - gets a value as a comma separated list of integers
 """
 
+from __future__ import with_statement
+
 import threading
 
 import stem.util.log as log
diff --git a/stem/util/system.py b/stem/util/system.py
index 559eaa0..a27d121 100644
--- a/stem/util/system.py
+++ b/stem/util/system.py
@@ -192,7 +192,7 @@ def get_pid_by_name(process_name):
   #     PID
   #    3283
   #    3392
-  #   
+  #
   #   atagar$ ps axc
   #     PID   TT  STAT      TIME COMMAND
   #       1   ??  Ss     9:00.22 launchd
@@ -309,7 +309,7 @@ def get_pid_by_port(port):
   #   # TODO: We need an example for the actual command we're using. I'm
   #   # suspecting that replacing the grep with checking the local port works,
   #   # but should double check.
-  #   
+  #
   #   # sockstat -4 | grep tor
   #   _tor     tor        4397  7  tcp4   51.64.7.84:9050    *:*
   #   _tor     tor        4397  8  udp4   51.64.7.84:53      *:*
@@ -469,7 +469,7 @@ def get_bsd_jail_id(pid):
   # Output when called from a FreeBSD jail or when Tor isn't jailed:
   #   JID
   #    0
-  # 
+  #
   # Otherwise it's something like:
   #   JID
   #    1
diff --git a/test/check_whitespace.py b/test/check_whitespace.py
index 5aed7fa..6c47cab 100644
--- a/test/check_whitespace.py
+++ b/test/check_whitespace.py
@@ -39,14 +39,18 @@ def get_issues(base_path = DEFAULT_TARGET):
     with open(file_path) as f: file_contents = f.read()
     lines, file_issues, prev_indent = file_contents.splitlines(), [], 0
     has_with_import, given_with_warning = False, False
+    is_block_comment = False
     
     for i in xrange(len(lines)):
       whitespace, content = re.match("^(\s*)(.*)$", lines[i]).groups()
       
+      if '"""' in content:
+        is_block_comment = not is_block_comment
+      
       if content == "from __future__ import with_statement":
         has_with_import = True
       elif content.startswith("with ") and content.endswith(":") \
-        and not has_with_import and not given_with_warning:
+        and not has_with_import and not given_with_warning and not is_block_comment:
         file_issues.append((i + 1, "missing 'with' import (from __future__ import with_statement)"))
         given_with_warning = True
       



More information about the tor-commits mailing list