Skip to content

Commit

Permalink
Partial introduction of bools where appropriate.
Browse files Browse the repository at this point in the history
  • Loading branch information
gvanrossum committed Apr 7, 2002
1 parent b8bff3f commit 8ca162f
Show file tree
Hide file tree
Showing 18 changed files with 96 additions and 94 deletions.
2 changes: 1 addition & 1 deletion Lib/CGIHTTPServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def executable(path):
try:
st = os.stat(path)
except os.error:
return 0
return False
return st[0] & 0111 != 0


Expand Down
2 changes: 1 addition & 1 deletion Lib/StringIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def close(self):
def isatty(self):
if self.closed:
raise ValueError, "I/O operation on closed file"
return 0
return False

def seek(self, pos, mode = 0):
if self.closed:
Expand Down
20 changes: 10 additions & 10 deletions Lib/chunk.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
exception.
Usage:
while 1:
while True:
try:
chunk = Chunk(file)
except EOFError:
break
chunktype = chunk.getname()
while 1:
while True:
data = chunk.read(nbytes)
if not data:
pass
Expand All @@ -49,9 +49,9 @@
"""

class Chunk:
def __init__(self, file, align = 1, bigendian = 1, inclheader = 0):
def __init__(self, file, align=True, bigendian=True, inclheader=False):
import struct
self.closed = 0
self.closed = False
self.align = align # whether to align to word (2-byte) boundaries
if bigendian:
strflag = '>'
Expand All @@ -71,9 +71,9 @@ def __init__(self, file, align = 1, bigendian = 1, inclheader = 0):
try:
self.offset = self.file.tell()
except (AttributeError, IOError):
self.seekable = 0
self.seekable = False
else:
self.seekable = 1
self.seekable = True

def getname(self):
"""Return the name (ID) of the current chunk."""
Expand All @@ -86,14 +86,14 @@ def getsize(self):
def close(self):
if not self.closed:
self.skip()
self.closed = 1
self.closed = True

def isatty(self):
if self.closed:
raise ValueError, "I/O operation on closed file"
return 0
return False

def seek(self, pos, whence = 0):
def seek(self, pos, whence=0):
"""Seek to specified position into the chunk.
Default position is 0 (start of chunk).
If the file is not seekable, this will result in an error.
Expand All @@ -117,7 +117,7 @@ def tell(self):
raise ValueError, "I/O operation on closed file"
return self.size_read

def read(self, size = -1):
def read(self, size=-1):
"""Read at most size bytes from the chunk.
If size is omitted or negative, read until the end
of the chunk.
Expand Down
2 changes: 1 addition & 1 deletion Lib/dospath.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def islink(path):
"""Is a path a symbolic link?
This will always return false on systems where posix.lstat doesn't exist."""

return 0
return False


def exists(path):
Expand Down
8 changes: 4 additions & 4 deletions Lib/fileinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def __init__(self, files=None, inplace=0, backup="", bufsize=0):
self._lineno = 0
self._filelineno = 0
self._file = None
self._isstdin = 0
self._isstdin = False
self._backupfilename = None
self._buffer = []
self._bufindex = 0
Expand Down Expand Up @@ -214,7 +214,7 @@ def nextfile(self):
try: os.unlink(backupfilename)
except: pass

self._isstdin = 0
self._isstdin = False
self._buffer = []
self._bufindex = 0

Expand All @@ -235,12 +235,12 @@ def readline(self):
self._files = self._files[1:]
self._filelineno = 0
self._file = None
self._isstdin = 0
self._isstdin = False
self._backupfilename = 0
if self._filename == '-':
self._filename = '<stdin>'
self._file = sys.stdin
self._isstdin = 1
self._isstdin = True
else:
if self._inplace:
self._backupfilename = (
Expand Down
22 changes: 11 additions & 11 deletions Lib/gzip.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __init__(self, filename=None, mode=None,
if mode[0:1] == 'r':
self.mode = READ
# Set flag indicating start of a new member
self._new_member = 1
self._new_member = True
self.extrabuf = ""
self.extrasize = 0
self.filename = filename
Expand Down Expand Up @@ -120,12 +120,12 @@ def _read_gzip_header(self):
self.fileobj.read(xlen)
if flag & FNAME:
# Read and discard a null-terminated string containing the filename
while (1):
while True:
s=self.fileobj.read(1)
if not s or s=='\000': break
if flag & FCOMMENT:
# Read and discard a null-terminated string containing a comment
while (1):
while True:
s=self.fileobj.read(1)
if not s or s=='\000': break
if flag & FHCRC:
Expand Down Expand Up @@ -156,7 +156,7 @@ def read(self, size=-1):
readsize = 1024
if size < 0: # get the whole thing
try:
while 1:
while True:
self._read(readsize)
readsize = readsize * 2
except EOFError:
Expand Down Expand Up @@ -201,7 +201,7 @@ def _read(self, size=1024):
self._init_read()
self._read_gzip_header()
self.decompress = zlib.decompressobj(-zlib.MAX_WBITS)
self._new_member = 0
self._new_member = False

# Read a chunk of data from the file
buf = self.fileobj.read(size)
Expand Down Expand Up @@ -229,7 +229,7 @@ def _read(self, size=1024):
# Check the CRC and file size, and set the flag so we read
# a new member on the next call
self._read_eof()
self._new_member = 1
self._new_member = True

def _add_read_data(self, data):
self.crc = zlib.crc32(data, self.crc)
Expand Down Expand Up @@ -275,7 +275,7 @@ def flush(self):
self.fileobj.flush()

def isatty(self):
return 0
return False

def tell(self):
return self.offset
Expand All @@ -286,7 +286,7 @@ def rewind(self):
if self.mode != READ:
raise IOError("Can't rewind in write mode")
self.fileobj.seek(0)
self._new_member = 1
self._new_member = True
self.extrabuf = ""
self.extrasize = 0
self.offset = 0
Expand All @@ -311,7 +311,7 @@ def readline(self, size=-1):
if size < 0: size = sys.maxint
bufs = []
readsize = min(100, size) # Read from the file in small chunks
while 1:
while True:
if size == 0:
return "".join(bufs) # Return resulting line

Expand Down Expand Up @@ -342,7 +342,7 @@ def readlines(self, sizehint=0):
while sizehint > 0:
line = self.readline()
if line == "": break
L.append( line )
L.append(line)
sizehint = sizehint - len(line)

return L
Expand Down Expand Up @@ -390,7 +390,7 @@ def _test():
else:
f = __builtin__.open(arg, "rb")
g = open(arg + ".gz", "wb")
while 1:
while True:
chunk = f.read(1024)
if not chunk:
break
Expand Down
4 changes: 2 additions & 2 deletions Lib/macpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def islink(s):
"""Return true if the pathname refers to a symbolic link.
Always false on the Mac, until we understand Aliases.)"""

return 0
return False


def isfile(s):
Expand All @@ -134,7 +134,7 @@ def isfile(s):
try:
st = os.stat(s)
except os.error:
return 0
return False
return S_ISREG(st[ST_MODE])


Expand Down
6 changes: 3 additions & 3 deletions Lib/ntpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def getatime(filename):

def islink(path):
"""Test for symbolic link. On WindowsNT/95 always returns false"""
return 0
return False


# Does a path exist?
Expand All @@ -259,7 +259,7 @@ def isdir(path):
try:
st = os.stat(path)
except os.error:
return 0
return False
return stat.S_ISDIR(st[stat.ST_MODE])


Expand All @@ -272,7 +272,7 @@ def isfile(path):
try:
st = os.stat(path)
except os.error:
return 0
return False
return stat.S_ISREG(st[stat.ST_MODE])


Expand Down
6 changes: 3 additions & 3 deletions Lib/os2emxpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def getatime(filename):

def islink(path):
"""Test for symbolic link. On OS/2 always returns false"""
return 0
return False


# Does a path exist?
Expand All @@ -216,7 +216,7 @@ def isdir(path):
try:
st = os.stat(path)
except os.error:
return 0
return False
return stat.S_ISDIR(st[stat.ST_MODE])


Expand All @@ -229,7 +229,7 @@ def isfile(path):
try:
st = os.stat(path)
except os.error:
return 0
return False
return stat.S_ISREG(st[stat.ST_MODE])


Expand Down
8 changes: 4 additions & 4 deletions Lib/posixpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def islink(path):
try:
st = os.lstat(path)
except (os.error, AttributeError):
return 0
return False
return stat.S_ISLNK(st[stat.ST_MODE])


Expand All @@ -183,7 +183,7 @@ def isdir(path):
try:
st = os.stat(path)
except os.error:
return 0
return False
return stat.S_ISDIR(st[stat.ST_MODE])


Expand All @@ -196,7 +196,7 @@ def isfile(path):
try:
st = os.stat(path)
except os.error:
return 0
return False
return stat.S_ISREG(st[stat.ST_MODE])


Expand Down Expand Up @@ -335,7 +335,7 @@ def expandvars(path):
import re
_varprog = re.compile(r'\$(\w+|\{[^}]*\})')
i = 0
while 1:
while True:
m = _varprog.search(path, i)
if not m:
break
Expand Down
Loading

0 comments on commit 8ca162f

Please sign in to comment.