Partial introduction of bools where appropriate.

This commit is contained in:
Guido van Rossum 2002-04-07 06:36:23 +00:00
parent b8bff3f4a9
commit 8ca162f417
18 changed files with 96 additions and 94 deletions

View File

@ -307,7 +307,7 @@ def executable(path):
try: try:
st = os.stat(path) st = os.stat(path)
except os.error: except os.error:
return 0 return False
return st[0] & 0111 != 0 return st[0] & 0111 != 0

View File

@ -59,7 +59,7 @@ def close(self):
def isatty(self): def isatty(self):
if self.closed: if self.closed:
raise ValueError, "I/O operation on closed file" raise ValueError, "I/O operation on closed file"
return 0 return False
def seek(self, pos, mode = 0): def seek(self, pos, mode = 0):
if self.closed: if self.closed:

View File

@ -25,13 +25,13 @@
exception. exception.
Usage: Usage:
while 1: while True:
try: try:
chunk = Chunk(file) chunk = Chunk(file)
except EOFError: except EOFError:
break break
chunktype = chunk.getname() chunktype = chunk.getname()
while 1: while True:
data = chunk.read(nbytes) data = chunk.read(nbytes)
if not data: if not data:
pass pass
@ -49,9 +49,9 @@
""" """
class Chunk: class Chunk:
def __init__(self, file, align = 1, bigendian = 1, inclheader = 0): def __init__(self, file, align=True, bigendian=True, inclheader=False):
import struct import struct
self.closed = 0 self.closed = False
self.align = align # whether to align to word (2-byte) boundaries self.align = align # whether to align to word (2-byte) boundaries
if bigendian: if bigendian:
strflag = '>' strflag = '>'
@ -71,9 +71,9 @@ def __init__(self, file, align = 1, bigendian = 1, inclheader = 0):
try: try:
self.offset = self.file.tell() self.offset = self.file.tell()
except (AttributeError, IOError): except (AttributeError, IOError):
self.seekable = 0 self.seekable = False
else: else:
self.seekable = 1 self.seekable = True
def getname(self): def getname(self):
"""Return the name (ID) of the current chunk.""" """Return the name (ID) of the current chunk."""
@ -86,12 +86,12 @@ def getsize(self):
def close(self): def close(self):
if not self.closed: if not self.closed:
self.skip() self.skip()
self.closed = 1 self.closed = True
def isatty(self): def isatty(self):
if self.closed: if self.closed:
raise ValueError, "I/O operation on closed file" 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. """Seek to specified position into the chunk.

View File

@ -141,7 +141,7 @@ def islink(path):
"""Is a path a symbolic link? """Is a path a symbolic link?
This will always return false on systems where posix.lstat doesn't exist.""" This will always return false on systems where posix.lstat doesn't exist."""
return 0 return False
def exists(path): def exists(path):

View File

@ -154,7 +154,7 @@ def __init__(self, files=None, inplace=0, backup="", bufsize=0):
self._lineno = 0 self._lineno = 0
self._filelineno = 0 self._filelineno = 0
self._file = None self._file = None
self._isstdin = 0 self._isstdin = False
self._backupfilename = None self._backupfilename = None
self._buffer = [] self._buffer = []
self._bufindex = 0 self._bufindex = 0
@ -214,7 +214,7 @@ def nextfile(self):
try: os.unlink(backupfilename) try: os.unlink(backupfilename)
except: pass except: pass
self._isstdin = 0 self._isstdin = False
self._buffer = [] self._buffer = []
self._bufindex = 0 self._bufindex = 0
@ -235,12 +235,12 @@ def readline(self):
self._files = self._files[1:] self._files = self._files[1:]
self._filelineno = 0 self._filelineno = 0
self._file = None self._file = None
self._isstdin = 0 self._isstdin = False
self._backupfilename = 0 self._backupfilename = 0
if self._filename == '-': if self._filename == '-':
self._filename = '<stdin>' self._filename = '<stdin>'
self._file = sys.stdin self._file = sys.stdin
self._isstdin = 1 self._isstdin = True
else: else:
if self._inplace: if self._inplace:
self._backupfilename = ( self._backupfilename = (

View File

@ -47,7 +47,7 @@ def __init__(self, filename=None, mode=None,
if mode[0:1] == 'r': if mode[0:1] == 'r':
self.mode = READ self.mode = READ
# Set flag indicating start of a new member # Set flag indicating start of a new member
self._new_member = 1 self._new_member = True
self.extrabuf = "" self.extrabuf = ""
self.extrasize = 0 self.extrasize = 0
self.filename = filename self.filename = filename
@ -120,12 +120,12 @@ def _read_gzip_header(self):
self.fileobj.read(xlen) self.fileobj.read(xlen)
if flag & FNAME: if flag & FNAME:
# Read and discard a null-terminated string containing the filename # Read and discard a null-terminated string containing the filename
while (1): while True:
s=self.fileobj.read(1) s=self.fileobj.read(1)
if not s or s=='\000': break if not s or s=='\000': break
if flag & FCOMMENT: if flag & FCOMMENT:
# Read and discard a null-terminated string containing a comment # Read and discard a null-terminated string containing a comment
while (1): while True:
s=self.fileobj.read(1) s=self.fileobj.read(1)
if not s or s=='\000': break if not s or s=='\000': break
if flag & FHCRC: if flag & FHCRC:
@ -156,7 +156,7 @@ def read(self, size=-1):
readsize = 1024 readsize = 1024
if size < 0: # get the whole thing if size < 0: # get the whole thing
try: try:
while 1: while True:
self._read(readsize) self._read(readsize)
readsize = readsize * 2 readsize = readsize * 2
except EOFError: except EOFError:
@ -201,7 +201,7 @@ def _read(self, size=1024):
self._init_read() self._init_read()
self._read_gzip_header() self._read_gzip_header()
self.decompress = zlib.decompressobj(-zlib.MAX_WBITS) self.decompress = zlib.decompressobj(-zlib.MAX_WBITS)
self._new_member = 0 self._new_member = False
# Read a chunk of data from the file # Read a chunk of data from the file
buf = self.fileobj.read(size) buf = self.fileobj.read(size)
@ -229,7 +229,7 @@ def _read(self, size=1024):
# Check the CRC and file size, and set the flag so we read # Check the CRC and file size, and set the flag so we read
# a new member on the next call # a new member on the next call
self._read_eof() self._read_eof()
self._new_member = 1 self._new_member = True
def _add_read_data(self, data): def _add_read_data(self, data):
self.crc = zlib.crc32(data, self.crc) self.crc = zlib.crc32(data, self.crc)
@ -275,7 +275,7 @@ def flush(self):
self.fileobj.flush() self.fileobj.flush()
def isatty(self): def isatty(self):
return 0 return False
def tell(self): def tell(self):
return self.offset return self.offset
@ -286,7 +286,7 @@ def rewind(self):
if self.mode != READ: if self.mode != READ:
raise IOError("Can't rewind in write mode") raise IOError("Can't rewind in write mode")
self.fileobj.seek(0) self.fileobj.seek(0)
self._new_member = 1 self._new_member = True
self.extrabuf = "" self.extrabuf = ""
self.extrasize = 0 self.extrasize = 0
self.offset = 0 self.offset = 0
@ -311,7 +311,7 @@ def readline(self, size=-1):
if size < 0: size = sys.maxint if size < 0: size = sys.maxint
bufs = [] bufs = []
readsize = min(100, size) # Read from the file in small chunks readsize = min(100, size) # Read from the file in small chunks
while 1: while True:
if size == 0: if size == 0:
return "".join(bufs) # Return resulting line return "".join(bufs) # Return resulting line
@ -390,7 +390,7 @@ def _test():
else: else:
f = __builtin__.open(arg, "rb") f = __builtin__.open(arg, "rb")
g = open(arg + ".gz", "wb") g = open(arg + ".gz", "wb")
while 1: while True:
chunk = f.read(1024) chunk = f.read(1024)
if not chunk: if not chunk:
break break

View File

@ -125,7 +125,7 @@ def islink(s):
"""Return true if the pathname refers to a symbolic link. """Return true if the pathname refers to a symbolic link.
Always false on the Mac, until we understand Aliases.)""" Always false on the Mac, until we understand Aliases.)"""
return 0 return False
def isfile(s): def isfile(s):
@ -134,7 +134,7 @@ def isfile(s):
try: try:
st = os.stat(s) st = os.stat(s)
except os.error: except os.error:
return 0 return False
return S_ISREG(st[ST_MODE]) return S_ISREG(st[ST_MODE])

View File

@ -235,7 +235,7 @@ def getatime(filename):
def islink(path): def islink(path):
"""Test for symbolic link. On WindowsNT/95 always returns false""" """Test for symbolic link. On WindowsNT/95 always returns false"""
return 0 return False
# Does a path exist? # Does a path exist?
@ -259,7 +259,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])
@ -272,7 +272,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

@ -194,7 +194,7 @@ def getatime(filename):
def islink(path): def islink(path):
"""Test for symbolic link. On OS/2 always returns false""" """Test for symbolic link. On OS/2 always returns false"""
return 0 return False
# Does a path exist? # Does a path exist?
@ -216,7 +216,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])
@ -229,7 +229,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

@ -158,7 +158,7 @@ def islink(path):
try: try:
st = os.lstat(path) st = os.lstat(path)
except (os.error, AttributeError): except (os.error, AttributeError):
return 0 return False
return stat.S_ISLNK(st[stat.ST_MODE]) return stat.S_ISLNK(st[stat.ST_MODE])
@ -183,7 +183,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])
@ -196,7 +196,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])
@ -335,7 +335,7 @@ def expandvars(path):
import re import re
_varprog = re.compile(r'\$(\w+|\{[^}]*\})') _varprog = re.compile(r'\$(\w+|\{[^}]*\})')
i = 0 i = 0
while 1: while True:
m = _varprog.search(path, i) m = _varprog.search(path, i)
if not m: if not m:
break break

View File

@ -126,8 +126,8 @@ def __format(self, object, stream, indent, allowance, context, level):
objid = _id(object) objid = _id(object)
if objid in context: if objid in context:
stream.write(_recursion(object)) stream.write(_recursion(object))
self.__recursive = 1 self.__recursive = True
self.__readable = 0 self.__readable = False
return return
rep = self.__repr(object, context, level - 1) rep = self.__repr(object, context, level - 1)
typ = _type(object) typ = _type(object)
@ -195,9 +195,9 @@ def __repr(self, object, context, level):
repr, readable, recursive = self.format(object, context.copy(), repr, readable, recursive = self.format(object, context.copy(),
self.__depth, level) self.__depth, level)
if not readable: if not readable:
self.__readable = 0 self.__readable = False
if recursive: if recursive:
self.__recursive = 1 self.__recursive = True
return repr return repr
def format(self, object, context, maxlevels, level): def format(self, object, context, maxlevels, level):
@ -214,7 +214,7 @@ def _safe_repr(object, context, maxlevels, level):
typ = _type(object) typ = _type(object)
if typ is StringType: if typ is StringType:
if 'locale' not in _sys_modules: if 'locale' not in _sys_modules:
return `object`, 1, 0 return `object`, True, False
if "'" in object and '"' not in object: if "'" in object and '"' not in object:
closure = '"' closure = '"'
quotes = {'"': '\\"'} quotes = {'"': '\\"'}
@ -229,19 +229,19 @@ def _safe_repr(object, context, maxlevels, level):
write(char) write(char)
else: else:
write(qget(char, `char`[1:-1])) 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 typ is DictType:
if not object: if not object:
return "{}", 1, 0 return "{}", True, False
objid = _id(object) objid = _id(object)
if maxlevels and level > maxlevels: if maxlevels and level > maxlevels:
return "{...}", 0, objid in context return "{...}", False, objid in context
if objid in context: if objid in context:
return _recursion(object), 0, 1 return _recursion(object), False, True
context[objid] = 1 context[objid] = 1
readable = 1 readable = True
recursive = 0 recursive = False
components = [] components = []
append = components.append append = components.append
level += 1 level += 1
@ -252,29 +252,29 @@ def _safe_repr(object, context, maxlevels, level):
append("%s: %s" % (krepr, vrepr)) append("%s: %s" % (krepr, vrepr))
readable = readable and kreadable and vreadable readable = readable and kreadable and vreadable
if krecur or vrecur: if krecur or vrecur:
recursive = 1 recursive = True
del context[objid] del context[objid]
return "{%s}" % _commajoin(components), readable, recursive return "{%s}" % _commajoin(components), readable, recursive
if typ is ListType or typ is TupleType: if typ is ListType or typ is TupleType:
if typ is ListType: if typ is ListType:
if not object: if not object:
return "[]", 1, 0 return "[]", True, False
format = "[%s]" format = "[%s]"
elif _len(object) == 1: elif _len(object) == 1:
format = "(%s,)" format = "(%s,)"
else: else:
if not object: if not object:
return "()", 1, 0 return "()", True, False
format = "(%s)" format = "(%s)"
objid = _id(object) objid = _id(object)
if maxlevels and level > maxlevels: if maxlevels and level > maxlevels:
return format % "...", 0, objid in context return format % "...", False, objid in context
if objid in context: if objid in context:
return _recursion(object), 0, 1 return _recursion(object), False, True
context[objid] = 1 context[objid] = 1
readable = 1 readable = True
recursive = 0 recursive = False
components = [] components = []
append = components.append append = components.append
level += 1 level += 1
@ -282,14 +282,14 @@ def _safe_repr(object, context, maxlevels, level):
orepr, oreadable, orecur = _safe_repr(o, context, maxlevels, level) orepr, oreadable, orecur = _safe_repr(o, context, maxlevels, level)
append(orepr) append(orepr)
if not oreadable: if not oreadable:
readable = 0 readable = False
if orecur: if orecur:
recursive = 1 recursive = True
del context[objid] del context[objid]
return format % _commajoin(components), readable, recursive return format % _commajoin(components), readable, recursive
rep = `object` rep = `object`
return rep, (rep and not rep.startswith('<')), 0 return rep, (rep and not rep.startswith('<')), False
def _recursion(object): def _recursion(object):

