]> granicus.if.org Git - python/commitdiff
Partial introduction of bools where appropriate.
authorGuido van Rossum <guido@python.org>
Sun, 7 Apr 2002 06:36:23 +0000 (06:36 +0000)
committerGuido van Rossum <guido@python.org>
Sun, 7 Apr 2002 06:36:23 +0000 (06:36 +0000)
18 files changed:
Lib/CGIHTTPServer.py
Lib/StringIO.py
Lib/chunk.py
Lib/dospath.py
Lib/fileinput.py
Lib/gzip.py
Lib/macpath.py
Lib/ntpath.py
Lib/os2emxpath.py
Lib/posixpath.py
Lib/pprint.py
Lib/pydoc.py
Lib/rfc822.py
Lib/sre_parse.py
Lib/statcache.py
Lib/threading.py
Lib/urllib2.py
Lib/zipfile.py

index c3a6a18ac42ad3cf15cd092117b926cc742d7d7c..56dee47e062d21bea677ee247f26e96a0d946899 100644 (file)
@@ -307,7 +307,7 @@ def executable(path):
     try:
         st = os.stat(path)
     except os.error:
-        return 0
+        return False
     return st[0] & 0111 != 0
 
 
index 087092e5c5b828f8aeaab4b13ac4ed958f990b18..cc88e9de4d8f8af4b6f893af5e2ea7179a09891d 100644 (file)
@@ -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:
index 1dc4a77a989aac88f95d163f7a90ba6d19141006..bda965fd6f0a2b5a56abfc76bd24d62e482a3bb9 100644 (file)
@@ -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.
index cfc0d864c31c34099cc75b026df0514366c7e68c..b4aab497e1d32b8be82844e76e3457e7f9325543 100644 (file)
@@ -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):
index 870322c5996dcdb443c797c398b800c416b0b14d..77487edd706787a31bbf3f2e96cad4f9af7c05ed 100644 (file)
@@ -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 = (
index 9e9f5d4b1f75a707ff658c513ab3cfa749e5715f..793a3b55989ead100923415e836d3056f90d2fb5 100644 (file)
@@ -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
index 80deaa918e32413d21935d74be986fc5b6b4d4ab..91412c5bba372586e600ea2c5c6d4ddfc3af3ce5 100644 (file)
@@ -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])
 
 
index 8cd8e9ad684326b6e5d3ed6ad5fe8ac814465f93..370bd6e06168fe54ece7674a6815b1b67c8b9d25 100644 (file)
@@ -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])
 
 
index 01db974beb6fb9dc6ceecac3a3f615afe61401f5..451fb0e9abd301f76662474a28c986755239a800 100644 (file)
@@ -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])
 
 
index cceb2d2be71e9b669d39b0710dacb5120d3cfd19..0b984f6da77f569a996480ccefaaecb0811878b1 100644 (file)
@@ -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
index 82eeac6a7a8c16b069f317077e8407886ef45e69..1c1159315f432e5a4cfe1fef9ec0b5c512e186bb 100644 (file)
@@ -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):
index 587a24c01a1cee2fd61fd3c190304a6e43021d62..de6fc63835ca4560e0b84275fc7e4d5a981dcfa2 100755 (executable)
@@ -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()
index 96ab21c795c1880844c7933d2d488bf50561f1e4..65957aba6d77330819b5c35f85906cb400d1e71e 100644 (file)
@@ -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.
index 0320885c67f9127aa0a179e913d311cfde6ce8eb..1aba45645a2dca90be6944c0f9aaa4f665c8cea8 100644 (file)
@@ -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
index 3123418ca4f62439c337bf742498b76d2b6c8b31..42e5e90db3dcc37832da7b2424629e18e2a59834 100644 (file)
@@ -73,5 +73,5 @@ def isdir(path):
     try:
         st = stat(path)
     except _os.error:
-        return 0
+        return False
     return S_ISDIR(st[ST_MODE])
index 706d5bbc5e1bcb135b575fd7a810b776467974a8..491a7c0b090edbb8a1e935c5db0c9a33a433ab80 100644 (file)
@@ -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
index 3c2c1048a35ff319ceb02d9ca5979fc33dc9e9ed..cfb4f64fc8c172a1825ab4d6ce5075895aec4856 100644 (file)
@@ -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):
index 0efcad3a8a4f38fd90bbb5164b5e201df717d5c0..4e7ea1058162b92f8166387be7b066564d6f933f 100644 (file)
@@ -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: