Partial introduction of bools where appropriate.
This commit is contained in:
parent
b8bff3f4a9
commit
8ca162f417
|
@ -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
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ class StringIO:
|
||||||
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:
|
||||||
|
|
20
Lib/chunk.py
20
Lib/chunk.py
|
@ -25,13 +25,13 @@ of the file, creating a new instance will fail with a EOFError
|
||||||
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 @@ default is 1, i.e. aligned.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
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 @@ class Chunk:
|
||||||
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,14 +86,14 @@ class Chunk:
|
||||||
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.
|
||||||
Default position is 0 (start of chunk).
|
Default position is 0 (start of chunk).
|
||||||
If the file is not seekable, this will result in an error.
|
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"
|
raise ValueError, "I/O operation on closed file"
|
||||||
return self.size_read
|
return self.size_read
|
||||||
|
|
||||||
def read(self, size = -1):
|
def read(self, size=-1):
|
||||||
"""Read at most size bytes from the chunk.
|
"""Read at most size bytes from the chunk.
|
||||||
If size is omitted or negative, read until the end
|
If size is omitted or negative, read until the end
|
||||||
of the chunk.
|
of the chunk.
|
||||||
|
|
|
@ -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):
|
||||||
|
|
|
@ -154,7 +154,7 @@ class FileInput:
|
||||||
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 @@ class FileInput:
|
||||||
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 @@ class FileInput:
|
||||||
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 = (
|
||||||
|
|
22
Lib/gzip.py
22
Lib/gzip.py
|
@ -47,7 +47,7 @@ class GzipFile:
|
||||||
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 @@ class GzipFile:
|
||||||
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 @@ class GzipFile:
|
||||||
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 @@ class GzipFile:
|
||||||
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 @@ class GzipFile:
|
||||||
# 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 @@ class GzipFile:
|
||||||
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 @@ class GzipFile:
|
||||||
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 @@ class GzipFile:
|
||||||
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
|
||||||
|
|
||||||
|
@ -342,7 +342,7 @@ class GzipFile:
|
||||||
while sizehint > 0:
|
while sizehint > 0:
|
||||||
line = self.readline()
|
line = self.readline()
|
||||||
if line == "": break
|
if line == "": break
|
||||||
L.append( line )
|
L.append(line)
|
||||||
sizehint = sizehint - len(line)
|
sizehint = sizehint - len(line)
|
||||||
|
|
||||||
return L
|
return L
|
||||||
|
@ -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
|
||||||
|
|
|
@ -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])
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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])
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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])
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -126,8 +126,8 @@ class PrettyPrinter:
|
||||||
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 @@ class PrettyPrinter:
|
||||||
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):
|
||||||
|
|
|
@ -443,7 +443,7 @@ TT { font-family: lucidatypewriter, lucida console, courier }
|
||||||
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 @@ has the same effect as typing a particular string at the help> prompt.
|
||||||
|
|
||||||
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 @@ class ModuleScanner(Scanner):
|
||||||
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 @@ pydoc</strong> by Ka-Ping Yee <ping@lfw.org></font>'''
|
||||||
|
|
||||||
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()
|
||||||
|
|
|
@ -222,7 +222,7 @@ class Message:
|
||||||
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.
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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])
|
||||||
|
|
|
@ -30,7 +30,7 @@ del StringIO
|
||||||
|
|
||||||
# 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 @@ class _Condition(_Verbose):
|
||||||
# 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 @@ class _Semaphore(_Verbose):
|
||||||
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 @@ class _Semaphore(_Verbose):
|
||||||
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 @@ _limbo = {}
|
||||||
|
|
||||||
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 @@ class Thread(_Verbose):
|
||||||
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 @@ class Thread(_Verbose):
|
||||||
_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 @@ class Thread(_Verbose):
|
||||||
|
|
||||||
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 @@ class Thread(_Verbose):
|
||||||
|
|
||||||
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 @@ class _MainThread(Thread):
|
||||||
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
|
||||||
|
|
|
@ -546,13 +546,13 @@ class HTTPPasswordMgr:
|
||||||
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):
|
||||||
|
|
|
@ -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:
|
||||||
|
|
Loading…
Reference in New Issue