summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2002-04-07 06:36:23 (GMT)
committerGuido van Rossum <guido@python.org>2002-04-07 06:36:23 (GMT)
commit8ca162f417c6a72faf02831457b4054a73087b78 (patch)
tree2d882f9a1fe596830f47f1132a5294633ba05f33 /Lib
parentb8bff3f4a9e3be8b43a394d3795a46af2831fe5e (diff)
downloadcpython-8ca162f417c6a72faf02831457b4054a73087b78.zip
cpython-8ca162f417c6a72faf02831457b4054a73087b78.tar.gz
cpython-8ca162f417c6a72faf02831457b4054a73087b78.tar.bz2
Partial introduction of bools where appropriate.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/CGIHTTPServer.py2
-rw-r--r--Lib/StringIO.py2
-rw-r--r--Lib/chunk.py20
-rw-r--r--Lib/dospath.py2
-rw-r--r--Lib/fileinput.py8
-rw-r--r--Lib/gzip.py22
-rw-r--r--Lib/macpath.py4
-rw-r--r--Lib/ntpath.py6
-rw-r--r--Lib/os2emxpath.py6
-rw-r--r--Lib/posixpath.py8
-rw-r--r--Lib/pprint.py42
-rwxr-xr-xLib/pydoc.py9
-rw-r--r--Lib/rfc822.py2
-rw-r--r--Lib/sre_parse.py6
-rw-r--r--Lib/statcache.py2
-rw-r--r--Lib/threading.py38
-rw-r--r--Lib/urllib2.py8
-rw-r--r--Lib/zipfile.py3
18 files changed, 96 insertions, 94 deletions
diff --git a/Lib/CGIHTTPServer.py b/Lib/CGIHTTPServer.py
index c3a6a18..56dee47 100644
--- a/Lib/CGIHTTPServer.py
+++ b/Lib/CGIHTTPServer.py
@@ -307,7 +307,7 @@ def executable(path):
try:
st = os.stat(path)
except os.error:
- return 0
+ return False
return st[0] & 0111 != 0
diff --git a/Lib/StringIO.py b/Lib/StringIO.py
index 087092e..cc88e9d 100644
--- a/Lib/StringIO.py
+++ b/Lib/StringIO.py
@@ -59,7 +59,7 @@ class StringIO:
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:
diff --git a/Lib/chunk.py b/Lib/chunk.py
index 1dc4a77..bda965f 100644
--- a/Lib/chunk.py
+++ b/Lib/chunk.py
@@ -25,13 +25,13 @@ of the file, creating a new instance will fail with a EOFError
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
@@ -49,9 +49,9 @@ default is 1, i.e. aligned.
"""
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 = '>'
@@ -71,9 +71,9 @@ class Chunk:
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."""
@@ -86,14 +86,14 @@ class Chunk:
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.
@@ -117,7 +117,7 @@ class Chunk:
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.
diff --git a/Lib/dospath.py b/Lib/dospath.py
index cfc0d86..b4aab49 100644
--- a/Lib/dospath.py
+++ b/Lib/dospath.py
@@ -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):
diff --git a/Lib/fileinput.py b/Lib/fileinput.py
index 870322c..77487ed 100644
--- a/Lib/fileinput.py
+++ b/Lib/fileinput.py
@@ -154,7 +154,7 @@ class FileInput:
self._lineno = 0
self._filelineno = 0
self._file = None
- self._isstdin = 0
+ self._isstdin = False
self._backupfilename = None
self._buffer = []
self._bufindex = 0
@@ -214,7 +214,7 @@ class FileInput:
try: os.unlink(backupfilename)
except: pass
- self._isstdin = 0
+ self._isstdin = False
self._buffer = []
self._bufindex = 0
@@ -235,12 +235,12 @@ class FileInput:
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 = (
diff --git a/Lib/gzip.py b/Lib/gzip.py
index 9e9f5d4..793a3b5 100644
--- a/Lib/gzip.py
+++ b/Lib/gzip.py
@@ -47,7 +47,7 @@ class GzipFile:
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
@@ -120,12 +120,12 @@ class GzipFile:
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:
@@ -156,7 +156,7 @@ class GzipFile:
readsize = 1024
if size < 0: # get the whole thing
try:
- while 1:
+ while True:
self._read(readsize)
readsize = readsize * 2
except EOFError:
@@ -201,7 +201,7 @@ class GzipFile:
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)
@@ -229,7 +229,7 @@ class GzipFile:
# 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)
@@ -275,7 +275,7 @@ class GzipFile:
self.fileobj.flush()
def isatty(self):
- return 0
+ return False
def tell(self):
return self.offset
@@ -286,7 +286,7 @@ class GzipFile:
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
@@ -311,7 +311,7 @@ class GzipFile:
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
@@ -342,7 +342,7 @@ class GzipFile:
while sizehint > 0:
line = self.readline()
if line == "": break
- L.append( line )
+ L.append(line)
sizehint = sizehint - len(line)
return L
@@ -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
diff --git a/Lib/macpath.py b/Lib/macpath.py
index 80deaa9..91412c5 100644
--- a/Lib/macpath.py
+++ b/Lib/macpath.py
@@ -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):
@@ -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])
diff --git a/Lib/ntpath.py b/Lib/ntpath.py
index 8cd8e9a..370bd6e 100644
--- a/Lib/ntpath.py
+++ b/Lib/ntpath.py
@@ -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?
@@ -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])
@@ -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])
diff --git a/Lib/os2emxpath.py b/Lib/os2emxpath.py
index 01db974..451fb0e 100644
--- a/Lib/os2emxpath.py
+++ b/Lib/os2emxpath.py
@@ -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?
@@ -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])
@@ -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])
diff --git a/Lib/posixpath.py b/Lib/posixpath.py
index cceb2d2..0b984f6 100644
--- a/Lib/posixpath.py
+++ b/Lib/posixpath.py
@@ -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])
@@ -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])
@@ -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])
@@ -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
diff --git a/Lib/pprint.py b/Lib/pprint.py
index 82eeac6..1c11593 100644
--- a/Lib/pprint.py
+++ b/Lib/pprint.py
@@ -126,8 +126,8 @@ class PrettyPrinter:
objid = _id(object)
if objid in context:
stream.write(_recursion(object))
- self.__recursive = 1
- self.__readable = 0
+ self.__recursive = True
+ self.__readable = False
return
rep = self.__repr(object, context, level - 1)
typ = _type(object)
@@ -195,9 +195,9 @@ class PrettyPrinter:
repr, readable, recursive = self.format(object, context.copy(),
self.__depth, level)
if not readable:
- self.__readable = 0
+ self.__readable = False
if recursive:
- self.__recursive = 1
+ self.__recursive = True
return repr
def format(self, object, context, maxlevels, level):
@@ -214,7 +214,7 @@ def _safe_repr(object, context, maxlevels, level):
typ = _type(object)
if typ is StringType:
if 'locale' not in _sys_modules:
- return `object`, 1, 0
+ return `object`, True, False
if "'" in object and '"' not in object:
closure = '"'
quotes = {'"': '\\"'}
@@ -229,19 +229,19 @@ def _safe_repr(object, context, maxlevels, level):
write(char)
else:
write(qget(char, `char`[1:-1]))
- return ("%s%s%s" % (closure, sio.getvalue(), closure)), 1, 0
+ return ("%s%s%s" % (closure, sio.getvalue(), closure)), True, False
if typ is DictType:
if not object:
- return "{}", 1, 0
+ return "{}", True, False
objid = _id(object)
if maxlevels and level > maxlevels:
- return "{...}", 0, objid in context
+ return "{...}", False, objid in context
if objid in context:
- return _recursion(object), 0, 1
+ return _recursion(object), False, True
context[objid] = 1
- readable = 1
- recursive = 0
+ readable = True
+ recursive = False
components = []
append = components.append
level += 1
@@ -252,29 +252,29 @@ def _safe_repr(object, context, maxlevels, level):
append("%s: %s" % (krepr, vrepr))
readable = readable and kreadable and vreadable
if krecur or vrecur:
- recursive = 1
+ recursive = True
del context[objid]
return "{%s}" % _commajoin(components), readable, recursive
if typ is ListType or typ is TupleType:
if typ is ListType:
if not object:
- return "[]", 1, 0
+ return "[]", True, False
format = "[%s]"
elif _len(object) == 1:
format = "(%s,)"
else:
if not object:
- return "()", 1, 0
+ return "()", True, False
format = "(%s)"
objid = _id(object)
if maxlevels and level > maxlevels:
- return format % "...", 0, objid in context
+ return format % "...", False, objid in context
if objid in context:
- return _recursion(object), 0, 1
+ return _recursion(object), False, True
context[objid] = 1
- readable = 1
- recursive = 0
+ readable = True
+ recursive = False
components = []
append = components.append
level += 1
@@ -282,14 +282,14 @@ def _safe_repr(object, context, maxlevels, level):
orepr, oreadable, orecur = _safe_repr(o, context, maxlevels, level)
append(orepr)
if not oreadable:
- readable = 0
+ readable = False
if orecur:
- recursive = 1
+ recursive = True
del context[objid]
return format % _commajoin(components), readable, recursive
rep = `object`
- return rep, (rep and not rep.startswith('<')), 0
+ return rep, (rep and not rep.startswith('<')), False
def _recursion(object):
diff --git a/Lib/pydoc.py b/Lib/pydoc.py
index 587a24c..de6fc63 100755
--- a/Lib/pydoc.py
+++ b/Lib/pydoc.py
@@ -443,7 +443,7 @@ TT { font-family: lucidatypewriter, lucida console, courier }
r'RFC[- ]?(\d+)|'
r'PEP[- ]?(\d+)|'
r'(self\.)?(\w+))')
- while 1:
+ while True:
match = pattern.search(text, here)
if not match: break
start, end = match.span()
@@ -1521,7 +1521,7 @@ has the same effect as typing a particular string at the help> prompt.
def interact(self):
self.output.write('\n')
- while 1:
+ while True:
self.output.write('help> ')
self.output.flush()
try:
@@ -1710,10 +1710,11 @@ class ModuleScanner(Scanner):
if not (os.path.islink(dir) and inode in self.inodes):
self.inodes.append(inode) # detect circular symbolic links
return ispackage(dir)
+ return False
def run(self, callback, key=None, completer=None):
if key: key = lower(key)
- self.quit = 0
+ self.quit = False
seen = {}
for modname in sys.builtin_module_names:
@@ -1825,7 +1826,7 @@ pydoc</strong> by Ka-Ping Yee &lt;ping@lfw.org&gt;</font>'''
def serve_until_quit(self):
import select
- self.quit = 0
+ self.quit = False
while not self.quit:
rd, wr, ex = select.select([self.socket.fileno()], [], [], 1)
if rd: self.handle_request()
diff --git a/Lib/rfc822.py b/Lib/rfc822.py
index 96ab21c..65957ab 100644
--- a/Lib/rfc822.py
+++ b/Lib/rfc822.py
@@ -222,7 +222,7 @@ class Message:
data in RFC 2822-like formats that support embedded comments or
free-text data.
"""
- return None
+ return False
def getallmatchingheaders(self, name):
"""Find all header lines matching a given header name.
diff --git a/Lib/sre_parse.py b/Lib/sre_parse.py
index 0320885..1aba456 100644
--- a/Lib/sre_parse.py
+++ b/Lib/sre_parse.py
@@ -221,11 +221,11 @@ def isdigit(char):
def isname(name):
# check that group name is a valid string
if not isident(name[0]):
- return 0
+ return False
for char in name:
if not isident(char) and not isdigit(char):
- return 0
- return 1
+ return False
+ return True
def _group(escape, groups):
# check if the escape string represents a valid group
diff --git a/Lib/statcache.py b/Lib/statcache.py
index 3123418..42e5e90 100644
--- a/Lib/statcache.py
+++ b/Lib/statcache.py
@@ -73,5 +73,5 @@ def isdir(path):
try:
st = stat(path)
except _os.error:
- return 0
+ return False
return S_ISDIR(st[ST_MODE])
diff --git a/Lib/threading.py b/Lib/threading.py
index 706d5bb..491a7c0 100644
--- a/Lib/threading.py
+++ b/Lib/threading.py
@@ -30,7 +30,7 @@ del StringIO
# Debug support (adapted from ihooks.py)
-_VERBOSE = 0
+_VERBOSE = 0 # XXX Bool or int?
if __debug__:
@@ -198,7 +198,7 @@ class _Condition(_Verbose):
# than 20 times per second (or the timeout time remaining).
endtime = _time() + timeout
delay = 0.0005 # 500 us -> initial delay of 1 ms
- while 1:
+ while True:
gotit = waiter.acquire(0)
if gotit:
break
@@ -256,7 +256,7 @@ class _Semaphore(_Verbose):
self.__value = value
def acquire(self, blocking=1):
- rc = 0
+ rc = False
self.__cond.acquire()
while self.__value == 0:
if not blocking:
@@ -270,7 +270,7 @@ class _Semaphore(_Verbose):
if __debug__:
self._note("%s.acquire: success, value=%s",
self, self.__value)
- rc = 1
+ rc = True
self.__cond.release()
return rc
@@ -309,20 +309,20 @@ class _Event(_Verbose):
def __init__(self, verbose=None):
_Verbose.__init__(self, verbose)
self.__cond = Condition(Lock())
- self.__flag = 0
+ self.__flag = False
def isSet(self):
return self.__flag
def set(self):
self.__cond.acquire()
- self.__flag = 1
+ self.__flag = True
self.__cond.notifyAll()
self.__cond.release()
def clear(self):
self.__cond.acquire()
- self.__flag = 0
+ self.__flag = False
self.__cond.release()
def wait(self, timeout=None):
@@ -348,7 +348,7 @@ _limbo = {}
class Thread(_Verbose):
- __initialized = 0
+ __initialized = False
def __init__(self, group=None, target=None, name=None,
args=(), kwargs={}, verbose=None):
@@ -359,10 +359,10 @@ class Thread(_Verbose):
self.__args = args
self.__kwargs = kwargs
self.__daemonic = self._set_daemon()
- self.__started = 0
- self.__stopped = 0
+ self.__started = False
+ self.__stopped = False
self.__block = Condition(Lock())
- self.__initialized = 1
+ self.__initialized = True
def _set_daemon(self):
# Overridden in _MainThread and _DummyThread
@@ -388,7 +388,7 @@ class Thread(_Verbose):
_limbo[self] = self
_active_limbo_lock.release()
_start_new_thread(self.__bootstrap, ())
- self.__started = 1
+ self.__started = True
_sleep(0.000001) # 1 usec, to let the thread run (Solaris hack)
def run(self):
@@ -397,7 +397,7 @@ class Thread(_Verbose):
def __bootstrap(self):
try:
- self.__started = 1
+ self.__started = True
_active_limbo_lock.acquire()
_active[_get_ident()] = self
del _limbo[self]
@@ -428,7 +428,7 @@ class Thread(_Verbose):
def __stop(self):
self.__block.acquire()
- self.__stopped = 1
+ self.__stopped = True
self.__block.notifyAll()
self.__block.release()
@@ -523,7 +523,7 @@ class _MainThread(Thread):
def __init__(self):
Thread.__init__(self, name="MainThread")
- self._Thread__started = 1
+ self._Thread__started = True
_active_limbo_lock.acquire()
_active[_get_ident()] = self
_active_limbo_lock.release()
@@ -531,7 +531,7 @@ class _MainThread(Thread):
atexit.register(self.__exitfunc)
def _set_daemon(self):
- return 0
+ return False
def __exitfunc(self):
self._Thread__stop()
@@ -564,16 +564,16 @@ class _DummyThread(Thread):
def __init__(self):
Thread.__init__(self, name=_newname("Dummy-%d"))
- self._Thread__started = 1
+ self._Thread__started = True
_active_limbo_lock.acquire()
_active[_get_ident()] = self
_active_limbo_lock.release()
def _set_daemon(self):
- return 1
+ return True
def join(self, timeout=None):
- assert 0, "cannot join a dummy thread"
+ assert False, "cannot join a dummy thread"
# Global API functions
diff --git a/Lib/urllib2.py b/Lib/urllib2.py
index 3c2c104..cfb4f64 100644
--- a/Lib/urllib2.py
+++ b/Lib/urllib2.py
@@ -546,13 +546,13 @@ class HTTPPasswordMgr:
Both args must be URIs in reduced form.
"""
if base == test:
- return 1
+ return True
if base[0] != test[0]:
- return 0
+ return False
common = posixpath.commonprefix((base[1], test[1]))
if len(common) == len(base[1]):
- return 1
- return 0
+ return True
+ return False
class HTTPPasswordMgrWithDefaultRealm(HTTPPasswordMgr):
diff --git a/Lib/zipfile.py b/Lib/zipfile.py
index 0efcad3..4e7ea10 100644
--- a/Lib/zipfile.py
+++ b/Lib/zipfile.py
@@ -83,9 +83,10 @@ def is_zipfile(filename):
endrec = fpin.read()
fpin.close()
if endrec[0:4] == "PK\005\006" and endrec[-2:] == "\000\000":
- return 1 # file has correct magic number
+ return True # file has correct magic number
except IOError:
pass
+ return False
class ZipInfo: