Convert a pile of obvious "yes/no" functions to return bool.

This commit is contained in:
Tim Peters 2002-04-04 22:55:58 +00:00
parent 2f486b7fa6
commit bc0e910826
34 changed files with 117 additions and 122 deletions

View File

@ -289,10 +289,10 @@ class CVS:
os.rename(file, bfile) os.rename(file, bfile)
def ignored(self, file): def ignored(self, file):
if os.path.isdir(file): return 1 if os.path.isdir(file): return True
for pat in self.IgnoreList: for pat in self.IgnoreList:
if fnmatch.fnmatch(file, pat): return 1 if fnmatch.fnmatch(file, pat): return True
return 0 return Falso
# hexify and unhexify are useful to print MD5 checksums in hex format # hexify and unhexify are useful to print MD5 checksums in hex format

View File

@ -222,7 +222,7 @@ class BaseHTTPRequestHandler(SocketServer.StreamRequestHandler):
are in self.command, self.path, self.request_version and are in self.command, self.path, self.request_version and
self.headers. 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. error is sent back.
""" """
@ -239,30 +239,30 @@ class BaseHTTPRequestHandler(SocketServer.StreamRequestHandler):
[command, path, version] = words [command, path, version] = words
if version[:5] != 'HTTP/': if version[:5] != 'HTTP/':
self.send_error(400, "Bad request version (%s)" % `version`) self.send_error(400, "Bad request version (%s)" % `version`)
return 0 return False
try: try:
version_number = float(version.split('/', 1)[1]) version_number = float(version.split('/', 1)[1])
except ValueError: except ValueError:
self.send_error(400, "Bad request version (%s)" % `version`) 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": if version_number >= 1.1 and self.protocol_version >= "HTTP/1.1":
self.close_connection = 0 self.close_connection = 0
if version_number >= 2.0: if version_number >= 2.0:
self.send_error(505, self.send_error(505,
"Invalid HTTP Version (%f)" % version_number) "Invalid HTTP Version (%f)" % version_number)
return 0 return False
elif len(words) == 2: elif len(words) == 2:
[command, path] = words [command, path] = words
self.close_connection = 1 self.close_connection = 1
if command != 'GET': if command != 'GET':
self.send_error(400, self.send_error(400,
"Bad HTTP/0.9 request type (%s)" % `command`) "Bad HTTP/0.9 request type (%s)" % `command`)
return 0 return False
elif not words: elif not words:
return 0 return False
else: else:
self.send_error(400, "Bad request syntax (%s)" % `requestline`) self.send_error(400, "Bad request syntax (%s)" % `requestline`)
return 0 return False
self.command, self.path, self.request_version = command, path, version self.command, self.path, self.request_version = command, path, version
# Deal with pipelining # Deal with pipelining
@ -283,7 +283,7 @@ class BaseHTTPRequestHandler(SocketServer.StreamRequestHandler):
elif (conntype.lower() == 'keep-alive' and elif (conntype.lower() == 'keep-alive' and
self.protocol_version >= "HTTP/1.1"): self.protocol_version >= "HTTP/1.1"):
self.close_connection = 0 self.close_connection = 0
return 1 return True
def handle_one_request(self): def handle_one_request(self):
"""Handle a single HTTP request. """Handle a single HTTP request.

View File

@ -86,8 +86,8 @@ class CGIHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
i = len(x) i = len(x)
if path[:i] == x and (not path[i:] or path[i] == '/'): if path[:i] == x and (not path[i:] or path[i] == '/'):
self.cgi_info = path[:i], path[i+1:] self.cgi_info = path[:i], path[i+1:]
return 1 return True
return 0 return False
cgi_directories = ['/cgi-bin', '/htbin'] cgi_directories = ['/cgi-bin', '/htbin']

View File

@ -374,9 +374,9 @@ class ConfigParser:
"""Remove a file section.""" """Remove a file section."""
if self.__sections.has_key(section): if self.__sections.has_key(section):
del self.__sections[section] del self.__sections[section]
return 1 return True
else: else:
return 0 return False
# #
# Regular expressions for parsing section headers and options. Note a # Regular expressions for parsing section headers and options. Note a

View File

@ -226,10 +226,10 @@ class BaseServer:
def verify_request(self, request, client_address): def verify_request(self, request, client_address):
"""Verify the request. May be overridden. """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): def process_request(self, request, client_address):
"""Call finish_request. """Call finish_request.

View File

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

View File

@ -92,31 +92,31 @@ class Bdb:
def stop_here(self, frame): def stop_here(self, frame):
if self.stopframe is None: if self.stopframe is None:
return 1 return True
if frame is self.stopframe: if frame is self.stopframe:
return 1 return True
while frame is not None and frame is not self.stopframe: while frame is not None and frame is not self.stopframe:
if frame is self.botframe: if frame is self.botframe:
return 1 return True
frame = frame.f_back frame = frame.f_back
return 0 return False
def break_here(self, frame): def break_here(self, frame):
filename = self.canonic(frame.f_code.co_filename) filename = self.canonic(frame.f_code.co_filename)
if not self.breaks.has_key(filename): if not self.breaks.has_key(filename):
return 0 return False
lineno = frame.f_lineno lineno = frame.f_lineno
if not lineno in self.breaks[filename]: if not lineno in self.breaks[filename]:
return 0 return False
# flag says ok to delete temp. bp # flag says ok to delete temp. bp
(bp, flag) = effective(filename, lineno, frame) (bp, flag) = effective(filename, lineno, frame)
if bp: if bp:
self.currentbp = bp.number self.currentbp = bp.number
if (flag and bp.temporary): if (flag and bp.temporary):
self.do_clear(str(bp.number)) self.do_clear(str(bp.number))
return 1 return True
else: else:
return 0 return False
def do_clear(self, arg): def do_clear(self, arg):
raise NotImplementedError, "subclass of bdb must implement do_clear()" raise NotImplementedError, "subclass of bdb must implement do_clear()"

View File

@ -600,8 +600,8 @@ class FieldStorage:
if self.list is None: if self.list is None:
raise TypeError, "not indexable" raise TypeError, "not indexable"
for item in self.list: for item in self.list:
if item.name == key: return 1 if item.name == key: return True
return 0 return False
def __len__(self): def __len__(self):
"""Dictionary style len(x) support.""" """Dictionary style len(x) support."""

View File

@ -66,7 +66,7 @@ class InteractiveInterpreter:
object. The code is executed by calling self.runcode() (which object. The code is executed by calling self.runcode() (which
also handles run-time exceptions, except for SystemExit). 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 an exception is raised). The return value can be used to
decide whether to use sys.ps1 or sys.ps2 to prompt the next decide whether to use sys.ps1 or sys.ps2 to prompt the next
line. line.
@ -77,15 +77,15 @@ class InteractiveInterpreter:
except (OverflowError, SyntaxError, ValueError): except (OverflowError, SyntaxError, ValueError):
# Case 1 # Case 1
self.showsyntaxerror(filename) self.showsyntaxerror(filename)
return 0 return False
if code is None: if code is None:
# Case 2 # Case 2
return 1 return True
# Case 3 # Case 3
self.runcode(code) self.runcode(code)
return 0 return False
def runcode(self, code): def runcode(self, code):
"""Execute a code object. """Execute a code object.

View File

@ -190,9 +190,9 @@ class build_py (Command):
if not os.path.isfile(module_file): if not os.path.isfile(module_file):
self.warn("file %s (for module %s) not found" % self.warn("file %s (for module %s) not found" %
(module_file, module)) (module_file, module))
return 0 return False
else: else:
return 1 return True
# check_module () # check_module ()

View File

@ -151,8 +151,8 @@ def exists(path):
try: try:
st = os.stat(path) st = os.stat(path)
except os.error: except os.error:
return 0 return False
return 1 return True
def isdir(path): def isdir(path):
@ -161,7 +161,7 @@ def isdir(path):
try: try:
st = os.stat(path) st = os.stat(path)
except os.error: except os.error:
return 0 return False
return stat.S_ISDIR(st[stat.ST_MODE]) return stat.S_ISDIR(st[stat.ST_MODE])
@ -171,7 +171,7 @@ def isfile(path):
try: try:
st = os.stat(path) st = os.stat(path)
except os.error: except os.error:
return 0 return False
return stat.S_ISREG(st[stat.ST_MODE]) return stat.S_ISREG(st[stat.ST_MODE])

View File

@ -35,7 +35,7 @@ def cmp(f1, f2, shallow=1, use_statcache=0):
Return value: 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, This function uses a cache for past comparisons and the results,
with a cache invalidation mechanism relying on stale signatures. 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)) s1 = _sig(stat_function(f1))
s2 = _sig(stat_function(f2)) s2 = _sig(stat_function(f2))
if s1[0] != stat.S_IFREG or s2[0] != stat.S_IFREG: if s1[0] != stat.S_IFREG or s2[0] != stat.S_IFREG:
return 0 return False
if shallow and s1 == s2: if shallow and s1 == s2:
return 1 return True
if s1[1] != s2[1]: if s1[1] != s2[1]:
return 0 return False
result = _cache.get((f1, f2)) result = _cache.get((f1, f2))
if result and (s1, s2) == result[:2]: if result and (s1, s2) == result[:2]:

View File

@ -103,9 +103,9 @@ def long_has_args(opt, longopts):
raise GetoptError('option --%s not recognized' % opt, opt) raise GetoptError('option --%s not recognized' % opt, opt)
# Is there an exact match? # Is there an exact match?
if opt in possibilities: if opt in possibilities:
return 0, opt return False, opt
elif opt + '=' in possibilities: elif opt + '=' in possibilities:
return 1, opt return True, opt
# No exact match, so better be unique. # No exact match, so better be unique.
if len(possibilities) > 1: if len(possibilities) > 1:
# XXX since possibilities contains all valid continuations, might be # XXX since possibilities contains all valid continuations, might be

View File

@ -139,13 +139,13 @@ def isfile(s):
def exists(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: try:
st = os.stat(s) st = os.stat(s)
except os.error: except os.error:
return 0 return False
return 1 return True
# Return the longest prefix of all list elements. # Return the longest prefix of all list elements.

View File

@ -151,7 +151,7 @@ class UnixMailbox(_Mailbox):
return self._regexp.match(line) return self._regexp.match(line)
def _portable_isrealfromline(self, line): def _portable_isrealfromline(self, line):
return 1 return True
_isrealfromline = _strict_isrealfromline _isrealfromline = _strict_isrealfromline

View File

@ -850,8 +850,8 @@ class IntSet:
def contains(self, x): def contains(self, x):
for lo, hi in self.pairs: for lo, hi in self.pairs:
if lo <= x <= hi: return 1 if lo <= x <= hi: return True
return 0 return False
def append(self, x): def append(self, x):
for i in range(len(self.pairs)): for i in range(len(self.pairs)):

View File

@ -24,12 +24,12 @@ class mutex:
def testandset(self): def testandset(self):
"""Atomic test-and-set -- grab the lock if it is not set, """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: if not self.locked:
self.locked = 1 self.locked = 1
return 1 return True
else: else:
return 0 return False
def lock(self, function, argument): def lock(self, function, argument):
"""Lock a mutex, call the function with supplied argument """Lock a mutex, call the function with supplied argument

View File

@ -246,8 +246,8 @@ def exists(path):
try: try:
st = os.stat(path) st = os.stat(path)
except os.error: except os.error:
return 0 return False
return 1 return True
# Is a path a dos directory? # Is a path a dos directory?

View File

@ -445,9 +445,9 @@ else:
def _exists(name): def _exists(name):
try: try:
eval(name) eval(name)
return 1 return True
except NameError: except NameError:
return 0 return False
# Supply spawn*() (probably only for Unix) # Supply spawn*() (probably only for Unix)
if _exists("fork") and not _exists("spawnv") and _exists("execv"): if _exists("fork") and not _exists("spawnv") and _exists("execv"):

View File

@ -205,8 +205,8 @@ def exists(path):
try: try:
st = os.stat(path) st = os.stat(path)
except os.error: except os.error:
return 0 return False
return 1 return True
# Is a path a directory? # Is a path a directory?

View File

@ -166,12 +166,12 @@ def islink(path):
# This is false for dangling symbolic links. # This is false for dangling symbolic links.
def exists(path): 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: try:
st = os.stat(path) st = os.stat(path)
except os.error: except os.error:
return 0 return False
return 1 return True
# Is a path a directory? # Is a path a directory?
@ -237,16 +237,16 @@ def ismount(path):
s1 = os.stat(path) s1 = os.stat(path)
s2 = os.stat(join(path, '..')) s2 = os.stat(join(path, '..'))
except os.error: 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] dev1 = s1[stat.ST_DEV]
dev2 = s2[stat.ST_DEV] dev2 = s2[stat.ST_DEV]
if dev1 != dev2: 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] ino1 = s1[stat.ST_INO]
ino2 = s2[stat.ST_INO] ino2 = s2[stat.ST_INO]
if ino1 == ino2: if ino1 == ino2:
return 1 # path/.. is the same i-node as path return True # path/.. is the same i-node as path
return 0 return False
# Directory tree walk. # Directory tree walk.

View File

@ -148,7 +148,8 @@ def ispackage(path):
if os.path.isdir(path): if os.path.isdir(path):
for ext in ['.py', '.pyc', '.pyo']: for ext in ['.py', '.pyc', '.pyo']:
if os.path.isfile(os.path.join(path, '__init__' + ext)): if os.path.isfile(os.path.join(path, '__init__' + ext)):
return 1 return True
return False
def synopsis(filename, cache={}): def synopsis(filename, cache={}):
"""Get the one-line summary out of a module file.""" """Get the one-line summary out of a module file."""

View File

@ -134,9 +134,9 @@ class RobotFileParser:
_debug("Checking robot.txt allowance for:\n user agent: %s\n url: %s" % _debug("Checking robot.txt allowance for:\n user agent: %s\n url: %s" %
(useragent, url)) (useragent, url))
if self.disallow_all: if self.disallow_all:
return 0 return False
if self.allow_all: if self.allow_all:
return 1 return True
# search for given user agent matches # search for given user agent matches
# the first match counts # the first match counts
url = urllib.quote(urlparse.urlparse(urllib.unquote(url))[2]) or "/" url = urllib.quote(urlparse.urlparse(urllib.unquote(url))[2]) or "/"
@ -147,7 +147,7 @@ class RobotFileParser:
if self.default_entry: if self.default_entry:
return self.default_entry.allowance(url) return self.default_entry.allowance(url)
# agent not found ==> access granted # agent not found ==> access granted
return 1 return True
def __str__(self): def __str__(self):
@ -195,11 +195,11 @@ class Entry:
for agent in self.useragents: for agent in self.useragents:
if agent=='*': if agent=='*':
# we have the catch-all agent # we have the catch-all agent
return 1 return True
agent = agent.lower() agent = agent.lower()
if useragent.find(agent) != -1: if useragent.find(agent) != -1:
return 1 return True
return 0 return False
def allowance(self, filename): def allowance(self, filename):
"""Preconditions: """Preconditions:

View File

@ -35,19 +35,13 @@ class SymbolTableFactory:
newSymbolTable = 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): def is_free(flags):
if (flags & (USE | DEF_FREE)) \ if (flags & (USE | DEF_FREE)) \
and (flags & (DEF_LOCAL | DEF_PARAM | DEF_GLOBAL)): and (flags & (DEF_LOCAL | DEF_PARAM | DEF_GLOBAL)):
return 1 return True
if flags & DEF_FREE_CLASS: if flags & DEF_FREE_CLASS:
return 1 return True
return 0 return False
class SymbolTable: class SymbolTable:
def __init__(self, raw_table, filename): def __init__(self, raw_table, filename):
@ -206,10 +200,10 @@ class Symbol:
def is_free(self): def is_free(self):
if (self.__flags & (USE | DEF_FREE)) \ if (self.__flags & (USE | DEF_FREE)) \
and (self.__flags & (DEF_LOCAL | DEF_PARAM | DEF_GLOBAL)): and (self.__flags & (DEF_LOCAL | DEF_PARAM | DEF_GLOBAL)):
return 1 return True
if self.__flags & DEF_FREE_CLASS: if self.__flags & DEF_FREE_CLASS:
return 1 return True
return 0 return False
def is_imported(self): def is_imported(self):
return bool(self.__flags & DEF_IMPORT) return bool(self.__flags & DEF_IMPORT)

View File

@ -196,7 +196,7 @@ class Whitespace:
other.indent_level(ts)) ) other.indent_level(ts)) )
return a 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. # for all t >= 1.
# The algorithm is due to Vincent Broman. # The algorithm is due to Vincent Broman.
# Easy to prove it's correct. # 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. # Note that M is of the form (T*)(S*) iff len(M.norm[0]) <= 1.
def less(self, other): def less(self, other):
if self.n >= other.n: if self.n >= other.n:
return 0 return False
if self.is_simple and other.is_simple: if self.is_simple and other.is_simple:
return self.nt <= other.nt return self.nt <= other.nt
n = max(self.longest_run_of_spaces(), 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 # the self.n >= other.n test already did it for ts=1
for ts in range(2, n+1): for ts in range(2, n+1):
if self.indent_level(ts) >= other.indent_level(ts): if self.indent_level(ts) >= other.indent_level(ts):
return 0 return False
return 1 return True
# return a list of tuples (ts, i1, i2) such that # return a list of tuples (ts, i1, i2) such that
# i1 == self.indent_level(ts) >= other.indent_level(ts) == i2. # i1 == self.indent_level(ts) >= other.indent_level(ts) == i2.

View File

@ -174,9 +174,9 @@ class _Condition(_Verbose):
def _is_owned(self): def _is_owned(self):
if self.__lock.acquire(0): if self.__lock.acquire(0):
self.__lock.release() self.__lock.release()
return 0 return False
else: else:
return 1 return True
def wait(self, timeout=None): def wait(self, timeout=None):
me = currentThread() me = currentThread()

View File

@ -78,15 +78,15 @@ def _synthesize(browser):
def _iscommand(cmd): 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") path = os.environ.get("PATH")
if not path: if not path:
return 0 return False
for d in path.split(os.pathsep): for d in path.split(os.pathsep):
exe = os.path.join(d, cmd) exe = os.path.join(d, cmd)
if os.path.isfile(exe): if os.path.isfile(exe):
return 1 return True
return 0 return False
PROCESS_CREATION_DELAY = 4 PROCESS_CREATION_DELAY = 4

View File

@ -56,10 +56,10 @@ def getnum(s):
# Function to check if a string is a number # Function to check if a string is a number
# #
def isnum(s): def isnum(s):
if not s: return 0 if not s: return False
for c in s: for c in s:
if not c in digits: return 0 if not c in digits: return False
return 1 return True
# Allowed function return types # Allowed function return types

View File

@ -375,16 +375,16 @@ class EditorWindow:
def ispythonsource(self, filename): def ispythonsource(self, filename):
if not filename: if not filename:
return 1 return True
base, ext = os.path.splitext(os.path.basename(filename)) base, ext = os.path.splitext(os.path.basename(filename))
if os.path.normcase(ext) in (".py", ".pyw"): if os.path.normcase(ext) in (".py", ".pyw"):
return 1 return True
try: try:
f = open(filename) f = open(filename)
line = f.readline() line = f.readline()
f.close() f.close()
except IOError: except IOError:
return 0 return False
return line[:2] == '#!' and string.find(line, 'python') >= 0 return line[:2] == '#!' and string.find(line, 'python') >= 0
def close_hook(self): def close_hook(self):

View File

@ -92,7 +92,7 @@ class IOBinding:
f.close() f.close()
except IOError, msg: except IOError, msg:
tkMessageBox.showerror("I/O Error", str(msg), master=self.text) tkMessageBox.showerror("I/O Error", str(msg), master=self.text)
return 0 return False
self.text.delete("1.0", "end") self.text.delete("1.0", "end")
self.set_filename(None) self.set_filename(None)
self.text.insert("1.0", chars) self.text.insert("1.0", chars)
@ -100,7 +100,7 @@ class IOBinding:
self.set_filename(filename) self.set_filename(filename)
self.text.mark_set("insert", "1.0") self.text.mark_set("insert", "1.0")
self.text.see("insert") self.text.see("insert")
return 1 return True
def maybesave(self): def maybesave(self):
if self.get_saved(): if self.get_saved():
@ -154,11 +154,11 @@ class IOBinding:
f.write(chars) f.write(chars)
f.close() f.close()
## print "saved to", `filename` ## print "saved to", `filename`
return 1 return True
except IOError, msg: except IOError, msg:
tkMessageBox.showerror("I/O Error", str(msg), tkMessageBox.showerror("I/O Error", str(msg),
master=self.text) master=self.text)
return 0 return False
def fixlastline(self): def fixlastline(self):
c = self.text.get("end-2c") c = self.text.get("end-2c")

View File

@ -59,7 +59,7 @@ class ObjectTreeItem(TreeItem):
class InstanceTreeItem(ObjectTreeItem): class InstanceTreeItem(ObjectTreeItem):
def IsExpandable(self): def IsExpandable(self):
return 1 return True
def GetSubList(self): def GetSubList(self):
sublist = ObjectTreeItem.GetSubList(self) sublist = ObjectTreeItem.GetSubList(self)
sublist.insert(0, sublist.insert(0,
@ -68,7 +68,7 @@ class InstanceTreeItem(ObjectTreeItem):
class ClassTreeItem(ObjectTreeItem): class ClassTreeItem(ObjectTreeItem):
def IsExpandable(self): def IsExpandable(self):
return 1 return True
def GetSubList(self): def GetSubList(self):
sublist = ObjectTreeItem.GetSubList(self) sublist = ObjectTreeItem.GetSubList(self)
if len(self.object.__bases__) == 1: if len(self.object.__bases__) == 1:

View File

@ -439,7 +439,7 @@ class PyShell(OutputWindow):
def ispythonsource(self, filename): def ispythonsource(self, filename):
# Override this so EditorWindow never removes the colorizer # Override this so EditorWindow never removes the colorizer
return 1 return True
def short_title(self): def short_title(self):
return self.shell_title return self.shell_title
@ -482,7 +482,7 @@ class PyShell(OutputWindow):
return line return line
def isatty(self): def isatty(self):
return 1 return True
def cancel_callback(self, event): def cancel_callback(self, event):
try: try:
@ -685,7 +685,7 @@ class PseudoFile:
pass pass
def isatty(self): def isatty(self):
return 1 return True
usage_msg = """\ usage_msg = """\

View File

@ -111,24 +111,24 @@ class ReplaceDialog(SearchDialogBase):
def do_find(self, ok=0): def do_find(self, ok=0):
if not self.engine.getprog(): if not self.engine.getprog():
return 0 return False
text = self.text text = self.text
res = self.engine.search_text(text, None, ok) res = self.engine.search_text(text, None, ok)
if not res: if not res:
text.bell() text.bell()
return 0 return False
line, m = res line, m = res
i, j = m.span() i, j = m.span()
first = "%d.%d" % (line, i) first = "%d.%d" % (line, i)
last = "%d.%d" % (line, j) last = "%d.%d" % (line, j)
self.show_hit(first, last) self.show_hit(first, last)
self.ok = 1 self.ok = 1
return 1 return True
def do_replace(self): def do_replace(self):
prog = self.engine.getprog() prog = self.engine.getprog()
if not prog: if not prog:
return 0 return False
text = self.text text = self.text
try: try:
first = pos = text.index("sel.first") first = pos = text.index("sel.first")
@ -141,7 +141,7 @@ class ReplaceDialog(SearchDialogBase):
chars = text.get("%d.0" % line, "%d.0" % (line+1)) chars = text.get("%d.0" % line, "%d.0" % (line+1))
m = prog.match(chars, col) m = prog.match(chars, col)
if not prog: if not prog:
return 0 return False
new = self._expand(m, self.replvar.get()) new = self._expand(m, self.replvar.get())
text.mark_set("insert", first) text.mark_set("insert", first)
text.undo_block_start() text.undo_block_start()
@ -152,7 +152,7 @@ class ReplaceDialog(SearchDialogBase):
text.undo_block_stop() text.undo_block_stop()
self.show_hit(first, text.index("insert")) self.show_hit(first, text.index("insert"))
self.ok = 0 self.ok = 0
return 1 return True
def _expand(self, m, template): def _expand(self, m, template):
# XXX This code depends on internals of the regular expression # XXX This code depends on internals of the regular expression

View File

@ -34,9 +34,9 @@ class SearchDialog(SearchDialogBase):
def find_again(self, text): def find_again(self, text):
if not self.engine.getpat(): if not self.engine.getpat():
self.open(text) self.open(text)
return 0 return False
if not self.engine.getprog(): if not self.engine.getprog():
return 0 return False
res = self.engine.search_text(text) res = self.engine.search_text(text)
if res: if res:
line, m = res line, m = res
@ -48,17 +48,17 @@ class SearchDialog(SearchDialogBase):
sellast = text.index("sel.last") sellast = text.index("sel.last")
if selfirst == first and sellast == last: if selfirst == first and sellast == last:
text.bell() text.bell()
return 0 return False
except TclError: except TclError:
pass pass
text.tag_remove("sel", "1.0", "end") text.tag_remove("sel", "1.0", "end")
text.tag_add("sel", first, last) text.tag_add("sel", first, last)
text.mark_set("insert", self.engine.isback() and first or last) text.mark_set("insert", self.engine.isback() and first or last)
text.see("insert") text.see("insert")
return 1 return True
else: else:
text.bell() text.bell()
return 0 return False
def find_selection(self, text): def find_selection(self, text):
pat = text.get("sel.first", "sel.last") pat = text.get("sel.first", "sel.last")