Skip to content

Commit

Permalink
Convert a pile of obvious "yes/no" functions to return bool.
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-one committed Apr 4, 2002
1 parent 2f486b7 commit bc0e910
Show file tree
Hide file tree
Showing 34 changed files with 117 additions and 122 deletions.
6 changes: 3 additions & 3 deletions Demo/pdist/cvslib.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,10 @@ def backup(self, file):
os.rename(file, bfile)

def ignored(self, file):
if os.path.isdir(file): return 1
if os.path.isdir(file): return True
for pat in self.IgnoreList:
if fnmatch.fnmatch(file, pat): return 1
return 0
if fnmatch.fnmatch(file, pat): return True
return Falso


# hexify and unhexify are useful to print MD5 checksums in hex format
Expand Down
16 changes: 8 additions & 8 deletions Lib/BaseHTTPServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def parse_request(self):
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.
"""
Expand All @@ -239,30 +239,30 @@ def parse_request(self):
[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
Expand All @@ -283,7 +283,7 @@ def parse_request(self):
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.
Expand Down
4 changes: 2 additions & 2 deletions Lib/CGIHTTPServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ def is_cgi(self):
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']

Expand Down
4 changes: 2 additions & 2 deletions Lib/ConfigParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,9 @@ def remove_section(self, section):
"""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
Expand Down
4 changes: 2 additions & 2 deletions Lib/SocketServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,10 @@ def handle_request(self):
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.
Expand Down
4 changes: 2 additions & 2 deletions Lib/asyncore.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def set_reuse_addr (self):
# ==================================================

def readable (self):
return 1
return True

if os.name == 'mac':
# The macintosh will select a listening socket for
Expand All @@ -290,7 +290,7 @@ def writable (self):
return not self.accepting
else:
def writable (self):
return 1
return True

# ==================================================
# socket object methods.
Expand Down
16 changes: 8 additions & 8 deletions Lib/bdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,31 +92,31 @@ def dispatch_exception(self, frame, arg):

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()"
Expand Down
4 changes: 2 additions & 2 deletions Lib/cgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,8 +600,8 @@ def has_key(self, key):
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."""
Expand Down
8 changes: 4 additions & 4 deletions Lib/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def runsource(self, source, filename="<input>", symbol="single"):
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.
Expand All @@ -77,15 +77,15 @@ def runsource(self, source, filename="<input>", symbol="single"):
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.
Expand Down
4 changes: 2 additions & 2 deletions Lib/distutils/command/build_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@ def check_module (self, module, module_file):
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 ()

Expand Down
8 changes: 4 additions & 4 deletions Lib/dospath.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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])


Expand All @@ -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])


Expand Down
8 changes: 4 additions & 4 deletions Lib/filecmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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]:
Expand Down
4 changes: 2 additions & 2 deletions Lib/getopt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions Lib/macpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion Lib/mailbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def _strict_isrealfromline(self, line):
return self._regexp.match(line)

def _portable_isrealfromline(self, line):
return 1
return True

_isrealfromline = _strict_isrealfromline

Expand Down
4 changes: 2 additions & 2 deletions Lib/mhlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -850,8 +850,8 @@ def max(self):

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)):
Expand Down
6 changes: 3 additions & 3 deletions Lib/mutex.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ def test(self):

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
Expand Down
4 changes: 2 additions & 2 deletions Lib/ntpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
4 changes: 2 additions & 2 deletions Lib/os.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,9 +445,9 @@ def getenv(key, default=None):
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"):
Expand Down
4 changes: 2 additions & 2 deletions Lib/os2emxpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
Loading

0 comments on commit bc0e910

Please sign in to comment.