Skip to content

Commit e6f2395

Browse files
committed
Fixup PEP8 issues.
1 parent d4f10b2 commit e6f2395

File tree

7 files changed

+113
-93
lines changed

7 files changed

+113
-93
lines changed

sshuttle/__main__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ def parse_ipport6(s):
105105
(ip, port) = (ip or '::', int(port or 0))
106106
return (ip, port)
107107

108+
108109
def parse_list(list):
109110
return re.split(r'[\s,]+', list.strip()) if list else []
110111

sshuttle/client.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import sys
1313
from sshuttle.ssnet import SockWrapper, Handler, Proxy, Mux, MuxWrapper
1414
from sshuttle.helpers import log, debug1, debug2, debug3, Fatal, islocal, \
15-
resolvconf_nameservers
15+
resolvconf_nameservers
1616

1717
recvmsg = None
1818
try:
@@ -187,11 +187,13 @@ def daemon_cleanup():
187187

188188
pf_command_file = None
189189

190+
190191
def pf_dst(sock):
191192
peer = sock.getpeername()
192193
proxy = sock.getsockname()
193194

194-
argv = (sock.family, socket.IPPROTO_TCP, peer[0], peer[1], proxy[0], proxy[1])
195+
argv = (sock.family, socket.IPPROTO_TCP,
196+
peer[0], peer[1], proxy[0], proxy[1])
195197
pf_command_file.write("QUERY_PF_NAT %r,%r,%s,%r,%s,%r\n" % argv)
196198
pf_command_file.flush()
197199
line = pf_command_file.readline()
@@ -202,6 +204,7 @@ def pf_dst(sock):
202204

203205
return sock.getsockname()
204206

207+
205208
def original_dst(sock):
206209
try:
207210
SO_ORIGINAL_DST = 80

sshuttle/compat/ssubprocess.py

Lines changed: 33 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -360,41 +360,47 @@ class Popen(args, bufsize=0, executable=None,
360360
import signal
361361

362362
# Exception classes used by this module.
363+
364+
363365
class CalledProcessError(Exception):
364366
"""This exception is raised when a process run by check_call() returns
365367
a non-zero exit status. The exit status will be stored in the
366368
returncode attribute."""
369+
367370
def __init__(self, returncode, cmd):
368371
self.returncode = returncode
369372
self.cmd = cmd
373+
370374
def __str__(self):
371375
return "Command '%s' returned non-zero exit status %d" % (self.cmd, self.returncode)
372376

373377

374378
if mswindows:
375379
import threading
376380
import msvcrt
377-
if 0: # <-- change this to use pywin32 instead of the _subprocess driver
381+
if 0: # <-- change this to use pywin32 instead of the _subprocess driver
378382
import pywintypes
379383
from win32api import GetStdHandle, STD_INPUT_HANDLE, \
380-
STD_OUTPUT_HANDLE, STD_ERROR_HANDLE
384+
STD_OUTPUT_HANDLE, STD_ERROR_HANDLE
381385
from win32api import GetCurrentProcess, DuplicateHandle, \
382-
GetModuleFileName, GetVersion
386+
GetModuleFileName, GetVersion
383387
from win32con import DUPLICATE_SAME_ACCESS, SW_HIDE
384388
from win32pipe import CreatePipe
385389
from win32process import CreateProcess, STARTUPINFO, \
386-
GetExitCodeProcess, STARTF_USESTDHANDLES, \
387-
STARTF_USESHOWWINDOW, CREATE_NEW_CONSOLE
390+
GetExitCodeProcess, STARTF_USESTDHANDLES, \
391+
STARTF_USESHOWWINDOW, CREATE_NEW_CONSOLE
388392
from win32process import TerminateProcess
389393
from win32event import WaitForSingleObject, INFINITE, WAIT_OBJECT_0
390394
else:
391395
from _subprocess import *
396+
392397
class STARTUPINFO:
393398
dwFlags = 0
394399
hStdInput = None
395400
hStdOutput = None
396401
hStdError = None
397402
wShowWindow = 0
403+
398404
class pywintypes:
399405
error = IOError
400406
else:
@@ -403,22 +409,24 @@ class pywintypes:
403409
import fcntl
404410
import pickle
405411

406-
__all__ = ["Popen", "PIPE", "STDOUT", "call", "check_call", "CalledProcessError"]
412+
__all__ = ["Popen", "PIPE", "STDOUT", "call",
413+
"check_call", "CalledProcessError"]
407414

408415
try:
409416
MAXFD = os.sysconf("SC_OPEN_MAX")
410417
except:
411418
MAXFD = 256
412419

413420
# True/False does not exist on 2.2.0
414-
#try:
421+
# try:
415422
# False
416-
#except NameError:
423+
# except NameError:
417424
# False = 0
418425
# True = 1
419426

420427
_active = []
421428

429+
422430
def _cleanup():
423431
for inst in _active[:]:
424432
if inst._internal_poll(_deadstate=sys.maxint) >= 0:
@@ -510,7 +518,7 @@ def list2cmdline(seq):
510518
bs_buf.append(c)
511519
elif c == '"':
512520
# Double backslashes.
513-
result.append('\\' * len(bs_buf)*2)
521+
result.append('\\' * len(bs_buf) * 2)
514522
bs_buf = []
515523
result.append('\\"')
516524
else:
@@ -543,6 +551,7 @@ def _closerange(start, max):
543551

544552

545553
class Popen(object):
554+
546555
def __init__(self, args, bufsize=0, executable=None,
547556
stdin=None, stdout=None, stderr=None,
548557
preexec_fn=None, close_fds=False, shell=False,
@@ -634,13 +643,11 @@ def __init__(self, args, bufsize=0, executable=None,
634643
else:
635644
self.stderr = os.fdopen(errread, 'rb', bufsize)
636645

637-
638646
def _translate_newlines(self, data):
639647
data = data.replace("\r\n", "\n")
640648
data = data.replace("\r", "\n")
641649
return data
642650

643-
644651
def __del__(self, sys=sys):
645652
if not self._child_created:
646653
# We didn't get to successfully create a child process.
@@ -651,7 +658,6 @@ def __del__(self, sys=sys):
651658
# Child is still running, keep us alive until we can wait on it.
652659
_active.append(self)
653660

654-
655661
def communicate(self, input=None):
656662
"""Interact with process: Send data to stdin. Read data from
657663
stdout and stderr, until end-of-file is reached. Wait for
@@ -681,11 +687,9 @@ def communicate(self, input=None):
681687

682688
return self._communicate(input)
683689

684-
685690
def poll(self):
686691
return self._internal_poll()
687692

688-
689693
if mswindows:
690694
#
691695
# Windows methods
@@ -755,14 +759,12 @@ def _get_handles(self, stdin, stdout, stderr):
755759
c2pread, c2pwrite,
756760
errread, errwrite)
757761

758-
759762
def _make_inheritable(self, handle):
760763
"""Return a duplicate of handle, which is inheritable"""
761764
return DuplicateHandle(GetCurrentProcess(), handle,
762765
GetCurrentProcess(), 0, 1,
763766
DUPLICATE_SAME_ACCESS)
764767

765-
766768
def _find_w9xpopen(self):
767769
"""Find and return absolut path to w9xpopen.exe"""
768770
w9xpopen = os.path.join(os.path.dirname(GetModuleFileName(0)),
@@ -778,7 +780,6 @@ def _find_w9xpopen(self):
778780
"shell or platform.")
779781
return w9xpopen
780782

781-
782783
def _execute_child(self, args, executable, preexec_fn, close_fds,
783784
cwd, env, universal_newlines,
784785
startupinfo, creationflags, shell,
@@ -823,13 +824,13 @@ def _execute_child(self, args, executable, preexec_fn, close_fds,
823824
# Start the process
824825
try:
825826
hp, ht, pid, tid = CreateProcess(executable, args,
826-
# no special security
827-
None, None,
828-
int(not close_fds),
829-
creationflags,
830-
env,
831-
cwd,
832-
startupinfo)
827+
# no special security
828+
None, None,
829+
int(not close_fds),
830+
creationflags,
831+
env,
832+
cwd,
833+
startupinfo)
833834
except pywintypes.error, e:
834835
# Translate pywintypes.error to WindowsError, which is
835836
# a subclass of OSError. FIXME: We should really
@@ -856,7 +857,6 @@ def _execute_child(self, args, executable, preexec_fn, close_fds,
856857
if errwrite is not None:
857858
errwrite.Close()
858859

859-
860860
def _internal_poll(self, _deadstate=None):
861861
"""Check if child process has terminated. Returns returncode
862862
attribute."""
@@ -865,7 +865,6 @@ def _internal_poll(self, _deadstate=None):
865865
self.returncode = GetExitCodeProcess(self._handle)
866866
return self.returncode
867867

868-
869868
def wait(self):
870869
"""Wait for child process to terminate. Returns returncode
871870
attribute."""
@@ -874,14 +873,12 @@ def wait(self):
874873
self.returncode = GetExitCodeProcess(self._handle)
875874
return self.returncode
876875

877-
878876
def _readerthread(self, fh, buffer):
879877
buffer.append(fh.read())
880878

881-
882879
def _communicate(self, input):
883-
stdout = None # Return
884-
stderr = None # Return
880+
stdout = None # Return
881+
stderr = None # Return
885882

886883
if self.stdout:
887884
stdout = []
@@ -988,7 +985,6 @@ def _get_handles(self, stdin, stdout, stderr):
988985
c2pread, c2pwrite,
989986
errread, errwrite)
990987

991-
992988
def _set_cloexec_flag(self, fd):
993989
try:
994990
cloexec_flag = fcntl.FD_CLOEXEC
@@ -998,12 +994,10 @@ def _set_cloexec_flag(self, fd):
998994
old = fcntl.fcntl(fd, fcntl.F_GETFD)
999995
fcntl.fcntl(fd, fcntl.F_SETFD, old | cloexec_flag)
1000996

1001-
1002997
def _close_fds(self, but):
1003998
_closerange(3, but)
1004999
_closerange(but + 1, MAXFD)
10051000

1006-
10071001
def _execute_child(self, args, executable, preexec_fn, close_fds,
10081002
cwd, env, universal_newlines,
10091003
startupinfo, creationflags, shell,
@@ -1109,14 +1103,13 @@ def _execute_child(self, args, executable, preexec_fn, close_fds,
11091103
os.close(errwrite)
11101104

11111105
# Wait for exec to fail or succeed; possibly raising exception
1112-
data = os.read(errpipe_read, 1048576) # Exceptions limited to 1 MB
1106+
data = os.read(errpipe_read, 1048576) # Exceptions limited to 1 MB
11131107
os.close(errpipe_read)
11141108
if data != "":
11151109
os.waitpid(self.pid, 0)
11161110
child_exception = pickle.loads(data)
11171111
raise child_exception
11181112

1119-
11201113
def _handle_exitstatus(self, sts):
11211114
if os.WIFSIGNALED(sts):
11221115
self.returncode = -os.WTERMSIG(sts)
@@ -1126,7 +1119,6 @@ def _handle_exitstatus(self, sts):
11261119
# Should never happen
11271120
raise RuntimeError("Unknown child exit status!")
11281121

1129-
11301122
def _internal_poll(self, _deadstate=None):
11311123
"""Check if child process has terminated. Returns returncode
11321124
attribute."""
@@ -1140,7 +1132,6 @@ def _internal_poll(self, _deadstate=None):
11401132
self.returncode = _deadstate
11411133
return self.returncode
11421134

1143-
11441135
def wait(self):
11451136
"""Wait for child process to terminate. Returns returncode
11461137
attribute."""
@@ -1149,12 +1140,11 @@ def wait(self):
11491140
self._handle_exitstatus(sts)
11501141
return self.returncode
11511142

1152-
11531143
def _communicate(self, input):
11541144
read_set = []
11551145
write_set = []
1156-
stdout = None # Return
1157-
stderr = None # Return
1146+
stdout = None # Return
1147+
stderr = None # Return
11581148

11591149
if self.stdin:
11601150
# Flush stdio buffer. This might block, if the user has
@@ -1174,7 +1164,8 @@ def _communicate(self, input):
11741164
input_offset = 0
11751165
while read_set or write_set:
11761166
try:
1177-
rlist, wlist, xlist = select.select(read_set, write_set, [])
1167+
rlist, wlist, xlist = select.select(
1168+
read_set, write_set, [])
11781169
except select.error, e:
11791170
if e.args[0] == errno.EINTR:
11801171
continue
@@ -1184,7 +1175,7 @@ def _communicate(self, input):
11841175
# When select has indicated that the file is writable,
11851176
# we can write up to PIPE_BUF bytes without risk
11861177
# blocking. POSIX defines PIPE_BUF >= 512
1187-
chunk = input[input_offset : input_offset + 512]
1178+
chunk = input[input_offset: input_offset + 512]
11881179
bytes_written = os.write(self.stdin.fileno(), chunk)
11891180
input_offset += bytes_written
11901181
if input_offset >= len(input):

0 commit comments

Comments
 (0)