diff options
author | Tim Peters <tim.peters@gmail.com> | 2002-04-04 22:55:58 +0000 |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2002-04-04 22:55:58 +0000 |
commit | bc0e9108261693b6278687f4fb4709ff76c2e543 (patch) | |
tree | afef5d4734034ed0268950cf06321aefd4154ff3 /Lib | |
parent | 2f486b7fa6451b790b154e6e4751239d69d46952 (diff) | |
download | cpython-git-bc0e9108261693b6278687f4fb4709ff76c2e543.tar.gz |
Convert a pile of obvious "yes/no" functions to return bool.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/BaseHTTPServer.py | 16 | ||||
-rw-r--r-- | Lib/CGIHTTPServer.py | 4 | ||||
-rw-r--r-- | Lib/ConfigParser.py | 4 | ||||
-rw-r--r-- | Lib/SocketServer.py | 4 | ||||
-rw-r--r-- | Lib/asyncore.py | 4 | ||||
-rw-r--r-- | Lib/bdb.py | 16 | ||||
-rwxr-xr-x | Lib/cgi.py | 4 | ||||
-rw-r--r-- | Lib/code.py | 8 | ||||
-rw-r--r-- | Lib/distutils/command/build_py.py | 4 | ||||
-rw-r--r-- | Lib/dospath.py | 8 | ||||
-rw-r--r-- | Lib/filecmp.py | 8 | ||||
-rw-r--r-- | Lib/getopt.py | 4 | ||||
-rw-r--r-- | Lib/macpath.py | 6 | ||||
-rwxr-xr-x | Lib/mailbox.py | 2 | ||||
-rw-r--r-- | Lib/mhlib.py | 4 | ||||
-rw-r--r-- | Lib/mutex.py | 6 | ||||
-rw-r--r-- | Lib/ntpath.py | 4 | ||||
-rw-r--r-- | Lib/os.py | 4 | ||||
-rw-r--r-- | Lib/os2emxpath.py | 4 | ||||
-rw-r--r-- | Lib/posixpath.py | 14 | ||||
-rwxr-xr-x | Lib/pydoc.py | 3 | ||||
-rw-r--r-- | Lib/robotparser.py | 12 | ||||
-rw-r--r-- | Lib/symtable.py | 18 | ||||
-rwxr-xr-x | Lib/tabnanny.py | 8 | ||||
-rw-r--r-- | Lib/threading.py | 4 | ||||
-rw-r--r-- | Lib/webbrowser.py | 8 |
26 files changed, 88 insertions, 93 deletions
diff --git a/Lib/BaseHTTPServer.py b/Lib/BaseHTTPServer.py index 3177cb6196..35baf2f4ac 100644 --- a/Lib/BaseHTTPServer.py +++ b/Lib/BaseHTTPServer.py @@ -222,7 +222,7 @@ class BaseHTTPRequestHandler(SocketServer.StreamRequestHandler): are in self.command, self.path, self.request_version and self.headers. - Return value is 1 for success, 0 for failure; on failure, an + Return True for success, False for failure; on failure, an error is sent back. """ @@ -239,30 +239,30 @@ class BaseHTTPRequestHandler(SocketServer.StreamRequestHandler): [command, path, version] = words if version[:5] != 'HTTP/': self.send_error(400, "Bad request version (%s)" % `version`) - return 0 + return False try: version_number = float(version.split('/', 1)[1]) except ValueError: self.send_error(400, "Bad request version (%s)" % `version`) - return 0 + return False if version_number >= 1.1 and self.protocol_version >= "HTTP/1.1": self.close_connection = 0 if version_number >= 2.0: self.send_error(505, "Invalid HTTP Version (%f)" % version_number) - return 0 + return False elif len(words) == 2: [command, path] = words self.close_connection = 1 if command != 'GET': self.send_error(400, "Bad HTTP/0.9 request type (%s)" % `command`) - return 0 + return False elif not words: - return 0 + return False else: self.send_error(400, "Bad request syntax (%s)" % `requestline`) - return 0 + return False self.command, self.path, self.request_version = command, path, version # Deal with pipelining @@ -283,7 +283,7 @@ class BaseHTTPRequestHandler(SocketServer.StreamRequestHandler): elif (conntype.lower() == 'keep-alive' and self.protocol_version >= "HTTP/1.1"): self.close_connection = 0 - return 1 + return True def handle_one_request(self): """Handle a single HTTP request. diff --git a/Lib/CGIHTTPServer.py b/Lib/CGIHTTPServer.py index 7bb7467798..c3a6a18ac4 100644 --- a/Lib/CGIHTTPServer.py +++ b/Lib/CGIHTTPServer.py @@ -86,8 +86,8 @@ class CGIHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): i = len(x) if path[:i] == x and (not path[i:] or path[i] == '/'): self.cgi_info = path[:i], path[i+1:] - return 1 - return 0 + return True + return False cgi_directories = ['/cgi-bin', '/htbin'] diff --git a/Lib/ConfigParser.py b/Lib/ConfigParser.py index bdce25ef0d..fe97c9e09c 100644 --- a/Lib/ConfigParser.py +++ b/Lib/ConfigParser.py @@ -374,9 +374,9 @@ class ConfigParser: """Remove a file section.""" if self.__sections.has_key(section): del self.__sections[section] - return 1 + return True else: - return 0 + return False # # Regular expressions for parsing section headers and options. Note a diff --git a/Lib/SocketServer.py b/Lib/SocketServer.py index 7e1e27ca02..2c15e9370b 100644 --- a/Lib/SocketServer.py +++ b/Lib/SocketServer.py @@ -226,10 +226,10 @@ class BaseServer: def verify_request(self, request, client_address): """Verify the request. May be overridden. - Return true if we should proceed with this request. + Return True if we should proceed with this request. """ - return 1 + return True def process_request(self, request, client_address): """Call finish_request. diff --git a/Lib/asyncore.py b/Lib/asyncore.py index 6bbfbabd58..c7a8f12684 100644 --- a/Lib/asyncore.py +++ b/Lib/asyncore.py @@ -281,7 +281,7 @@ class dispatcher: # ================================================== def readable (self): - return 1 + return True if os.name == 'mac': # The macintosh will select a listening socket for @@ -290,7 +290,7 @@ class dispatcher: return not self.accepting else: def writable (self): - return 1 + return True # ================================================== # socket object methods. diff --git a/Lib/bdb.py b/Lib/bdb.py index d5b051b5e3..d0c738fa72 100644 --- a/Lib/bdb.py +++ b/Lib/bdb.py @@ -92,31 +92,31 @@ class Bdb: def stop_here(self, frame): if self.stopframe is None: - return 1 + return True if frame is self.stopframe: - return 1 + return True while frame is not None and frame is not self.stopframe: if frame is self.botframe: - return 1 + return True frame = frame.f_back - return 0 + return False def break_here(self, frame): filename = self.canonic(frame.f_code.co_filename) if not self.breaks.has_key(filename): - return 0 + return False lineno = frame.f_lineno if not lineno in self.breaks[filename]: - return 0 + return False # flag says ok to delete temp. bp (bp, flag) = effective(filename, lineno, frame) if bp: self.currentbp = bp.number if (flag and bp.temporary): self.do_clear(str(bp.number)) - return 1 + return True else: - return 0 + return False def do_clear(self, arg): raise NotImplementedError, "subclass of bdb must implement do_clear()" diff --git a/Lib/cgi.py b/Lib/cgi.py index db91ec6d2e..a7ad5bf01f 100755 --- a/Lib/cgi.py +++ b/Lib/cgi.py @@ -600,8 +600,8 @@ class FieldStorage: if self.list is None: raise TypeError, "not indexable" for item in self.list: - if item.name == key: return 1 - return 0 + if item.name == key: return True + return False def __len__(self): """Dictionary style len(x) support.""" diff --git a/Lib/code.py b/Lib/code.py index b7a5af908c..75c64e60e4 100644 --- a/Lib/code.py +++ b/Lib/code.py @@ -66,7 +66,7 @@ class InteractiveInterpreter: object. The code is executed by calling self.runcode() (which also handles run-time exceptions, except for SystemExit). - The return value is 1 in case 2, 0 in the other cases (unless + The return value is True in case 2, False in the other cases (unless an exception is raised). The return value can be used to decide whether to use sys.ps1 or sys.ps2 to prompt the next line. @@ -77,15 +77,15 @@ class InteractiveInterpreter: except (OverflowError, SyntaxError, ValueError): # Case 1 self.showsyntaxerror(filename) - return 0 + return False if code is None: # Case 2 - return 1 + return True # Case 3 self.runcode(code) - return 0 + return False def runcode(self, code): """Execute a code object. diff --git a/Lib/distutils/command/build_py.py b/Lib/distutils/command/build_py.py index 97d094b1b2..453ca97a09 100644 --- a/Lib/distutils/command/build_py.py +++ b/Lib/distutils/command/build_py.py @@ -190,9 +190,9 @@ class build_py (Command): if not os.path.isfile(module_file): self.warn("file %s (for module %s) not found" % (module_file, module)) - return 0 + return False else: - return 1 + return True # check_module () diff --git a/Lib/dospath.py b/Lib/dospath.py index 652b35f51f..cfc0d864c3 100644 --- a/Lib/dospath.py +++ b/Lib/dospath.py @@ -151,8 +151,8 @@ def exists(path): try: st = os.stat(path) except os.error: - return 0 - return 1 + return False + return True def isdir(path): @@ -161,7 +161,7 @@ def isdir(path): try: st = os.stat(path) except os.error: - return 0 + return False return stat.S_ISDIR(st[stat.ST_MODE]) @@ -171,7 +171,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/filecmp.py b/Lib/filecmp.py index 3018762003..f0e6d47bc3 100644 --- a/Lib/filecmp.py +++ b/Lib/filecmp.py @@ -35,7 +35,7 @@ def cmp(f1, f2, shallow=1, use_statcache=0): Return value: - integer -- 1 if the files are the same, 0 otherwise. + True if the files are the same, False otherwise. This function uses a cache for past comparisons and the results, with a cache invalidation mechanism relying on stale signatures. @@ -50,11 +50,11 @@ def cmp(f1, f2, shallow=1, use_statcache=0): s1 = _sig(stat_function(f1)) s2 = _sig(stat_function(f2)) if s1[0] != stat.S_IFREG or s2[0] != stat.S_IFREG: - return 0 + return False if shallow and s1 == s2: - return 1 + return True if s1[1] != s2[1]: - return 0 + return False result = _cache.get((f1, f2)) if result and (s1, s2) == result[:2]: diff --git a/Lib/getopt.py b/Lib/getopt.py index f1dc7ac446..91584fe78f 100644 --- a/Lib/getopt.py +++ b/Lib/getopt.py @@ -103,9 +103,9 @@ def long_has_args(opt, longopts): raise GetoptError('option --%s not recognized' % opt, opt) # Is there an exact match? if opt in possibilities: - return 0, opt + return False, opt elif opt + '=' in possibilities: - return 1, opt + return True, opt # No exact match, so better be unique. if len(possibilities) > 1: # XXX since possibilities contains all valid continuations, might be diff --git a/Lib/macpath.py b/Lib/macpath.py index 6501fcd91d..80deaa918e 100644 --- a/Lib/macpath.py +++ b/Lib/macpath.py @@ -139,13 +139,13 @@ def isfile(s): def exists(s): - """Return true if the pathname refers to an existing file or directory.""" + """Return True if the pathname refers to an existing file or directory.""" try: st = os.stat(s) except os.error: - return 0 - return 1 + return False + return True # Return the longest prefix of all list elements. diff --git a/Lib/mailbox.py b/Lib/mailbox.py index ed83489716..853949b995 100755 --- a/Lib/mailbox.py +++ b/Lib/mailbox.py @@ -151,7 +151,7 @@ class UnixMailbox(_Mailbox): return self._regexp.match(line) def _portable_isrealfromline(self, line): - return 1 + return True _isrealfromline = _strict_isrealfromline diff --git a/Lib/mhlib.py b/Lib/mhlib.py index 6cf0128307..8d0eff1861 100644 --- a/Lib/mhlib.py +++ b/Lib/mhlib.py @@ -850,8 +850,8 @@ class IntSet: def contains(self, x): for lo, hi in self.pairs: - if lo <= x <= hi: return 1 - return 0 + if lo <= x <= hi: return True + return False def append(self, x): for i in range(len(self.pairs)): diff --git a/Lib/mutex.py b/Lib/mutex.py index 2348a2e004..47d2ca2371 100644 --- a/Lib/mutex.py +++ b/Lib/mutex.py @@ -24,12 +24,12 @@ class mutex: def testandset(self): """Atomic test-and-set -- grab the lock if it is not set, - return true if it succeeded.""" + return True if it succeeded.""" if not self.locked: self.locked = 1 - return 1 + return True else: - return 0 + return False def lock(self, function, argument): """Lock a mutex, call the function with supplied argument diff --git a/Lib/ntpath.py b/Lib/ntpath.py index 5a63105d08..8cd8e9ad68 100644 --- a/Lib/ntpath.py +++ b/Lib/ntpath.py @@ -246,8 +246,8 @@ def exists(path): try: st = os.stat(path) except os.error: - return 0 - return 1 + return False + return True # Is a path a dos directory? @@ -445,9 +445,9 @@ else: def _exists(name): try: eval(name) - return 1 + return True except NameError: - return 0 + return False # Supply spawn*() (probably only for Unix) if _exists("fork") and not _exists("spawnv") and _exists("execv"): diff --git a/Lib/os2emxpath.py b/Lib/os2emxpath.py index e4d63c62be..01db974beb 100644 --- a/Lib/os2emxpath.py +++ b/Lib/os2emxpath.py @@ -205,8 +205,8 @@ def exists(path): try: st = os.stat(path) except os.error: - return 0 - return 1 + return False + return True # Is a path a directory? diff --git a/Lib/posixpath.py b/Lib/posixpath.py index c342bbcf19..cceb2d2be7 100644 --- a/Lib/posixpath.py +++ b/Lib/posixpath.py @@ -166,12 +166,12 @@ def islink(path): # This is false for dangling symbolic links. def exists(path): - """Test whether a path exists. Returns false for broken symbolic links""" + """Test whether a path exists. Returns False for broken symbolic links""" try: st = os.stat(path) except os.error: - return 0 - return 1 + return False + return True # Is a path a directory? @@ -237,16 +237,16 @@ def ismount(path): s1 = os.stat(path) s2 = os.stat(join(path, '..')) except os.error: - return 0 # It doesn't exist -- so not a mount point :-) + return False # It doesn't exist -- so not a mount point :-) dev1 = s1[stat.ST_DEV] dev2 = s2[stat.ST_DEV] if dev1 != dev2: - return 1 # path/.. on a different device as path + return True # path/.. on a different device as path ino1 = s1[stat.ST_INO] ino2 = s2[stat.ST_INO] if ino1 == ino2: - return 1 # path/.. is the same i-node as path - return 0 + return True # path/.. is the same i-node as path + return False # Directory tree walk. diff --git a/Lib/pydoc.py b/Lib/pydoc.py index c27da11ad6..587a24c01a 100755 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -148,7 +148,8 @@ def ispackage(path): if os.path.isdir(path): for ext in ['.py', '.pyc', '.pyo']: if os.path.isfile(os.path.join(path, '__init__' + ext)): - return 1 + return True + return False def synopsis(filename, cache={}): """Get the one-line summary out of a module file.""" diff --git a/Lib/robotparser.py b/Lib/robotparser.py index 5b759d4968..99bcdae2f1 100644 --- a/Lib/robotparser.py +++ b/Lib/robotparser.py @@ -134,9 +134,9 @@ class RobotFileParser: _debug("Checking robot.txt allowance for:\n user agent: %s\n url: %s" % (useragent, url)) if self.disallow_all: - return 0 + return False if self.allow_all: - return 1 + return True # search for given user agent matches # the first match counts url = urllib.quote(urlparse.urlparse(urllib.unquote(url))[2]) or "/" @@ -147,7 +147,7 @@ class RobotFileParser: if self.default_entry: return self.default_entry.allowance(url) # agent not found ==> access granted - return 1 + return True def __str__(self): @@ -195,11 +195,11 @@ class Entry: for agent in self.useragents: if agent=='*': # we have the catch-all agent - return 1 + return True agent = agent.lower() if useragent.find(agent) != -1: - return 1 - return 0 + return True + return False def allowance(self, filename): """Preconditions: diff --git a/Lib/symtable.py b/Lib/symtable.py index 15549eeb1d..44983358ca 100644 --- a/Lib/symtable.py +++ b/Lib/symtable.py @@ -35,19 +35,13 @@ class SymbolTableFactory: newSymbolTable = SymbolTableFactory() -def bool(x): - """Helper to force boolean result to 1 or 0""" - if x: - return 1 - return 0 - def is_free(flags): if (flags & (USE | DEF_FREE)) \ and (flags & (DEF_LOCAL | DEF_PARAM | DEF_GLOBAL)): - return 1 + return True if flags & DEF_FREE_CLASS: - return 1 - return 0 + return True + return False class SymbolTable: def __init__(self, raw_table, filename): @@ -206,10 +200,10 @@ class Symbol: def is_free(self): if (self.__flags & (USE | DEF_FREE)) \ and (self.__flags & (DEF_LOCAL | DEF_PARAM | DEF_GLOBAL)): - return 1 + return True if self.__flags & DEF_FREE_CLASS: - return 1 - return 0 + return True + return False def is_imported(self): return bool(self.__flags & DEF_IMPORT) diff --git a/Lib/tabnanny.py b/Lib/tabnanny.py index 7d2ca52dea..25955400bf 100755 --- a/Lib/tabnanny.py +++ b/Lib/tabnanny.py @@ -196,7 +196,7 @@ class Whitespace: other.indent_level(ts)) ) return a - # Return true iff self.indent_level(t) < other.indent_level(t) + # Return True iff self.indent_level(t) < other.indent_level(t) # for all t >= 1. # The algorithm is due to Vincent Broman. # Easy to prove it's correct. @@ -211,7 +211,7 @@ class Whitespace: # Note that M is of the form (T*)(S*) iff len(M.norm[0]) <= 1. def less(self, other): if self.n >= other.n: - return 0 + return False if self.is_simple and other.is_simple: return self.nt <= other.nt n = max(self.longest_run_of_spaces(), @@ -219,8 +219,8 @@ class Whitespace: # the self.n >= other.n test already did it for ts=1 for ts in range(2, n+1): if self.indent_level(ts) >= other.indent_level(ts): - return 0 - return 1 + return False + return True # return a list of tuples (ts, i1, i2) such that # i1 == self.indent_level(ts) >= other.indent_level(ts) == i2. diff --git a/Lib/threading.py b/Lib/threading.py index 9763c629d8..706d5bbc5e 100644 --- a/Lib/threading.py +++ b/Lib/threading.py @@ -174,9 +174,9 @@ class _Condition(_Verbose): def _is_owned(self): if self.__lock.acquire(0): self.__lock.release() - return 0 + return False else: - return 1 + return True def wait(self, timeout=None): me = currentThread() diff --git a/Lib/webbrowser.py b/Lib/webbrowser.py index 19443ca1e5..1509b7aa85 100644 --- a/Lib/webbrowser.py +++ b/Lib/webbrowser.py @@ -78,15 +78,15 @@ def _synthesize(browser): def _iscommand(cmd): - """Return true if cmd can be found on the executable search path.""" + """Return True if cmd can be found on the executable search path.""" path = os.environ.get("PATH") if not path: - return 0 + return False for d in path.split(os.pathsep): exe = os.path.join(d, cmd) if os.path.isfile(exe): - return 1 - return 0 + return True + return False PROCESS_CREATION_DELAY = 4 |