View File

@ -443,7 +443,7 @@ def markup(self, text, escape=None, funcs={}, classes={}, methods={}):
r'RFC[- ]?(\d+)|' r'RFC[- ]?(\d+)|'
r'PEP[- ]?(\d+)|' r'PEP[- ]?(\d+)|'
r'(self\.)?(\w+))') r'(self\.)?(\w+))')
while 1: while True:
match = pattern.search(text, here) match = pattern.search(text, here)
if not match: break if not match: break
start, end = match.span() start, end = match.span()
@ -1521,7 +1521,7 @@ def __call__(self, request=None):
def interact(self): def interact(self):
self.output.write('\n') self.output.write('\n')
while 1: while True:
self.output.write('help> ') self.output.write('help> ')
self.output.flush() self.output.flush()
try: try:
@ -1710,10 +1710,11 @@ def isnewpackage(self, (dir, package)):
if not (os.path.islink(dir) and inode in self.inodes): if not (os.path.islink(dir) and inode in self.inodes):
self.inodes.append(inode) # detect circular symbolic links self.inodes.append(inode) # detect circular symbolic links
return ispackage(dir) return ispackage(dir)
return False
def run(self, callback, key=None, completer=None): def run(self, callback, key=None, completer=None):
if key: key = lower(key) if key: key = lower(key)
self.quit = 0 self.quit = False
seen = {} seen = {}
for modname in sys.builtin_module_names: for modname in sys.builtin_module_names:
@ -1825,7 +1826,7 @@ def __init__(self, port, callback):
def serve_until_quit(self): def serve_until_quit(self):
import select import select
self.quit = 0 self.quit = False
while not self.quit: while not self.quit:
rd, wr, ex = select.select([self.socket.fileno()], [], [], 1) rd, wr, ex = select.select([self.socket.fileno()], [], [], 1)
if rd: self.handle_request() if rd: self.handle_request()

View File

@ -222,7 +222,7 @@ def iscomment(self, line):
data in RFC 2822-like formats that support embedded comments or data in RFC 2822-like formats that support embedded comments or
free-text data. free-text data.
""" """
return None return False
def getallmatchingheaders(self, name): def getallmatchingheaders(self, name):
"""Find all header lines matching a given header name. """Find all header lines matching a given header name.

View File

@ -221,11 +221,11 @@ def isdigit(char):
def isname(name): def isname(name):
# check that group name is a valid string # check that group name is a valid string
if not isident(name[0]): if not isident(name[0]):
return 0 return False
for char in name: for char in name:
if not isident(char) and not isdigit(char): if not isident(char) and not isdigit(char):
return 0 return False
return 1 return True
def _group(escape, groups): def _group(escape, groups):
# check if the escape string represents a valid group # check if the escape string represents a valid group

View File

@ -73,5 +73,5 @@ def isdir(path):
try: try:
st = stat(path) st = stat(path)
except _os.error: except _os.error:
return 0 return False
return S_ISDIR(st[ST_MODE]) return S_ISDIR(st[ST_MODE])

View File

@ -30,7 +30,7 @@
# Debug support (adapted from ihooks.py) # Debug support (adapted from ihooks.py)
_VERBOSE = 0 _VERBOSE = 0 # XXX Bool or int?
if __debug__: if __debug__:
@ -198,7 +198,7 @@ def wait(self, timeout=None):
# than 20 times per second (or the timeout time remaining). # than 20 times per second (or the timeout time remaining).
endtime = _time() + timeout endtime = _time() + timeout
delay = 0.0005 # 500 us -> initial delay of 1 ms delay = 0.0005 # 500 us -> initial delay of 1 ms
while 1: while True:
gotit = waiter.acquire(0) gotit = waiter.acquire(0)
if gotit: if gotit:
break break
@ -256,7 +256,7 @@ def __init__(self, value=1, verbose=None):
self.__value = value self.__value = value
def acquire(self, blocking=1): def acquire(self, blocking=1):
rc = 0 rc = False
self.__cond.acquire() self.__cond.acquire()
while self.__value == 0: while self.__value == 0:
if not blocking: if not blocking:
@ -270,7 +270,7 @@ def acquire(self, blocking=1):
if __debug__: if __debug__:
self._note("%s.acquire: success, value=%s", self._note("%s.acquire: success, value=%s",
self, self.__value) self, self.__value)
rc = 1 rc = True
self.__cond.release() self.__cond.release()
return rc return rc
@ -309,20 +309,20 @@ class _Event(_Verbose):
def __init__(self, verbose=None): def __init__(self, verbose=None):
_Verbose.__init__(self, verbose) _Verbose.__init__(self, verbose)
self.__cond = Condition(Lock()) self.__cond = Condition(Lock())
self.__flag = 0 self.__flag = False
def isSet(self): def isSet(self):
return self.__flag return self.__flag
def set(self): def set(self):
self.__cond.acquire() self.__cond.acquire()
self.__flag = 1 self.__flag = True
self.__cond.notifyAll() self.__cond.notifyAll()
self.__cond.release() self.__cond.release()
def clear(self): def clear(self):
self.__cond.acquire() self.__cond.acquire()
self.__flag = 0 self.__flag = False
self.__cond.release() self.__cond.release()
def wait(self, timeout=None): def wait(self, timeout=None):
@ -348,7 +348,7 @@ def _newname(template="Thread-%d"):
class Thread(_Verbose): class Thread(_Verbose):
__initialized = 0 __initialized = False
def __init__(self, group=None, target=None, name=None, def __init__(self, group=None, target=None, name=None,
args=(), kwargs={}, verbose=None): args=(), kwargs={}, verbose=None):
@ -359,10 +359,10 @@ def __init__(self, group=None, target=None, name=None,
self.__args = args self.__args = args
self.__kwargs = kwargs self.__kwargs = kwargs
self.__daemonic = self._set_daemon() self.__daemonic = self._set_daemon()
self.__started = 0 self.__started = False
self.__stopped = 0 self.__stopped = False
self.__block = Condition(Lock()) self.__block = Condition(Lock())
self.__initialized = 1 self.__initialized = True
def _set_daemon(self): def _set_daemon(self):
# Overridden in _MainThread and _DummyThread # Overridden in _MainThread and _DummyThread
@ -388,7 +388,7 @@ def start(self):
_limbo[self] = self _limbo[self] = self
_active_limbo_lock.release() _active_limbo_lock.release()
_start_new_thread(self.__bootstrap, ()) _start_new_thread(self.__bootstrap, ())
self.__started = 1 self.__started = True
_sleep(0.000001) # 1 usec, to let the thread run (Solaris hack) _sleep(0.000001) # 1 usec, to let the thread run (Solaris hack)
def run(self): def run(self):
@ -397,7 +397,7 @@ def run(self):
def __bootstrap(self): def __bootstrap(self):
try: try:
self.__started = 1 self.__started = True
_active_limbo_lock.acquire() _active_limbo_lock.acquire()
_active[_get_ident()] = self _active[_get_ident()] = self
del _limbo[self] del _limbo[self]
@ -428,7 +428,7 @@ def __bootstrap(self):
def __stop(self): def __stop(self):
self.__block.acquire() self.__block.acquire()
self.__stopped = 1 self.__stopped = True
self.__block.notifyAll() self.__block.notifyAll()
self.__block.release() self.__block.release()
@ -523,7 +523,7 @@ class _MainThread(Thread):
def __init__(self): def __init__(self):
Thread.__init__(self, name="MainThread") Thread.__init__(self, name="MainThread")
self._Thread__started = 1 self._Thread__started = True
_active_limbo_lock.acquire() _active_limbo_lock.acquire()
_active[_get_ident()] = self _active[_get_ident()] = self
_active_limbo_lock.release() _active_limbo_lock.release()
@ -531,7 +531,7 @@ def __init__(self):
atexit.register(self.__exitfunc) atexit.register(self.__exitfunc)
def _set_daemon(self): def _set_daemon(self):
return 0 return False
def __exitfunc(self): def __exitfunc(self):
self._Thread__stop() self._Thread__stop()
@ -564,16 +564,16 @@ class _DummyThread(Thread):
def __init__(self): def __init__(self):
Thread.__init__(self, name=_newname("Dummy-%d")) Thread.__init__(self, name=_newname("Dummy-%d"))
self._Thread__started = 1 self._Thread__started = True
_active_limbo_lock.acquire() _active_limbo_lock.acquire()
_active[_get_ident()] = self _active[_get_ident()] = self
_active_limbo_lock.release() _active_limbo_lock.release()
def _set_daemon(self): def _set_daemon(self):
return 1 return True
def join(self, timeout=None): def join(self, timeout=None):
assert 0, "cannot join a dummy thread" assert False, "cannot join a dummy thread"
# Global API functions # Global API functions

View File

@ -546,13 +546,13 @@ def is_suburi(self, base, test):
Both args must be URIs in reduced form. Both args must be URIs in reduced form.
""" """
if base == test: if base == test:
return 1 return True
if base[0] != test[0]: if base[0] != test[0]:
return 0 return False
common = posixpath.commonprefix((base[1], test[1])) common = posixpath.commonprefix((base[1], test[1]))
if len(common) == len(base[1]): if len(common) == len(base[1]):
return 1 return True
return 0 return False
class HTTPPasswordMgrWithDefaultRealm(HTTPPasswordMgr): class HTTPPasswordMgrWithDefaultRealm(HTTPPasswordMgr):

View File

@ -83,9 +83,10 @@ def is_zipfile(filename):
endrec = fpin.read() endrec = fpin.read()
fpin.close() fpin.close()
if endrec[0:4] == "PK\005\006" and endrec[-2:] == "\000\000": 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: except IOError:
pass pass
return False
class ZipInfo: class ZipInfo: