[Pkg-anonymity-tools] [onionshare] 17/57: pep8: fix empty line counts

Ulrike Uhlig u-guest at moszumanska.debian.org
Tue May 19 18:18:54 UTC 2015


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

u-guest pushed a commit to annotated tag 0.7
in repository onionshare.

commit 179eefae29491f5d0c0ddf2aca1164dbf2cba4f9
Author: Thomas Waldmann <tw at waldmann-edv.de>
Date:   Tue Nov 18 18:29:32 2014 +0100

    pep8: fix empty line counts
    
    top level: 2, else 1
    
    I also advice to not put "pass" into empty classes, but rather a docstring instead of "pass".
---
 check_lacked_trans.py            |  2 --
 onionshare/helpers.py            |  9 ++++++++-
 onionshare/onionshare.py         | 15 ++++++++++++---
 onionshare/socks.py              | 40 +++++++++++++++++++++++++++++++---------
 onionshare/strings.py            |  2 ++
 onionshare_gui/common.py         |  2 ++
 onionshare_gui/downloads.py      |  1 +
 onionshare_gui/file_selection.py |  2 ++
 onionshare_gui/onionshare_gui.py |  4 ++++
 onionshare_gui/options.py        |  1 +
 onionshare_gui/server_status.py  |  1 +
 setup.py                         |  1 +
 test/onionshare_helpers_test.py  |  2 ++
 test/onionshare_strings_test.py  |  3 +++
 test/onionshare_test.py          |  2 ++
 test/onionshare_web_test.py      |  2 ++
 16 files changed, 74 insertions(+), 15 deletions(-)

diff --git a/check_lacked_trans.py b/check_lacked_trans.py
index ae57cdf..6dc145a 100644
--- a/check_lacked_trans.py
+++ b/check_lacked_trans.py
@@ -75,13 +75,11 @@ def main():
             key = m.group(1)
             translate_keys.add(key)
 
-
     if args.show_all_keys:
         for k in sorted(translate_keys):
             print k
         sys.exit()
 
-
     locale_files = [f for f in files_in(dir, 'locale') if f.endswith('.json')]
     for locale_file in locale_files:
         with codecs.open(locale_file, 'r', encoding='utf-8') as f:
diff --git a/onionshare/helpers.py b/onionshare/helpers.py
index 4555f7b..da7e911 100644
--- a/onionshare/helpers.py
+++ b/onionshare/helpers.py
@@ -32,6 +32,7 @@ def get_platform():
         p = 'Tails'
     return p
 
+
 def get_onionshare_dir():
     if get_platform() == 'Darwin':
         onionshare_dir = os.path.dirname(__file__)
@@ -39,6 +40,7 @@ def get_onionshare_dir():
         onionshare_dir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
     return onionshare_dir
 
+
 def constant_time_compare(val1, val2):
     _builtin_constant_time_compare = getattr(hmac, 'compare_digest', None)
     if _builtin_constant_time_compare is not None:
@@ -55,6 +57,7 @@ def constant_time_compare(val1, val2):
         result |= x ^ y
     return result == 0
 
+
 def random_string(num_bytes, output_len=None):
     b = os.urandom(num_bytes)
     h = hashlib.sha256(b).digest()[:16]
@@ -63,6 +66,7 @@ def random_string(num_bytes, output_len=None):
         return s
     return s[:output_len]
 
+
 def human_readable_filesize(b):
     thresh = 1024.0
     if b < thresh:
@@ -75,9 +79,11 @@ def human_readable_filesize(b):
         u += 1
     return '{0} {1}'.format(round(b, 1), units[u])
 
+
 def is_root():
     return os.geteuid() == 0
 
+
 def dir_size(start_path):
     total_size = 0
     for dirpath, dirnames, filenames in os.walk(start_path):
@@ -87,6 +93,7 @@ def dir_size(start_path):
                 total_size += os.path.getsize(fp)
     return total_size
 
+
 def get_tmp_dir():
     if get_platform() == "Windows":
         if 'Temp' in os.environ:
@@ -97,6 +104,7 @@ def get_tmp_dir():
         temp = '/tmp'
     return temp
 
+
 class ZipWriter(object):
     def __init__(self, zip_filename=None):
         if zip_filename:
@@ -120,4 +128,3 @@ class ZipWriter(object):
 
     def close(self):
         self.z.close()
-
diff --git a/onionshare/onionshare.py b/onionshare/onionshare.py
index 739862c..742a6b9 100644
--- a/onionshare/onionshare.py
+++ b/onionshare/onionshare.py
@@ -25,8 +25,14 @@ from stem import SocketError
 
 import strings, helpers, web
 
-class NoTor(Exception): pass
-class TailsError(Exception): pass
+
+class NoTor(Exception):
+    pass
+
+
+class TailsError(Exception):
+    pass
+
 
 def hsdic2list(dic):
     """Convert what we get from get_conf_map to what we need for set_options"""
@@ -37,6 +43,7 @@ def hsdic2list(dic):
         ] for pair in pairs
     ]
 
+
 class OnionShare(object):
     def __init__(self, debug=False, local_only=False, stay_open=False):
         self.port = None
@@ -56,7 +63,6 @@ class OnionShare(object):
         # files and dirs to delete on shutdown
         self.cleanup_filenames = []
 
-
     def cleanup(self):
         if self.controller:
             # Get fresh hidden services (maybe changed since last time)
@@ -191,6 +197,7 @@ class OnionShare(object):
                 return False
         return True
 
+
 def tails_root():
     # if running in Tails and as root, do only the things that require root
     if helpers.get_platform() == 'Tails' and helpers.is_root():
@@ -217,6 +224,7 @@ def tails_root():
 
         # close hole in firewall on shutdown
         import signal
+
         def handler(signum = None, frame = None):
             subprocess.call(['/sbin/iptables', '-D', 'OUTPUT', '-o', 'lo', '-p', 'tcp', '--dport', str(port), '-j', 'ACCEPT'])
             sys.exit()
@@ -227,6 +235,7 @@ def tails_root():
         while True:
             time.sleep(1)
 
+
 def main():
     strings.load_strings()
     tails_root()
diff --git a/onionshare/socks.py b/onionshare/socks.py
index 709220d..49b96b7 100644
--- a/onionshare/socks.py
+++ b/onionshare/socks.py
@@ -65,6 +65,7 @@ PRINTABLE_PROXY_TYPES = {SOCKS4: "SOCKS4", SOCKS5: "SOCKS5", HTTP: "HTTP"}
 
 _orgsocket = _orig_socket = socket.socket
 
+
 class ProxyError(IOError):
     """
     socket_err contains original socket.error exception.
@@ -79,12 +80,30 @@ class ProxyError(IOError):
     def __str__(self):
         return self.msg
 
-class GeneralProxyError(ProxyError): pass
-class ProxyConnectionError(ProxyError): pass
-class SOCKS5AuthError(ProxyError): pass
-class SOCKS5Error(ProxyError): pass
-class SOCKS4Error(ProxyError): pass
-class HTTPError(ProxyError): pass
+
+class GeneralProxyError(ProxyError):
+    pass
+
+
+class ProxyConnectionError(ProxyError):
+    pass
+
+
+class SOCKS5AuthError(ProxyError):
+    pass
+
+
+class SOCKS5Error(ProxyError):
+    pass
+
+
+class SOCKS4Error(ProxyError):
+    pass
+
+
+class HTTPError(ProxyError):
+    pass
+
 
 SOCKS4_ERRORS = { 0x5B: "Request rejected or failed",
                   0x5C: "Request rejected because SOCKS server cannot connect to identd on the client",
@@ -106,6 +125,7 @@ DEFAULT_PORTS = { SOCKS4: 1080,
                   HTTP: 8080
                 }
 
+
 def set_default_proxy(proxy_type=None, addr=None, port=None, rdns=True, username=None, password=None):
     """
     set_default_proxy(proxy_type, addr[, port[, rdns[, username, password]]])
@@ -119,6 +139,7 @@ def set_default_proxy(proxy_type=None, addr=None, port=None, rdns=True, username
 
 setdefaultproxy = set_default_proxy
 
+
 def get_default_proxy():
     """
     Returns the default proxy, set by set_default_proxy.
@@ -127,6 +148,7 @@ def get_default_proxy():
 
 getdefaultproxy = get_default_proxy
 
+
 def wrap_module(module):
     """
     Attempts to replace a module's socket library with a SOCKS socket. Must set
@@ -141,7 +163,8 @@ def wrap_module(module):
 
 wrapmodule = wrap_module
 
-def create_connection(dest_pair, proxy_type=None, proxy_addr=None, 
+
+def create_connection(dest_pair, proxy_type=None, proxy_addr=None,
                       proxy_port=None, proxy_username=None,
                       proxy_password=None, timeout=None):
     """create_connection(dest_pair, **proxy_args) -> socket object
@@ -161,6 +184,7 @@ def create_connection(dest_pair, proxy_type=None, proxy_addr=None,
     sock.connect(dest_pair)
     return sock
 
+
 class socksocket(socket.socket):
     """socksocket([family[, type[, proto]]]) -> socket object
 
@@ -446,7 +470,6 @@ class socksocket(socket.socket):
         self.proxy_sockname = (b"0.0.0.0", 0)
         self.proxy_peername = addr, dest_port
 
-
     def connect(self, dest_pair):
         """        
         Connects to the specified destination through a proxy.
@@ -465,7 +488,6 @@ class socksocket(socket.socket):
                 or not isinstance(dest_port, int)):
             raise GeneralProxyError("Invalid destination-connection (host, port) pair")
 
-
         if proxy_type is None:
             # Treat like regular socket object
             _orig_socket.connect(self, (dest_addr, dest_port))
diff --git a/onionshare/strings.py b/onionshare/strings.py
index 4222fba..4a0bdb8 100644
--- a/onionshare/strings.py
+++ b/onionshare/strings.py
@@ -22,6 +22,7 @@ import helpers
 
 strings = {}
 
+
 def load_strings(default="en"):
     global strings
 
@@ -49,6 +50,7 @@ def load_strings(default="en"):
                 if key in translated[lang]:
                     strings[key] = translated[lang][key]
 
+
 def translated(k, gui=False):
     if gui:
         return strings[k].encode("utf-8").decode('utf-8', 'replace')
diff --git a/onionshare_gui/common.py b/onionshare_gui/common.py
index 6c5c06a..927ebfe 100644
--- a/onionshare_gui/common.py
+++ b/onionshare_gui/common.py
@@ -19,6 +19,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 """
 import os, sys, inspect, platform
 
+
 def get_onionshare_gui_dir():
     if platform.system() == 'Darwin':
         onionshare_gui_dir = os.path.dirname(__file__)
@@ -28,6 +29,7 @@ def get_onionshare_gui_dir():
 
 onionshare_gui_dir = get_onionshare_gui_dir()
 
+
 def get_image_path(filename):
     if platform.system() == 'Linux':
         prefix = os.path.join(sys.prefix, 'share/onionshare/images')
diff --git a/onionshare_gui/downloads.py b/onionshare_gui/downloads.py
index 90ef6f0..be32c0f 100644
--- a/onionshare_gui/downloads.py
+++ b/onionshare_gui/downloads.py
@@ -22,6 +22,7 @@ from PyQt4 import QtCore, QtGui
 import common
 from onionshare import strings, helpers
 
+
 class Downloads(QtGui.QVBoxLayout):
     def __init__(self):
         super(Downloads, self).__init__()
diff --git a/onionshare_gui/file_selection.py b/onionshare_gui/file_selection.py
index 4a5bfeb..eb6cb36 100644
--- a/onionshare_gui/file_selection.py
+++ b/onionshare_gui/file_selection.py
@@ -23,6 +23,7 @@ from PyQt4 import QtCore, QtGui
 import common
 from onionshare import strings, helpers
 
+
 class FileList(QtGui.QListWidget):
     files_dropped = QtCore.pyqtSignal()
     files_updated = QtCore.pyqtSignal()
@@ -137,6 +138,7 @@ class FileList(QtGui.QListWidget):
             u += 1
         return '{0} {1}'.format(round(b, 1), units[u])
 
+
 class FileSelection(QtGui.QVBoxLayout):
     def __init__(self):
         super(FileSelection, self).__init__()
diff --git a/onionshare_gui/onionshare_gui.py b/onionshare_gui/onionshare_gui.py
index 41f0185..f20c681 100644
--- a/onionshare_gui/onionshare_gui.py
+++ b/onionshare_gui/onionshare_gui.py
@@ -35,6 +35,7 @@ from server_status import ServerStatus
 from downloads import Downloads
 from options import Options
 
+
 class Application(QtGui.QApplication):
     def __init__(self):
         platform = helpers.get_platform()
@@ -42,6 +43,7 @@ class Application(QtGui.QApplication):
             self.setAttribute(QtCore.Qt.AA_X11InitThreads, True)
         QtGui.QApplication.__init__(self, sys.argv)
 
+
 class OnionShareGui(QtGui.QWidget):
     start_server_finished = QtCore.pyqtSignal()
     stop_server_finished = QtCore.pyqtSignal()
@@ -206,6 +208,7 @@ class OnionShareGui(QtGui.QWidget):
     def clear_message(self):
         self.status_bar.clearMessage()
 
+
 def alert(msg, icon=QtGui.QMessageBox.NoIcon):
     dialog = QtGui.QMessageBox()
     dialog.setWindowTitle("OnionShare")
@@ -214,6 +217,7 @@ def alert(msg, icon=QtGui.QMessageBox.NoIcon):
     dialog.setIcon(icon)
     dialog.exec_()
 
+
 def main():
     strings.load_strings()
 
diff --git a/onionshare_gui/options.py b/onionshare_gui/options.py
index 24d5992..f7443b8 100644
--- a/onionshare_gui/options.py
+++ b/onionshare_gui/options.py
@@ -22,6 +22,7 @@ from PyQt4 import QtCore, QtGui
 import common
 from onionshare import strings, helpers
 
+
 class Options(QtGui.QHBoxLayout):
     def __init__(self, web):
         super(Options, self).__init__()
diff --git a/onionshare_gui/server_status.py b/onionshare_gui/server_status.py
index 2909c31..c5a9daa 100644
--- a/onionshare_gui/server_status.py
+++ b/onionshare_gui/server_status.py
@@ -23,6 +23,7 @@ from PyQt4 import QtCore, QtGui
 import common
 from onionshare import strings, helpers
 
+
 class ServerStatus(QtGui.QVBoxLayout):
     server_started = QtCore.pyqtSignal()
     server_stopped = QtCore.pyqtSignal()
diff --git a/setup.py b/setup.py
index 9b9a500..1ef27cc 100644
--- a/setup.py
+++ b/setup.py
@@ -27,6 +27,7 @@ try:
 except ImportError:
     from distutils.core import setup
 
+
 def file_list(path):
     files = []
     for filename in os.listdir(path):
diff --git a/test/onionshare_helpers_test.py b/test/onionshare_helpers_test.py
index 94febed..1c7c42d 100644
--- a/test/onionshare_helpers_test.py
+++ b/test/onionshare_helpers_test.py
@@ -21,11 +21,13 @@ from nose import with_setup
 
 import test_helpers
 
+
 def test_get_platform_on_tails():
     """get_platform() returns 'Tails' when hostname is 'amnesia'"""
     helpers.platform.uname = lambda: ('Linux', 'amnesia', '3.14-1-amd64', '#1 SMP Debian 3.14.4-1 (2014-05-13)', 'x86_64', '')
     assert helpers.get_platform() == 'Tails'
 
+
 def test_get_platform_returns_platform_system():
     """get_platform() returns platform.system() when ONIONSHARE_PLATFORM is not defined"""
     helpers.platform.system = lambda: 'Sega Saturn'
diff --git a/test/onionshare_strings_test.py b/test/onionshare_strings_test.py
index 011bf40..ab215e0 100644
--- a/test/onionshare_strings_test.py
+++ b/test/onionshare_strings_test.py
@@ -21,16 +21,19 @@ import locale
 from onionshare import strings
 from nose import with_setup
 
+
 def test_starts_with_empty_strings():
     """creates an empty strings dict by default"""
     assert strings.strings == {}
 
+
 def test_load_strings_defaults_to_english():
     """load_strings() loads English by default"""
     locale.getdefaultlocale = lambda: ('en_US', 'UTF-8')
     strings.load_strings()
     assert strings._('wait_for_hs') == "Waiting for HS to be ready:"
 
+
 def test_load_strings_loads_other_languages():
     """load_strings() loads other languages in different locales"""
     locale.getdefaultlocale = lambda: ('fr_FR', 'UTF-8')
diff --git a/test/onionshare_test.py b/test/onionshare_test.py
index 0edf1be..76d6b9a 100644
--- a/test/onionshare_test.py
+++ b/test/onionshare_test.py
@@ -20,12 +20,14 @@ import socket
 from onionshare import OnionShare
 from nose import with_setup
 
+
 def test_choose_port_returns_a_port_number():
     """choose_port() returns a port number"""
     app = OnionShare()
     app.choose_port()
     assert 1024 <= app.port <= 65535
 
+
 def test_choose_port_returns_an_open_port():
     """choose_port() returns an open port"""
     app = OnionShare()
diff --git a/test/onionshare_web_test.py b/test/onionshare_web_test.py
index 963e7e2..54c4872 100644
--- a/test/onionshare_web_test.py
+++ b/test/onionshare_web_test.py
@@ -19,10 +19,12 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 from onionshare import web
 from nose import with_setup
 
+
 def test_generate_slug_length():
     """generates a 26-character slug"""
     assert len(web.slug) == 26
 
+
 def test_generate_slug_characters():
     """generates a base32-encoded slug"""
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/collab-maint/onionshare.git



More information about the Pkg-anonymity-tools mailing list