Update the code to better reflect recommended style:

Use != instead of <> since <> is documented as "obsolescent".
Use "is" and "is not" when comparing with None or type objects.
This commit is contained in:
Fred Drake 2000-12-12 23:20:45 +00:00
parent c140131995
commit 8152d32375
36 changed files with 101 additions and 99 deletions

View File

@ -489,7 +489,7 @@ class Morsel(UserDict):
RA("%s=%s;" % (self.key, self.coded_value)) RA("%s=%s;" % (self.key, self.coded_value))
# Now add any defined attributes # Now add any defined attributes
if attrs == None: if attrs is None:
attrs = self._reserved_keys attrs = self._reserved_keys
for K,V in self.items(): for K,V in self.items():
if V == "": continue if V == "": continue

View File

@ -189,7 +189,7 @@ class BinHex:
hqxer = _Hqxcoderengine(ofp) hqxer = _Hqxcoderengine(ofp)
self.ofp = _Rlecoderengine(hqxer) self.ofp = _Rlecoderengine(hqxer)
self.crc = 0 self.crc = 0
if finfo == None: if finfo is None:
finfo = FInfo() finfo = FInfo()
self.dlen = dlen self.dlen = dlen
self.rlen = rlen self.rlen = rlen
@ -228,7 +228,7 @@ class BinHex:
self._write(data) self._write(data)
def close_data(self): def close_data(self):
if self.dlen <> 0: if self.dlen != 0:
raise Error, 'Incorrect data size, diff='+`self.rlen` raise Error, 'Incorrect data size, diff='+`self.rlen`
self._writecrc() self._writecrc()
self.state = _DID_DATA self.state = _DID_DATA
@ -246,7 +246,7 @@ class BinHex:
self.close_data() self.close_data()
if self.state != _DID_DATA: if self.state != _DID_DATA:
raise Error, 'Close at the wrong time' raise Error, 'Close at the wrong time'
if self.rlen <> 0: if self.rlen != 0:
raise Error, \ raise Error, \
"Incorrect resource-datasize, diff="+`self.rlen` "Incorrect resource-datasize, diff="+`self.rlen`
self._writecrc() self._writecrc()

View File

@ -50,7 +50,7 @@ def setfirstweekday(weekday):
def isleap(year): def isleap(year):
"""Return 1 for leap years, 0 for non-leap years.""" """Return 1 for leap years, 0 for non-leap years."""
return year % 4 == 0 and (year % 100 <> 0 or year % 400 == 0) return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)
def leapdays(y1, y2): def leapdays(y1, y2):
"""Return number of leap years in range [y1, y2). """Return number of leap years in range [y1, y2).

View File

@ -57,7 +57,7 @@ class Cmd:
def cmdloop(self, intro=None): def cmdloop(self, intro=None):
self.preloop() self.preloop()
if intro != None: if intro is not None:
self.intro = intro self.intro = intro
if self.intro: if self.intro:
print self.intro print self.intro

View File

@ -51,7 +51,7 @@ def getstatusoutput(cmd):
pipe = os.popen('{ ' + cmd + '; } 2>&1', 'r') pipe = os.popen('{ ' + cmd + '; } 2>&1', 'r')
text = pipe.read() text = pipe.read()
sts = pipe.close() sts = pipe.close()
if sts == None: sts = 0 if sts is None: sts = 0
if text[-1:] == '\n': text = text[:-1] if text[-1:] == '\n': text = text[:-1]
return sts, text return sts, text

View File

@ -19,7 +19,7 @@ def listdir(path):
mtime = os.stat(path)[8] mtime = os.stat(path)[8]
except os.error: except os.error:
return [] return []
if mtime <> cached_mtime: if mtime != cached_mtime:
try: try:
list = os.listdir(path) list = os.listdir(path)
except os.error: except os.error:

View File

@ -108,7 +108,7 @@ def commonprefix(m):
prefix = m[0] prefix = m[0]
for item in m: for item in m:
for i in range(len(prefix)): for i in range(len(prefix)):
if prefix[:i+1] <> item[:i+1]: if prefix[:i+1] != item[:i+1]:
prefix = prefix[:i] prefix = prefix[:i]
if i == 0: return '' if i == 0: return ''
break break
@ -210,7 +210,7 @@ def expanduser(path):
(A function should also be defined to do full *sh-style environment (A function should also be defined to do full *sh-style environment
variable expansion.)""" variable expansion.)"""
if path[:1] <> '~': if path[:1] != '~':
return path return path
i, n = 1, len(path) i, n = 1, len(path)
while i < n and path[i] not in '/\\': while i < n and path[i] not in '/\\':
@ -303,7 +303,7 @@ def normpath(path):
comps[i-1] not in ('', '..'): comps[i-1] not in ('', '..'):
del comps[i-1:i+1] del comps[i-1:i+1]
i = i - 1 i = i - 1
elif comps[i] == '' and i > 0 and comps[i-1] <> '': elif comps[i] == '' and i > 0 and comps[i-1] != '':
del comps[i] del comps[i]
elif '.' in comps[i]: elif '.' in comps[i]:
comp = comps[i].split('.') comp = comps[i].split('.')

View File

@ -199,7 +199,7 @@ class dircmp:
if ok: if ok:
a_type = stat.S_IFMT(a_stat[stat.ST_MODE]) a_type = stat.S_IFMT(a_stat[stat.ST_MODE])
b_type = stat.S_IFMT(b_stat[stat.ST_MODE]) b_type = stat.S_IFMT(b_stat[stat.ST_MODE])
if a_type <> b_type: if a_type != b_type:
self.common_funny.append(x) self.common_funny.append(x)
elif stat.S_ISDIR(a_type): elif stat.S_ISDIR(a_type):
self.common_dirs.append(x) self.common_dirs.append(x)
@ -317,7 +317,8 @@ def demo():
import sys import sys
import getopt import getopt
options, args = getopt.getopt(sys.argv[1:], 'r') options, args = getopt.getopt(sys.argv[1:], 'r')
if len(args) <> 2: raise getopt.error, 'need exactly two args' if len(args) != 2:
raise getopt.error, 'need exactly two args'
dd = dircmp(args[0], args[1]) dd = dircmp(args[0], args[1])
if ('-r', '') in options: if ('-r', '') in options:
dd.report_full_closure() dd.report_full_closure()

View File

@ -185,7 +185,7 @@ class FTP:
nextline = self.getline() nextline = self.getline()
line = line + ('\n' + nextline) line = line + ('\n' + nextline)
if nextline[:3] == code and \ if nextline[:3] == code and \
nextline[3:4] <> '-': nextline[3:4] != '-':
break break
return line return line
@ -207,7 +207,7 @@ class FTP:
def voidresp(self): def voidresp(self):
"""Expect a response beginning with '2'.""" """Expect a response beginning with '2'."""
resp = self.getresp() resp = self.getresp()
if resp[0] <> '2': if resp[0] != '2':
raise error_reply, resp raise error_reply, resp
return resp return resp
@ -277,14 +277,14 @@ class FTP:
if rest is not None: if rest is not None:
self.sendcmd("REST %s" % rest) self.sendcmd("REST %s" % rest)
resp = self.sendcmd(cmd) resp = self.sendcmd(cmd)
if resp[0] <> '1': if resp[0] != '1':
raise error_reply, resp raise error_reply, resp
else: else:
sock = self.makeport() sock = self.makeport()
if rest is not None: if rest is not None:
self.sendcmd("REST %s" % rest) self.sendcmd("REST %s" % rest)
resp = self.sendcmd(cmd) resp = self.sendcmd(cmd)
if resp[0] <> '1': if resp[0] != '1':
raise error_reply, resp raise error_reply, resp
conn, sockaddr = sock.accept() conn, sockaddr = sock.accept()
if resp[:3] == '150': if resp[:3] == '150':
@ -318,7 +318,7 @@ class FTP:
resp = self.sendcmd('USER ' + user) resp = self.sendcmd('USER ' + user)
if resp[0] == '3': resp = self.sendcmd('PASS ' + passwd) if resp[0] == '3': resp = self.sendcmd('PASS ' + passwd)
if resp[0] == '3': resp = self.sendcmd('ACCT ' + acct) if resp[0] == '3': resp = self.sendcmd('ACCT ' + acct)
if resp[0] <> '2': if resp[0] != '2':
raise error_reply, resp raise error_reply, resp
return resp return resp
@ -384,7 +384,7 @@ class FTP:
while 1: while 1:
buf = fp.readline() buf = fp.readline()
if not buf: break if not buf: break
if buf[-2:] <> CRLF: if buf[-2:] != CRLF:
if buf[-1] in CRLF: buf = buf[:-1] if buf[-1] in CRLF: buf = buf[:-1]
buf = buf + CRLF buf = buf + CRLF
conn.send(buf) conn.send(buf)
@ -423,7 +423,7 @@ class FTP:
def rename(self, fromname, toname): def rename(self, fromname, toname):
'''Rename a file.''' '''Rename a file.'''
resp = self.sendcmd('RNFR ' + fromname) resp = self.sendcmd('RNFR ' + fromname)
if resp[0] <> '3': if resp[0] != '3':
raise error_reply, resp raise error_reply, resp
return self.voidcmd('RNTO ' + toname) return self.voidcmd('RNTO ' + toname)
@ -508,7 +508,7 @@ def parse227(resp):
Raises error_proto if it does not contain '(h1,h2,h3,h4,p1,p2)' Raises error_proto if it does not contain '(h1,h2,h3,h4,p1,p2)'
Return ('host.addr.as.numbers', port#) tuple.''' Return ('host.addr.as.numbers', port#) tuple.'''
if resp[:3] <> '227': if resp[:3] != '227':
raise error_reply, resp raise error_reply, resp
left = string.find(resp, '(') left = string.find(resp, '(')
if left < 0: raise error_proto, resp if left < 0: raise error_proto, resp
@ -516,7 +516,7 @@ def parse227(resp):
if right < 0: if right < 0:
raise error_proto, resp # should contain '(h1,h2,h3,h4,p1,p2)' raise error_proto, resp # should contain '(h1,h2,h3,h4,p1,p2)'
numbers = string.split(resp[left+1:right], ',') numbers = string.split(resp[left+1:right], ',')
if len(numbers) <> 6: if len(numbers) != 6:
raise error_proto, resp raise error_proto, resp
host = string.join(numbers[:4], '.') host = string.join(numbers[:4], '.')
port = (string.atoi(numbers[4]) << 8) + string.atoi(numbers[5]) port = (string.atoi(numbers[4]) << 8) + string.atoi(numbers[5])
@ -528,9 +528,9 @@ def parse257(resp):
This is a response to a MKD or PWD request: a directory name. This is a response to a MKD or PWD request: a directory name.
Returns the directoryname in the 257 reply.''' Returns the directoryname in the 257 reply.'''
if resp[:3] <> '257': if resp[:3] != '257':
raise error_reply, resp raise error_reply, resp
if resp[3:5] <> ' "': if resp[3:5] != ' "':
return '' # Not compliant to RFC 959, but UNIX ftpd does this return '' # Not compliant to RFC 959, but UNIX ftpd does this
dirname = '' dirname = ''
i = 5 i = 5
@ -539,7 +539,7 @@ def parse257(resp):
c = resp[i] c = resp[i]
i = i+1 i = i+1
if c == '"': if c == '"':
if i >= n or resp[i] <> '"': if i >= n or resp[i] != '"':
break break
i = i+1 i = i+1
dirname = dirname + c dirname = dirname + c

View File

@ -434,7 +434,7 @@ def _os_bootstrap():
path = s path = s
if ':' not in a: if ':' not in a:
a = ':' + a a = ':' + a
if a[-1:] <> ':': if a[-1:] != ':':
a = a + ':' a = a + ':'
return a + b return a + b
else: else:
@ -643,7 +643,7 @@ def _test_revamp():
# from Guido: # from Guido:
# need to change sys.* references for rexec environs # need to change sys.* references for rexec environs
# need hook for MAL's walk-me-up import strategy, or Tim's absolute strategy # need hook for MAL's walk-me-up import strategy, or Tim's absolute strategy
# watch out for sys.modules[...] == None # watch out for sys.modules[...] is None
# flag to force absolute imports? (speeds _determine_import_context and # flag to force absolute imports? (speeds _determine_import_context and
# checking for a relative module) # checking for a relative module)
# insert names of archives into sys.path (see quote below) # insert names of archives into sys.path (see quote below)

View File

@ -50,7 +50,7 @@ def checkcache():
except os.error: except os.error:
del cache[filename] del cache[filename]
continue continue
if size <> stat[ST_SIZE] or mtime <> stat[ST_MTIME]: if size != stat[ST_SIZE] or mtime != stat[ST_MTIME]:
del cache[filename] del cache[filename]

View File

@ -17,7 +17,7 @@ def isabs(s):
Anything else is absolute (the string up to the first colon is the Anything else is absolute (the string up to the first colon is the
volume name).""" volume name)."""
return ':' in s and s[0] <> ':' return ':' in s and s[0] != ':'
def join(s, *p): def join(s, *p):
@ -30,7 +30,7 @@ def join(s, *p):
t = t[1:] t = t[1:]
if ':' not in path: if ':' not in path:
path = ':' + path path = ':' + path
if path[-1:] <> ':': if path[-1:] != ':':
path = path + ':' path = path + ':'
path = path + t path = path + t
return path return path
@ -151,7 +151,7 @@ def commonprefix(m):
prefix = m[0] prefix = m[0]
for item in m: for item in m:
for i in range(len(prefix)): for i in range(len(prefix)):
if prefix[:i+1] <> item[:i+1]: if prefix[:i+1] != item[:i+1]:
prefix = prefix[:i] prefix = prefix[:i]
if i == 0: return '' if i == 0: return ''
break break

View File

@ -12,7 +12,7 @@ def url2pathname(pathname):
# XXXX The .. handling should be fixed... # XXXX The .. handling should be fixed...
# #
tp = urllib.splittype(pathname)[0] tp = urllib.splittype(pathname)[0]
if tp and tp <> 'file': if tp and tp != 'file':
raise RuntimeError, 'Cannot convert non-local URL to pathname' raise RuntimeError, 'Cannot convert non-local URL to pathname'
# Turn starting /// into /, an empty hostname means current host # Turn starting /// into /, an empty hostname means current host
if pathname[:3] == '///': if pathname[:3] == '///':
@ -29,7 +29,7 @@ def url2pathname(pathname):
components[i-1] not in ('', '..'): components[i-1] not in ('', '..'):
del components[i-1:i+1] del components[i-1:i+1]
i = i-1 i = i-1
elif components[i] == '' and i > 0 and components[i-1] <> '': elif components[i] == '' and i > 0 and components[i-1] != '':
del components[i] del components[i]
else: else:
i = i+1 i = i+1

View File

@ -30,7 +30,7 @@ class _Mailbox:
start = self.fp.tell() start = self.fp.tell()
self._search_end() self._search_end()
self.seekp = stop = self.fp.tell() self.seekp = stop = self.fp.tell()
if start <> stop: if start != stop:
break break
return rfc822.Message(_Subfile(self.fp, start, stop)) return rfc822.Message(_Subfile(self.fp, start, stop))

View File

@ -173,7 +173,7 @@ def subst(field, MIMEtype, filename, plist=[]):
i, n = 0, len(field) i, n = 0, len(field)
while i < n: while i < n:
c = field[i]; i = i+1 c = field[i]; i = i+1
if c <> '%': if c != '%':
if c == '\\': if c == '\\':
c = field[i:i+1]; i = i+1 c = field[i:i+1]; i = i+1
res = res + c res = res + c
@ -187,7 +187,7 @@ def subst(field, MIMEtype, filename, plist=[]):
res = res + MIMEtype res = res + MIMEtype
elif c == '{': elif c == '{':
start = i start = i
while i < n and field[i] <> '}': while i < n and field[i] != '}':
i = i+1 i = i+1
name = field[start:i] name = field[start:i]
i = i+1 i = i+1

View File

@ -305,7 +305,7 @@ class Folder:
line = f.readline() line = f.readline()
if not line: break if not line: break
fields = string.splitfields(line, ':') fields = string.splitfields(line, ':')
if len(fields) <> 2: if len(fields) != 2:
self.error('bad sequence in %s: %s' % self.error('bad sequence in %s: %s' %
(fullname, string.strip(line))) (fullname, string.strip(line)))
key = string.strip(fields[0]) key = string.strip(fields[0])

View File

@ -22,7 +22,7 @@ class Message(rfc822.Message):
def parsetype(self): def parsetype(self):
str = self.typeheader str = self.typeheader
if str == None: if str is None:
str = 'text/plain' str = 'text/plain'
if ';' in str: if ';' in str:
i = string.index(str, ';') i = string.index(str, ';')
@ -75,7 +75,7 @@ class Message(rfc822.Message):
return result return result
def getencoding(self): def getencoding(self):
if self.encodingheader == None: if self.encodingheader is None:
return '7bit' return '7bit'
return string.lower(self.encodingheader) return string.lower(self.encodingheader)
@ -109,7 +109,7 @@ def choose_boundary():
global _prefix global _prefix
import time import time
import random import random
if _prefix == None: if _prefix is None:
import socket import socket
import os import os
hostid = socket.gethostbyname(socket.gethostname()) hostid = socket.gethostbyname(socket.gethostname())

View File

@ -155,7 +155,7 @@ class MultiFile:
self.lastpos = abslastpos - self.start self.lastpos = abslastpos - self.start
def is_data(self, line): def is_data(self, line):
return line[:2] <> '--' return line[:2] != '--'
def section_divider(self, str): def section_divider(self, str):
return "--" + str return "--" + str

View File

@ -17,7 +17,7 @@ class netrc:
while 1: while 1:
# Look for a machine, default, or macdef top-level keyword # Look for a machine, default, or macdef top-level keyword
toplevel = tt = lexer.get_token() toplevel = tt = lexer.get_token()
if tt == '' or tt == None: if not tt:
break break
elif tt == 'machine': elif tt == 'machine':
entryname = lexer.get_token() entryname = lexer.get_token()

View File

@ -258,7 +258,7 @@ class NNTP:
- name: the group name""" - name: the group name"""
resp = self.shortcmd('GROUP ' + name) resp = self.shortcmd('GROUP ' + name)
if resp[:3] <> '211': if resp[:3] != '211':
raise NNTPReplyError(resp) raise NNTPReplyError(resp)
words = string.split(resp) words = string.split(resp)
count = first = last = 0 count = first = last = 0
@ -282,7 +282,7 @@ class NNTP:
def statparse(self, resp): def statparse(self, resp):
"""Internal: parse the response of a STAT, NEXT or LAST command.""" """Internal: parse the response of a STAT, NEXT or LAST command."""
if resp[:2] <> '22': if resp[:2] != '22':
raise NNTPReplyError(resp) raise NNTPReplyError(resp)
words = string.split(resp) words = string.split(resp)
nr = 0 nr = 0
@ -429,7 +429,7 @@ class NNTP:
path: directory path to article""" path: directory path to article"""
resp = self.shortcmd("XPATH " + id) resp = self.shortcmd("XPATH " + id)
if resp[:3] <> '223': if resp[:3] != '223':
raise NNTPReplyError(resp) raise NNTPReplyError(resp)
try: try:
[resp_num, path] = string.split(resp) [resp_num, path] = string.split(resp)
@ -447,7 +447,7 @@ class NNTP:
time: Time suitable for newnews/newgroups commands etc.""" time: Time suitable for newnews/newgroups commands etc."""
resp = self.shortcmd("DATE") resp = self.shortcmd("DATE")
if resp[:3] <> '111': if resp[:3] != '111':
raise NNTPReplyError(resp) raise NNTPReplyError(resp)
elem = string.split(resp) elem = string.split(resp)
if len(elem) != 2: if len(elem) != 2:
@ -467,7 +467,7 @@ class NNTP:
resp = self.shortcmd('POST') resp = self.shortcmd('POST')
# Raises error_??? if posting is not allowed # Raises error_??? if posting is not allowed
if resp[0] <> '3': if resp[0] != '3':
raise NNTPReplyError(resp) raise NNTPReplyError(resp)
while 1: while 1:
line = f.readline() line = f.readline()
@ -491,7 +491,7 @@ class NNTP:
resp = self.shortcmd('IHAVE ' + id) resp = self.shortcmd('IHAVE ' + id)
# Raises error_??? if the server already has it # Raises error_??? if the server already has it
if resp[0] <> '3': if resp[0] != '3':
raise NNTPReplyError(resp) raise NNTPReplyError(resp)
while 1: while 1:
line = f.readline() line = f.readline()

View File

@ -160,7 +160,7 @@ def commonprefix(m):
prefix = m[0] prefix = m[0]
for item in m: for item in m:
for i in range(len(prefix)): for i in range(len(prefix)):
if prefix[:i+1] <> item[:i+1]: if prefix[:i+1] != item[:i+1]:
prefix = prefix[:i] prefix = prefix[:i]
if i == 0: return '' if i == 0: return ''
break break
@ -283,7 +283,7 @@ def expanduser(path):
"""Expand ~ and ~user constructs. """Expand ~ and ~user constructs.
If user or $HOME is unknown, do nothing.""" If user or $HOME is unknown, do nothing."""
if path[:1] <> '~': if path[:1] != '~':
return path return path
i, n = 1, len(path) i, n = 1, len(path)
while i < n and path[i] not in '/\\': while i < n and path[i] not in '/\\':
@ -387,7 +387,7 @@ def normpath(path):
elif comps[i] == '..' and i > 0 and comps[i-1] not in ('', '..'): elif comps[i] == '..' and i > 0 and comps[i-1] not in ('', '..'):
del comps[i-1:i+1] del comps[i-1:i+1]
i = i - 1 i = i - 1
elif comps[i] == '' and i > 0 and comps[i-1] <> '': elif comps[i] == '' and i > 0 and comps[i-1] != '':
del comps[i] del comps[i]
else: else:
i = i + 1 i = i + 1

View File

@ -553,7 +553,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
first = max(1, self.curframe.f_lineno - 5) first = max(1, self.curframe.f_lineno - 5)
else: else:
first = self.lineno + 1 first = self.lineno + 1
if last == None: if last is None:
last = first + 10 last = first + 10
filename = self.curframe.f_code.co_filename filename = self.curframe.f_code.co_filename
breaklist = self.get_file_breaks(filename) breaklist = self.get_file_breaks(filename)
@ -895,7 +895,8 @@ def set_trace():
def post_mortem(t): def post_mortem(t):
p = Pdb() p = Pdb()
p.reset() p.reset()
while t.tb_next <> None: t = t.tb_next while t.tb_next is not None:
t = t.tb_next
p.interaction(t.tb_frame, t) p.interaction(t.tb_frame, t)
def pm(): def pm():

View File

@ -110,7 +110,7 @@ class Template:
def append(self, cmd, kind): def append(self, cmd, kind):
"""t.append(cmd, kind) adds a new step at the end.""" """t.append(cmd, kind) adds a new step at the end."""
if type(cmd) <> type(''): if type(cmd) is not type(''):
raise TypeError, \ raise TypeError, \
'Template.append: cmd must be a string' 'Template.append: cmd must be a string'
if kind not in stepkinds: if kind not in stepkinds:
@ -119,7 +119,7 @@ class Template:
if kind == SOURCE: if kind == SOURCE:
raise ValueError, \ raise ValueError, \
'Template.append: SOURCE can only be prepended' 'Template.append: SOURCE can only be prepended'
if self.steps <> [] and self.steps[-1][1] == SINK: if self.steps and self.steps[-1][1] == SINK:
raise ValueError, \ raise ValueError, \
'Template.append: already ends with SINK' 'Template.append: already ends with SINK'
if kind[0] == 'f' and not re.search('\$IN\b', cmd): if kind[0] == 'f' and not re.search('\$IN\b', cmd):
@ -132,7 +132,7 @@ class Template:
def prepend(self, cmd, kind): def prepend(self, cmd, kind):
"""t.prepend(cmd, kind) adds a new step at the front.""" """t.prepend(cmd, kind) adds a new step at the front."""
if type(cmd) <> type(''): if type(cmd) is not type(''):
raise TypeError, \ raise TypeError, \
'Template.prepend: cmd must be a string' 'Template.prepend: cmd must be a string'
if kind not in stepkinds: if kind not in stepkinds:
@ -141,7 +141,7 @@ class Template:
if kind == SINK: if kind == SINK:
raise ValueError, \ raise ValueError, \
'Template.prepend: SINK can only be appended' 'Template.prepend: SINK can only be appended'
if self.steps <> [] and self.steps[0][1] == SOURCE: if self.steps and self.steps[0][1] == SOURCE:
raise ValueError, \ raise ValueError, \
'Template.prepend: already begins with SOURCE' 'Template.prepend: already begins with SOURCE'
if kind[0] == 'f' and not re.search('\$IN\b', cmd): if kind[0] == 'f' and not re.search('\$IN\b', cmd):
@ -165,7 +165,7 @@ class Template:
def open_r(self, file): def open_r(self, file):
"""t.open_r(file) and t.open_w(file) implement """t.open_r(file) and t.open_w(file) implement
t.open(file, 'r') and t.open(file, 'w') respectively.""" t.open(file, 'r') and t.open(file, 'w') respectively."""
if self.steps == []: if not self.steps:
return open(file, 'r') return open(file, 'r')
if self.steps[-1][1] == SINK: if self.steps[-1][1] == SINK:
raise ValueError, \ raise ValueError, \
@ -174,7 +174,7 @@ class Template:
return os.popen(cmd, 'r') return os.popen(cmd, 'r')
def open_w(self, file): def open_w(self, file):
if self.steps == []: if not self.steps:
return open(file, 'w') return open(file, 'w')
if self.steps[0][1] == SOURCE: if self.steps[0][1] == SOURCE:
raise ValueError, \ raise ValueError, \
@ -203,7 +203,7 @@ def makepipeline(infile, steps, outfile):
# #
# Make sure there is at least one step # Make sure there is at least one step
# #
if list == []: if not list:
list.append(['', 'cat', '--', '']) list.append(['', 'cat', '--', ''])
# #
# Take care of the input and output ends # Take care of the input and output ends

View File

@ -59,7 +59,7 @@ def split(p):
everything after the final slash. Either part may be empty.""" everything after the final slash. Either part may be empty."""
i = p.rfind('/') + 1 i = p.rfind('/') + 1
head, tail = p[:i], p[i:] head, tail = p[:i], p[i:]
if head and head <> '/'*len(head): if head and head != '/'*len(head):
while head[-1] == '/': while head[-1] == '/':
head = head[:-1] head = head[:-1]
return head, tail return head, tail
@ -120,7 +120,7 @@ def commonprefix(m):
prefix = m[0] prefix = m[0]
for item in m: for item in m:
for i in range(len(prefix)): for i in range(len(prefix)):
if prefix[:i+1] <> item[:i+1]: if prefix[:i+1] != item[:i+1]:
prefix = prefix[:i] prefix = prefix[:i]
if i == 0: return '' if i == 0: return ''
break break
@ -281,10 +281,10 @@ def walk(top, func, arg):
def expanduser(path): def expanduser(path):
"""Expand ~ and ~user constructions. If user or $HOME is unknown, """Expand ~ and ~user constructions. If user or $HOME is unknown,
do nothing.""" do nothing."""
if path[:1] <> '~': if path[:1] != '~':
return path return path
i, n = 1, len(path) i, n = 1, len(path)
while i < n and path[i] <> '/': while i < n and path[i] != '/':
i = i + 1 i = i + 1
if i == 1: if i == 1:
if not os.environ.has_key('HOME'): if not os.environ.has_key('HOME'):

View File

@ -69,7 +69,7 @@ def decode(input, output):
partial = 1 partial = 1
while i < n: while i < n:
c = line[i] c = line[i]
if c <> ESCAPE: if c != ESCAPE:
new = new + c; i = i+1 new = new + c; i = i+1
elif i+1 == n and not partial: elif i+1 == n and not partial:
partial = 1; break partial = 1; break

View File

@ -124,7 +124,7 @@ def capwords(str, pat='[^a-zA-Z0-9_]+'):
cache = {} cache = {}
def compile(pat): def compile(pat):
if type(pat) <> type(''): if type(pat) != type(''):
return pat # Assume it is a compiled regex return pat # Assume it is a compiled regex
key = (pat, regex.get_syntax()) key = (pat, regex.get_syntax())
if cache.has_key(key): if cache.has_key(key):
@ -153,7 +153,7 @@ def expand(repl, regs, str):
ord0 = ord('0') ord0 = ord('0')
while i < len(repl): while i < len(repl):
c = repl[i]; i = i+1 c = repl[i]; i = i+1
if c <> '\\' or i >= len(repl): if c != '\\' or i >= len(repl):
new = new + c new = new + c
else: else:
c = repl[i]; i = i+1 c = repl[i]; i = i+1
@ -182,7 +182,7 @@ def test():
if not line: break if not line: break
if line[-1] == '\n': line = line[:-1] if line[-1] == '\n': line = line[:-1]
fields = split(line, delpat) fields = split(line, delpat)
if len(fields) <> 3: if len(fields) != 3:
print 'Sorry, not three fields' print 'Sorry, not three fields'
print 'split:', `fields` print 'split:', `fields`
continue continue

View File

@ -185,7 +185,7 @@ class SGMLParser:
# Internal -- parse comment, return length or -1 if not terminated # Internal -- parse comment, return length or -1 if not terminated
def parse_comment(self, i): def parse_comment(self, i):
rawdata = self.rawdata rawdata = self.rawdata
if rawdata[i:i+4] <> '<!--': if rawdata[i:i+4] != '<!--':
raise RuntimeError, 'unexpected call to handle_comment' raise RuntimeError, 'unexpected call to handle_comment'
match = commentclose.search(rawdata, i+4) match = commentclose.search(rawdata, i+4)
if not match: if not match:
@ -198,7 +198,7 @@ class SGMLParser:
# Internal -- parse processing instr, return length or -1 if not terminated # Internal -- parse processing instr, return length or -1 if not terminated
def parse_pi(self, i): def parse_pi(self, i):
rawdata = self.rawdata rawdata = self.rawdata
if rawdata[i:i+2] <> '<?': if rawdata[i:i+2] != '<?':
raise RuntimeError, 'unexpected call to handle_pi' raise RuntimeError, 'unexpected call to handle_pi'
match = piclose.search(rawdata, i+2) match = piclose.search(rawdata, i+2)
if not match: if not match:

View File

@ -319,7 +319,7 @@ class SMTP:
if code == -1 and len(msg) == 0: if code == -1 and len(msg) == 0:
raise SMTPServerDisconnected("Server not connected") raise SMTPServerDisconnected("Server not connected")
self.ehlo_resp=msg self.ehlo_resp=msg
if code<>250: if code != 250:
return (code,msg) return (code,msg)
self.does_esmtp=1 self.does_esmtp=1
#parse the ehlo response -ddm #parse the ehlo response -ddm
@ -378,7 +378,7 @@ class SMTP:
self.putcmd("data") self.putcmd("data")
(code,repl)=self.getreply() (code,repl)=self.getreply()
if self.debuglevel >0 : print "data:", (code,repl) if self.debuglevel >0 : print "data:", (code,repl)
if code <> 354: if code != 354:
raise SMTPDataError(code,repl) raise SMTPDataError(code,repl)
else: else:
q = quotedata(msg) q = quotedata(msg)
@ -475,7 +475,7 @@ class SMTP:
esmtp_opts.append(option) esmtp_opts.append(option)
(code,resp) = self.mail(from_addr, esmtp_opts) (code,resp) = self.mail(from_addr, esmtp_opts)
if code <> 250: if code != 250:
self.rset() self.rset()
raise SMTPSenderRefused(code, resp, from_addr) raise SMTPSenderRefused(code, resp, from_addr)
senderrs={} senderrs={}
@ -483,14 +483,14 @@ class SMTP:
to_addrs = [to_addrs] to_addrs = [to_addrs]
for each in to_addrs: for each in to_addrs:
(code,resp)=self.rcpt(each, rcpt_options) (code,resp)=self.rcpt(each, rcpt_options)
if (code <> 250) and (code <> 251): if (code != 250) and (code != 251):
senderrs[each]=(code,resp) senderrs[each]=(code,resp)
if len(senderrs)==len(to_addrs): if len(senderrs)==len(to_addrs):
# the server refused all our recipients # the server refused all our recipients
self.rset() self.rset()
raise SMTPRecipientsRefused(senderrs) raise SMTPRecipientsRefused(senderrs)
(code,resp)=self.data(msg) (code,resp) = self.data(msg)
if code <> 250: if code != 250:
self.rset() self.rset()
raise SMTPDataError(code, resp) raise SMTPDataError(code, resp)
#if we got here then somebody got our mail #if we got here then somebody got our mail

View File

@ -56,7 +56,7 @@ tests = []
def test_aifc(h, f): def test_aifc(h, f):
import aifc import aifc
if h[:4] <> 'FORM': if h[:4] != 'FORM':
return None return None
if h[8:12] == 'AIFC': if h[8:12] == 'AIFC':
fmt = 'aifc' fmt = 'aifc'
@ -105,7 +105,7 @@ tests.append(test_au)
def test_hcom(h, f): def test_hcom(h, f):
if h[65:69] <> 'FSSD' or h[128:132] <> 'HCOM': if h[65:69] != 'FSSD' or h[128:132] != 'HCOM':
return None return None
divisor = get_long_be(h[128+16:128+20]) divisor = get_long_be(h[128+16:128+20])
return 'hcom', 22050/divisor, 1, -1, 8 return 'hcom', 22050/divisor, 1, -1, 8
@ -114,7 +114,7 @@ tests.append(test_hcom)
def test_voc(h, f): def test_voc(h, f):
if h[:20] <> 'Creative Voice File\032': if h[:20] != 'Creative Voice File\032':
return None return None
sbseek = get_short_le(h[20:22]) sbseek = get_short_le(h[20:22])
rate = 0 rate = 0
@ -128,7 +128,7 @@ tests.append(test_voc)
def test_wav(h, f): def test_wav(h, f):
# 'RIFF' <len> 'WAVE' 'fmt ' <len> # 'RIFF' <len> 'WAVE' 'fmt ' <len>
if h[:4] <> 'RIFF' or h[8:12] <> 'WAVE' or h[12:16] <> 'fmt ': if h[:4] != 'RIFF' or h[8:12] != 'WAVE' or h[12:16] != 'fmt ':
return None return None
style = get_short_le(h[20:22]) style = get_short_le(h[20:22])
nchannels = get_short_le(h[22:24]) nchannels = get_short_le(h[22:24])
@ -140,7 +140,7 @@ tests.append(test_wav)
def test_8svx(h, f): def test_8svx(h, f):
if h[:4] <> 'FORM' or h[8:12] <> '8SVX': if h[:4] != 'FORM' or h[8:12] != '8SVX':
return None return None
# Should decode it to get #channels -- assume always 1 # Should decode it to get #channels -- assume always 1
return '8svx', 0, 1, 0, 8 return '8svx', 0, 1, 0, 8

View File

@ -43,10 +43,10 @@ def forget_prefix(prefix):
def forget_dir(prefix): def forget_dir(prefix):
"""Forget about a directory and all entries in it, but not about """Forget about a directory and all entries in it, but not about
entries in subdirectories.""" entries in subdirectories."""
if prefix[-1:] == '/' and prefix <> '/': if prefix[-1:] == '/' and prefix != '/':
prefix = prefix[:-1] prefix = prefix[:-1]
forget(prefix) forget(prefix)
if prefix[-1:] <> '/': if prefix[-1:] != '/':
prefix = prefix + '/' prefix = prefix + '/'
n = len(prefix) n = len(prefix)
for path in cache.keys(): for path in cache.keys():
@ -62,7 +62,7 @@ def forget_except_prefix(prefix):
Normally used with prefix = '/' after a chdir().""" Normally used with prefix = '/' after a chdir()."""
n = len(prefix) n = len(prefix)
for path in cache.keys(): for path in cache.keys():
if path[:n] <> prefix: if path[:n] != prefix:
del cache[path] del cache[path]

View File

@ -13,7 +13,7 @@ def get_long_be(s):
def gethdr(fp): def gethdr(fp):
"""Read a sound header from an open file.""" """Read a sound header from an open file."""
if fp.read(4) <> MAGIC: if fp.read(4) != MAGIC:
raise error, 'gethdr: bad magic word' raise error, 'gethdr: bad magic word'
hdr_size = get_long_be(fp.read(4)) hdr_size = get_long_be(fp.read(4))
data_size = get_long_be(fp.read(4)) data_size = get_long_be(fp.read(4))

View File

@ -63,7 +63,7 @@ def toaiff(filename):
ret = _toaiff(filename, temps) ret = _toaiff(filename, temps)
finally: finally:
for temp in temps[:]: for temp in temps[:]:
if temp <> ret: if temp != ret:
try: try:
os.unlink(temp) os.unlink(temp)
except os.error: except os.error:
@ -88,12 +88,12 @@ def _toaiff(filename, temps):
if type(msg) == type(()) and len(msg) == 2 and \ if type(msg) == type(()) and len(msg) == 2 and \
type(msg[0]) == type(0) and type(msg[1]) == type(''): type(msg[0]) == type(0) and type(msg[1]) == type(''):
msg = msg[1] msg = msg[1]
if type(msg) <> type(''): if type(msg) != type(''):
msg = `msg` msg = `msg`
raise error, filename + ': ' + msg raise error, filename + ': ' + msg
if ftype == 'aiff': if ftype == 'aiff':
return fname return fname
if ftype == None or not table.has_key(ftype): if ftype is None or not table.has_key(ftype):
raise error, \ raise error, \
filename + ': unsupported audio file type ' + `ftype` filename + ': unsupported audio file type ' + `ftype`
temp = tempfile.mktemp() temp = tempfile.mktemp()

View File

@ -16,7 +16,7 @@ def tzparse(tzstr):
timezone, and 'daystart'/'hourstart' and 'dayend'/'hourend' timezone, and 'daystart'/'hourstart' and 'dayend'/'hourend'
specify the starting and ending points for daylight saving time.""" specify the starting and ending points for daylight saving time."""
global tzprog global tzprog
if tzprog == None: if tzprog is None:
import re import re
tzprog = re.compile(tzpat) tzprog = re.compile(tzpat)
match = tzprog.match(tzstr) match = tzprog.match(tzstr)

View File

@ -46,9 +46,9 @@ def encode(in_file, out_file, name=None, mode=None):
if in_file == '-': if in_file == '-':
in_file = sys.stdin in_file = sys.stdin
elif type(in_file) == type(''): elif type(in_file) == type(''):
if name == None: if name is None:
name = os.path.basename(in_file) name = os.path.basename(in_file)
if mode == None: if mode is None:
try: try:
mode = os.stat(in_file)[0] mode = os.stat(in_file)[0]
except AttributeError: except AttributeError:
@ -64,9 +64,9 @@ def encode(in_file, out_file, name=None, mode=None):
# #
# Set defaults for name and mode # Set defaults for name and mode
# #
if name == None: if name is None:
name = '-' name = '-'
if mode == None: if mode is None:
mode = 0666 mode = 0666
# #
# Write the data # Write the data
@ -104,9 +104,9 @@ def decode(in_file, out_file=None, mode=None):
break break
except ValueError: except ValueError:
pass pass
if out_file == None: if out_file is None:
out_file = hdrfields[2] out_file = hdrfields[2]
if mode == None: if mode is None:
mode = string.atoi(hdrfields[1], 8) mode = string.atoi(hdrfields[1], 8)
# #
# Open the output file # Open the output file

View File

@ -95,7 +95,7 @@ class Packer:
self.pack_uint(0) self.pack_uint(0)
def pack_farray(self, n, list, pack_item): def pack_farray(self, n, list, pack_item):
if len(list) <> n: if len(list) != n:
raise ValueError, 'wrong array size' raise ValueError, 'wrong array size'
for item in list: for item in list:
pack_item(item) pack_item(item)
@ -204,7 +204,7 @@ class Unpacker:
while 1: while 1:
x = self.unpack_uint() x = self.unpack_uint()
if x == 0: break if x == 0: break
if x <> 1: if x != 1:
raise ConversionError, '0 or 1 expected, got ' + `x` raise ConversionError, '0 or 1 expected, got ' + `x`
item = unpack_item() item = unpack_item()
list.append(item) list.append(item)

View File

@ -421,7 +421,7 @@ class XMLParser:
# Internal -- parse comment, return length or -1 if not terminated # Internal -- parse comment, return length or -1 if not terminated
def parse_comment(self, i): def parse_comment(self, i):
rawdata = self.rawdata rawdata = self.rawdata
if rawdata[i:i+4] <> '<!--': if rawdata[i:i+4] != '<!--':
raise Error('unexpected call to handle_comment') raise Error('unexpected call to handle_comment')
res = commentclose.search(rawdata, i+4) res = commentclose.search(rawdata, i+4)
if res is None: if res is None:
@ -487,7 +487,7 @@ class XMLParser:
# Internal -- handle CDATA tag, return length or -1 if not terminated # Internal -- handle CDATA tag, return length or -1 if not terminated
def parse_cdata(self, i): def parse_cdata(self, i):
rawdata = self.rawdata rawdata = self.rawdata
if rawdata[i:i+9] <> '<![CDATA[': if rawdata[i:i+9] != '<![CDATA[':
raise Error('unexpected call to parse_cdata') raise Error('unexpected call to parse_cdata')
res = cdataclose.search(rawdata, i+9) res = cdataclose.search(rawdata, i+9)
if res is None: if res is None: