Commit d38ddf4c authored by Peter Astrand's avatar Peter Astrand

Patch from Leandro Lucarella: replaced:

var == None and var != None
with
var is None and var is not None

and type(var) == int
with
instanceof(var, int)

...as recomended in PEP 8 [1].
parent b615bf06
...@@ -623,42 +623,42 @@ class Popen(object): ...@@ -623,42 +623,42 @@ class Popen(object):
"""Construct and return tupel with IO objects: """Construct and return tupel with IO objects:
p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite
""" """
if stdin == None and stdout == None and stderr == None: if stdin is None and stdout is None and stderr is None:
return (None, None, None, None, None, None) return (None, None, None, None, None, None)
p2cread, p2cwrite = None, None p2cread, p2cwrite = None, None
c2pread, c2pwrite = None, None c2pread, c2pwrite = None, None
errread, errwrite = None, None errread, errwrite = None, None
if stdin == None: if stdin is None:
p2cread = GetStdHandle(STD_INPUT_HANDLE) p2cread = GetStdHandle(STD_INPUT_HANDLE)
elif stdin == PIPE: elif stdin == PIPE:
p2cread, p2cwrite = CreatePipe(None, 0) p2cread, p2cwrite = CreatePipe(None, 0)
# Detach and turn into fd # Detach and turn into fd
p2cwrite = p2cwrite.Detach() p2cwrite = p2cwrite.Detach()
p2cwrite = msvcrt.open_osfhandle(p2cwrite, 0) p2cwrite = msvcrt.open_osfhandle(p2cwrite, 0)
elif type(stdin) == int: elif isinstance(stdin, int):
p2cread = msvcrt.get_osfhandle(stdin) p2cread = msvcrt.get_osfhandle(stdin)
else: else:
# Assuming file-like object # Assuming file-like object
p2cread = msvcrt.get_osfhandle(stdin.fileno()) p2cread = msvcrt.get_osfhandle(stdin.fileno())
p2cread = self._make_inheritable(p2cread) p2cread = self._make_inheritable(p2cread)
if stdout == None: if stdout is None:
c2pwrite = GetStdHandle(STD_OUTPUT_HANDLE) c2pwrite = GetStdHandle(STD_OUTPUT_HANDLE)
elif stdout == PIPE: elif stdout == PIPE:
c2pread, c2pwrite = CreatePipe(None, 0) c2pread, c2pwrite = CreatePipe(None, 0)
# Detach and turn into fd # Detach and turn into fd
c2pread = c2pread.Detach() c2pread = c2pread.Detach()
c2pread = msvcrt.open_osfhandle(c2pread, 0) c2pread = msvcrt.open_osfhandle(c2pread, 0)
elif type(stdout) == int: elif isinstance(stdout, int):
c2pwrite = msvcrt.get_osfhandle(stdout) c2pwrite = msvcrt.get_osfhandle(stdout)
else: else:
# Assuming file-like object # Assuming file-like object
c2pwrite = msvcrt.get_osfhandle(stdout.fileno()) c2pwrite = msvcrt.get_osfhandle(stdout.fileno())
c2pwrite = self._make_inheritable(c2pwrite) c2pwrite = self._make_inheritable(c2pwrite)
if stderr == None: if stderr is None:
errwrite = GetStdHandle(STD_ERROR_HANDLE) errwrite = GetStdHandle(STD_ERROR_HANDLE)
elif stderr == PIPE: elif stderr == PIPE:
errread, errwrite = CreatePipe(None, 0) errread, errwrite = CreatePipe(None, 0)
...@@ -667,7 +667,7 @@ class Popen(object): ...@@ -667,7 +667,7 @@ class Popen(object):
errread = msvcrt.open_osfhandle(errread, 0) errread = msvcrt.open_osfhandle(errread, 0)
elif stderr == STDOUT: elif stderr == STDOUT:
errwrite = c2pwrite errwrite = c2pwrite
elif type(stderr) == int: elif isinstance(stderr, int):
errwrite = msvcrt.get_osfhandle(stderr) errwrite = msvcrt.get_osfhandle(stderr)
else: else:
# Assuming file-like object # Assuming file-like object
...@@ -715,7 +715,7 @@ class Popen(object): ...@@ -715,7 +715,7 @@ class Popen(object):
# Process startup details # Process startup details
default_startupinfo = STARTUPINFO() default_startupinfo = STARTUPINFO()
if startupinfo == None: if startupinfo is None:
startupinfo = default_startupinfo startupinfo = default_startupinfo
if not None in (p2cread, c2pwrite, errwrite): if not None in (p2cread, c2pwrite, errwrite):
startupinfo.dwFlags |= STARTF_USESTDHANDLES startupinfo.dwFlags |= STARTF_USESTDHANDLES
...@@ -774,18 +774,18 @@ class Popen(object): ...@@ -774,18 +774,18 @@ class Popen(object):
# output pipe are maintained in this process or else the # output pipe are maintained in this process or else the
# pipe will not close when the child process exits and the # pipe will not close when the child process exits and the
# ReadFile will hang. # ReadFile will hang.
if p2cread != None: if p2cread is not None:
p2cread.Close() p2cread.Close()
if c2pwrite != None: if c2pwrite is not None:
c2pwrite.Close() c2pwrite.Close()
if errwrite != None: if errwrite is not None:
errwrite.Close() errwrite.Close()
def poll(self): def poll(self):
"""Check if child process has terminated. Returns returncode """Check if child process has terminated. Returns returncode
attribute.""" attribute."""
if self.returncode == None: if self.returncode is None:
if WaitForSingleObject(self._handle, 0) == WAIT_OBJECT_0: if WaitForSingleObject(self._handle, 0) == WAIT_OBJECT_0:
self.returncode = GetExitCodeProcess(self._handle) self.returncode = GetExitCodeProcess(self._handle)
_active.remove(self) _active.remove(self)
...@@ -795,7 +795,7 @@ class Popen(object): ...@@ -795,7 +795,7 @@ class Popen(object):
def wait(self): def wait(self):
"""Wait for child process to terminate. Returns returncode """Wait for child process to terminate. Returns returncode
attribute.""" attribute."""
if self.returncode == None: if self.returncode is None:
obj = WaitForSingleObject(self._handle, INFINITE) obj = WaitForSingleObject(self._handle, INFINITE)
self.returncode = GetExitCodeProcess(self._handle) self.returncode = GetExitCodeProcess(self._handle)
_active.remove(self) _active.remove(self)
...@@ -831,7 +831,7 @@ class Popen(object): ...@@ -831,7 +831,7 @@ class Popen(object):
stderr_thread.start() stderr_thread.start()
if self.stdin: if self.stdin:
if input != None: if input is not None:
self.stdin.write(input) self.stdin.write(input)
self.stdin.close() self.stdin.close()
...@@ -841,9 +841,9 @@ class Popen(object): ...@@ -841,9 +841,9 @@ class Popen(object):
stderr_thread.join() stderr_thread.join()
# All data exchanged. Translate lists into strings. # All data exchanged. Translate lists into strings.
if stdout != None: if stdout is not None:
stdout = stdout[0] stdout = stdout[0]
if stderr != None: if stderr is not None:
stderr = stderr[0] stderr = stderr[0]
# Translate newlines, if requested. We cannot let the file # Translate newlines, if requested. We cannot let the file
...@@ -871,33 +871,33 @@ class Popen(object): ...@@ -871,33 +871,33 @@ class Popen(object):
c2pread, c2pwrite = None, None c2pread, c2pwrite = None, None
errread, errwrite = None, None errread, errwrite = None, None
if stdin == None: if stdin is None:
pass pass
elif stdin == PIPE: elif stdin == PIPE:
p2cread, p2cwrite = os.pipe() p2cread, p2cwrite = os.pipe()
elif type(stdin) == int: elif isinstance(stdin, int):
p2cread = stdin p2cread = stdin
else: else:
# Assuming file-like object # Assuming file-like object
p2cread = stdin.fileno() p2cread = stdin.fileno()
if stdout == None: if stdout is None:
pass pass
elif stdout == PIPE: elif stdout == PIPE:
c2pread, c2pwrite = os.pipe() c2pread, c2pwrite = os.pipe()
elif type(stdout) == int: elif isinstance(stdout, int):
c2pwrite = stdout c2pwrite = stdout
else: else:
# Assuming file-like object # Assuming file-like object
c2pwrite = stdout.fileno() c2pwrite = stdout.fileno()
if stderr == None: if stderr is None:
pass pass
elif stderr == PIPE: elif stderr == PIPE:
errread, errwrite = os.pipe() errread, errwrite = os.pipe()
elif stderr == STDOUT: elif stderr == STDOUT:
errwrite = c2pwrite errwrite = c2pwrite
elif type(stderr) == int: elif isinstance(stderr, int):
errwrite = stderr errwrite = stderr
else: else:
# Assuming file-like object # Assuming file-like object
...@@ -942,7 +942,7 @@ class Popen(object): ...@@ -942,7 +942,7 @@ class Popen(object):
if shell: if shell:
args = ["/bin/sh", "-c"] + args args = ["/bin/sh", "-c"] + args
if executable == None: if executable is None:
executable = args[0] executable = args[0]
# For transferring possible exec failure from child to parent # For transferring possible exec failure from child to parent
...@@ -985,13 +985,13 @@ class Popen(object): ...@@ -985,13 +985,13 @@ class Popen(object):
if close_fds: if close_fds:
self._close_fds(but=errpipe_write) self._close_fds(but=errpipe_write)
if cwd != None: if cwd is not None:
os.chdir(cwd) os.chdir(cwd)
if preexec_fn: if preexec_fn:
apply(preexec_fn) apply(preexec_fn)
if env == None: if env is None:
os.execvp(executable, args) os.execvp(executable, args)
else: else:
os.execvpe(executable, args, env) os.execvpe(executable, args, env)
...@@ -1042,7 +1042,7 @@ class Popen(object): ...@@ -1042,7 +1042,7 @@ class Popen(object):
def poll(self): def poll(self):
"""Check if child process has terminated. Returns returncode """Check if child process has terminated. Returns returncode
attribute.""" attribute."""
if self.returncode == None: if self.returncode is None:
try: try:
pid, sts = os.waitpid(self.pid, os.WNOHANG) pid, sts = os.waitpid(self.pid, os.WNOHANG)
if pid == self.pid: if pid == self.pid:
...@@ -1055,7 +1055,7 @@ class Popen(object): ...@@ -1055,7 +1055,7 @@ class Popen(object):
def wait(self): def wait(self):
"""Wait for child process to terminate. Returns returncode """Wait for child process to terminate. Returns returncode
attribute.""" attribute."""
if self.returncode == None: if self.returncode is None:
pid, sts = os.waitpid(self.pid, 0) pid, sts = os.waitpid(self.pid, 0)
self._handle_exitstatus(sts) self._handle_exitstatus(sts)
return self.returncode return self.returncode
...@@ -1117,9 +1117,9 @@ class Popen(object): ...@@ -1117,9 +1117,9 @@ class Popen(object):
stderr.append(data) stderr.append(data)
# All data exchanged. Translate lists into strings. # All data exchanged. Translate lists into strings.
if stdout != None: if stdout is not None:
stdout = ''.join(stdout) stdout = ''.join(stdout)
if stderr != None: if stderr is not None:
stderr = ''.join(stderr) stderr = ''.join(stderr)
# Translate newlines, if requested. We cannot let the file # Translate newlines, if requested. We cannot let the file
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment