Use != instead of <> since <> is documented as "obsolescent".
Use "is" and "is not" when comparing with None or type objects.
RA("%s=%s;" % (self.key, self.coded_value))
# Now add any defined attributes
- if attrs == None:
+ if attrs is None:
attrs = self._reserved_keys
for K,V in self.items():
if V == "": continue
hqxer = _Hqxcoderengine(ofp)
self.ofp = _Rlecoderengine(hqxer)
self.crc = 0
- if finfo == None:
+ if finfo is None:
finfo = FInfo()
self.dlen = dlen
self.rlen = rlen
self._write(data)
def close_data(self):
- if self.dlen <> 0:
+ if self.dlen != 0:
raise Error, 'Incorrect data size, diff='+`self.rlen`
self._writecrc()
self.state = _DID_DATA
self.close_data()
if self.state != _DID_DATA:
raise Error, 'Close at the wrong time'
- if self.rlen <> 0:
+ if self.rlen != 0:
raise Error, \
"Incorrect resource-datasize, diff="+`self.rlen`
self._writecrc()
def isleap(year):
"""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):
"""Return number of leap years in range [y1, y2).
def cmdloop(self, intro=None):
self.preloop()
- if intro != None:
+ if intro is not None:
self.intro = intro
if self.intro:
print self.intro
pipe = os.popen('{ ' + cmd + '; } 2>&1', 'r')
text = pipe.read()
sts = pipe.close()
- if sts == None: sts = 0
+ if sts is None: sts = 0
if text[-1:] == '\n': text = text[:-1]
return sts, text
mtime = os.stat(path)[8]
except os.error:
return []
- if mtime <> cached_mtime:
+ if mtime != cached_mtime:
try:
list = os.listdir(path)
except os.error:
prefix = m[0]
for item in m:
for i in range(len(prefix)):
- if prefix[:i+1] <> item[:i+1]:
+ if prefix[:i+1] != item[:i+1]:
prefix = prefix[:i]
if i == 0: return ''
break
(A function should also be defined to do full *sh-style environment
variable expansion.)"""
- if path[:1] <> '~':
+ if path[:1] != '~':
return path
i, n = 1, len(path)
while i < n and path[i] not in '/\\':
comps[i-1] not in ('', '..'):
del comps[i-1: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]
elif '.' in comps[i]:
comp = comps[i].split('.')
if ok:
a_type = stat.S_IFMT(a_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)
elif stat.S_ISDIR(a_type):
self.common_dirs.append(x)
import sys
import getopt
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])
if ('-r', '') in options:
dd.report_full_closure()
nextline = self.getline()
line = line + ('\n' + nextline)
if nextline[:3] == code and \
- nextline[3:4] <> '-':
+ nextline[3:4] != '-':
break
return line
def voidresp(self):
"""Expect a response beginning with '2'."""
resp = self.getresp()
- if resp[0] <> '2':
+ if resp[0] != '2':
raise error_reply, resp
return resp
if rest is not None:
self.sendcmd("REST %s" % rest)
resp = self.sendcmd(cmd)
- if resp[0] <> '1':
+ if resp[0] != '1':
raise error_reply, resp
else:
sock = self.makeport()
if rest is not None:
self.sendcmd("REST %s" % rest)
resp = self.sendcmd(cmd)
- if resp[0] <> '1':
+ if resp[0] != '1':
raise error_reply, resp
conn, sockaddr = sock.accept()
if resp[:3] == '150':
resp = self.sendcmd('USER ' + user)
if resp[0] == '3': resp = self.sendcmd('PASS ' + passwd)
if resp[0] == '3': resp = self.sendcmd('ACCT ' + acct)
- if resp[0] <> '2':
+ if resp[0] != '2':
raise error_reply, resp
return resp
while 1:
buf = fp.readline()
if not buf: break
- if buf[-2:] <> CRLF:
+ if buf[-2:] != CRLF:
if buf[-1] in CRLF: buf = buf[:-1]
buf = buf + CRLF
conn.send(buf)
def rename(self, fromname, toname):
'''Rename a file.'''
resp = self.sendcmd('RNFR ' + fromname)
- if resp[0] <> '3':
+ if resp[0] != '3':
raise error_reply, resp
return self.voidcmd('RNTO ' + toname)
Raises error_proto if it does not contain '(h1,h2,h3,h4,p1,p2)'
Return ('host.addr.as.numbers', port#) tuple.'''
- if resp[:3] <> '227':
+ if resp[:3] != '227':
raise error_reply, resp
left = string.find(resp, '(')
if left < 0: raise error_proto, resp
if right < 0:
raise error_proto, resp # should contain '(h1,h2,h3,h4,p1,p2)'
numbers = string.split(resp[left+1:right], ',')
- if len(numbers) <> 6:
+ if len(numbers) != 6:
raise error_proto, resp
host = string.join(numbers[:4], '.')
port = (string.atoi(numbers[4]) << 8) + string.atoi(numbers[5])
This is a response to a MKD or PWD request: a directory name.
Returns the directoryname in the 257 reply.'''
- if resp[:3] <> '257':
+ if resp[:3] != '257':
raise error_reply, resp
- if resp[3:5] <> ' "':
+ if resp[3:5] != ' "':
return '' # Not compliant to RFC 959, but UNIX ftpd does this
dirname = ''
i = 5
c = resp[i]
i = i+1
if c == '"':
- if i >= n or resp[i] <> '"':
+ if i >= n or resp[i] != '"':
break
i = i+1
dirname = dirname + c
path = s
if ':' not in a:
a = ':' + a
- if a[-1:] <> ':':
+ if a[-1:] != ':':
a = a + ':'
return a + b
else:
# from Guido:
# need to change sys.* references for rexec environs
# 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
# checking for a relative module)
# insert names of archives into sys.path (see quote below)
except os.error:
del cache[filename]
continue
- if size <> stat[ST_SIZE] or mtime <> stat[ST_MTIME]:
+ if size != stat[ST_SIZE] or mtime != stat[ST_MTIME]:
del cache[filename]
Anything else is absolute (the string up to the first colon is the
volume name)."""
- return ':' in s and s[0] <> ':'
+ return ':' in s and s[0] != ':'
def join(s, *p):
t = t[1:]
if ':' not in path:
path = ':' + path
- if path[-1:] <> ':':
+ if path[-1:] != ':':
path = path + ':'
path = path + t
return path
prefix = m[0]
for item in m:
for i in range(len(prefix)):
- if prefix[:i+1] <> item[:i+1]:
+ if prefix[:i+1] != item[:i+1]:
prefix = prefix[:i]
if i == 0: return ''
break
# XXXX The .. handling should be fixed...
#
tp = urllib.splittype(pathname)[0]
- if tp and tp <> 'file':
+ if tp and tp != 'file':
raise RuntimeError, 'Cannot convert non-local URL to pathname'
# Turn starting /// into /, an empty hostname means current host
if pathname[:3] == '///':
components[i-1] not in ('', '..'):
del components[i-1: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]
else:
i = i+1
start = self.fp.tell()
self._search_end()
self.seekp = stop = self.fp.tell()
- if start <> stop:
+ if start != stop:
break
return rfc822.Message(_Subfile(self.fp, start, stop))
i, n = 0, len(field)
while i < n:
c = field[i]; i = i+1
- if c <> '%':
+ if c != '%':
if c == '\\':
c = field[i:i+1]; i = i+1
res = res + c
res = res + MIMEtype
elif c == '{':
start = i
- while i < n and field[i] <> '}':
+ while i < n and field[i] != '}':
i = i+1
name = field[start:i]
i = i+1
line = f.readline()
if not line: break
fields = string.splitfields(line, ':')
- if len(fields) <> 2:
+ if len(fields) != 2:
self.error('bad sequence in %s: %s' %
(fullname, string.strip(line)))
key = string.strip(fields[0])
def parsetype(self):
str = self.typeheader
- if str == None:
+ if str is None:
str = 'text/plain'
if ';' in str:
i = string.index(str, ';')
return result
def getencoding(self):
- if self.encodingheader == None:
+ if self.encodingheader is None:
return '7bit'
return string.lower(self.encodingheader)
global _prefix
import time
import random
- if _prefix == None:
+ if _prefix is None:
import socket
import os
hostid = socket.gethostbyname(socket.gethostname())
self.lastpos = abslastpos - self.start
def is_data(self, line):
- return line[:2] <> '--'
+ return line[:2] != '--'
def section_divider(self, str):
return "--" + str
while 1:
# Look for a machine, default, or macdef top-level keyword
toplevel = tt = lexer.get_token()
- if tt == '' or tt == None:
+ if not tt:
break
elif tt == 'machine':
entryname = lexer.get_token()
- name: the group name"""
resp = self.shortcmd('GROUP ' + name)
- if resp[:3] <> '211':
+ if resp[:3] != '211':
raise NNTPReplyError(resp)
words = string.split(resp)
count = first = last = 0
def statparse(self, resp):
"""Internal: parse the response of a STAT, NEXT or LAST command."""
- if resp[:2] <> '22':
+ if resp[:2] != '22':
raise NNTPReplyError(resp)
words = string.split(resp)
nr = 0
path: directory path to article"""
resp = self.shortcmd("XPATH " + id)
- if resp[:3] <> '223':
+ if resp[:3] != '223':
raise NNTPReplyError(resp)
try:
[resp_num, path] = string.split(resp)
time: Time suitable for newnews/newgroups commands etc."""
resp = self.shortcmd("DATE")
- if resp[:3] <> '111':
+ if resp[:3] != '111':
raise NNTPReplyError(resp)
elem = string.split(resp)
if len(elem) != 2:
resp = self.shortcmd('POST')
# Raises error_??? if posting is not allowed
- if resp[0] <> '3':
+ if resp[0] != '3':
raise NNTPReplyError(resp)
while 1:
line = f.readline()
resp = self.shortcmd('IHAVE ' + id)
# Raises error_??? if the server already has it
- if resp[0] <> '3':
+ if resp[0] != '3':
raise NNTPReplyError(resp)
while 1:
line = f.readline()
prefix = m[0]
for item in m:
for i in range(len(prefix)):
- if prefix[:i+1] <> item[:i+1]:
+ if prefix[:i+1] != item[:i+1]:
prefix = prefix[:i]
if i == 0: return ''
break
"""Expand ~ and ~user constructs.
If user or $HOME is unknown, do nothing."""
- if path[:1] <> '~':
+ if path[:1] != '~':
return path
i, n = 1, len(path)
while i < n and path[i] not in '/\\':
elif comps[i] == '..' and i > 0 and comps[i-1] not in ('', '..'):
del comps[i-1: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]
else:
i = i + 1
first = max(1, self.curframe.f_lineno - 5)
else:
first = self.lineno + 1
- if last == None:
+ if last is None:
last = first + 10
filename = self.curframe.f_code.co_filename
breaklist = self.get_file_breaks(filename)
def post_mortem(t):
p = Pdb()
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)
def pm():
def append(self, cmd, kind):
"""t.append(cmd, kind) adds a new step at the end."""
- if type(cmd) <> type(''):
+ if type(cmd) is not type(''):
raise TypeError, \
'Template.append: cmd must be a string'
if kind not in stepkinds:
if kind == SOURCE:
raise ValueError, \
'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, \
'Template.append: already ends with SINK'
if kind[0] == 'f' and not re.search('\$IN\b', cmd):
def prepend(self, cmd, kind):
"""t.prepend(cmd, kind) adds a new step at the front."""
- if type(cmd) <> type(''):
+ if type(cmd) is not type(''):
raise TypeError, \
'Template.prepend: cmd must be a string'
if kind not in stepkinds:
if kind == SINK:
raise ValueError, \
'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, \
'Template.prepend: already begins with SOURCE'
if kind[0] == 'f' and not re.search('\$IN\b', cmd):
def open_r(self, file):
"""t.open_r(file) and t.open_w(file) implement
t.open(file, 'r') and t.open(file, 'w') respectively."""
- if self.steps == []:
+ if not self.steps:
return open(file, 'r')
if self.steps[-1][1] == SINK:
raise ValueError, \
return os.popen(cmd, 'r')
def open_w(self, file):
- if self.steps == []:
+ if not self.steps:
return open(file, 'w')
if self.steps[0][1] == SOURCE:
raise ValueError, \
#
# Make sure there is at least one step
#
- if list == []:
+ if not list:
list.append(['', 'cat', '--', ''])
#
# Take care of the input and output ends
everything after the final slash. Either part may be empty."""
i = p.rfind('/') + 1
head, tail = p[:i], p[i:]
- if head and head <> '/'*len(head):
+ if head and head != '/'*len(head):
while head[-1] == '/':
head = head[:-1]
return head, tail
prefix = m[0]
for item in m:
for i in range(len(prefix)):
- if prefix[:i+1] <> item[:i+1]:
+ if prefix[:i+1] != item[:i+1]:
prefix = prefix[:i]
if i == 0: return ''
break
def expanduser(path):
"""Expand ~ and ~user constructions. If user or $HOME is unknown,
do nothing."""
- if path[:1] <> '~':
+ if path[:1] != '~':
return path
i, n = 1, len(path)
- while i < n and path[i] <> '/':
+ while i < n and path[i] != '/':
i = i + 1
if i == 1:
if not os.environ.has_key('HOME'):
partial = 1
while i < n:
c = line[i]
- if c <> ESCAPE:
+ if c != ESCAPE:
new = new + c; i = i+1
elif i+1 == n and not partial:
partial = 1; break
cache = {}
def compile(pat):
- if type(pat) <> type(''):
+ if type(pat) != type(''):
return pat # Assume it is a compiled regex
key = (pat, regex.get_syntax())
if cache.has_key(key):
ord0 = ord('0')
while i < len(repl):
c = repl[i]; i = i+1
- if c <> '\\' or i >= len(repl):
+ if c != '\\' or i >= len(repl):
new = new + c
else:
c = repl[i]; i = i+1
if not line: break
if line[-1] == '\n': line = line[:-1]
fields = split(line, delpat)
- if len(fields) <> 3:
+ if len(fields) != 3:
print 'Sorry, not three fields'
print 'split:', `fields`
continue
# Internal -- parse comment, return length or -1 if not terminated
def parse_comment(self, i):
rawdata = self.rawdata
- if rawdata[i:i+4] <> '<!--':
+ if rawdata[i:i+4] != '<!--':
raise RuntimeError, 'unexpected call to handle_comment'
match = commentclose.search(rawdata, i+4)
if not match:
# Internal -- parse processing instr, return length or -1 if not terminated
def parse_pi(self, i):
rawdata = self.rawdata
- if rawdata[i:i+2] <> '<?':
+ if rawdata[i:i+2] != '<?':
raise RuntimeError, 'unexpected call to handle_pi'
match = piclose.search(rawdata, i+2)
if not match:
if code == -1 and len(msg) == 0:
raise SMTPServerDisconnected("Server not connected")
self.ehlo_resp=msg
- if code<>250:
+ if code != 250:
return (code,msg)
self.does_esmtp=1
#parse the ehlo response -ddm
self.putcmd("data")
(code,repl)=self.getreply()
if self.debuglevel >0 : print "data:", (code,repl)
- if code <> 354:
+ if code != 354:
raise SMTPDataError(code,repl)
else:
q = quotedata(msg)
esmtp_opts.append(option)
(code,resp) = self.mail(from_addr, esmtp_opts)
- if code <> 250:
+ if code != 250:
self.rset()
raise SMTPSenderRefused(code, resp, from_addr)
senderrs={}
to_addrs = [to_addrs]
for each in to_addrs:
(code,resp)=self.rcpt(each, rcpt_options)
- if (code <> 250) and (code <> 251):
+ if (code != 250) and (code != 251):
senderrs[each]=(code,resp)
if len(senderrs)==len(to_addrs):
# the server refused all our recipients
self.rset()
raise SMTPRecipientsRefused(senderrs)
- (code,resp)=self.data(msg)
- if code <> 250:
+ (code,resp) = self.data(msg)
+ if code != 250:
self.rset()
raise SMTPDataError(code, resp)
#if we got here then somebody got our mail
def test_aifc(h, f):
import aifc
- if h[:4] <> 'FORM':
+ if h[:4] != 'FORM':
return None
if h[8:12] == 'AIFC':
fmt = 'aifc'
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
divisor = get_long_be(h[128+16:128+20])
return 'hcom', 22050/divisor, 1, -1, 8
def test_voc(h, f):
- if h[:20] <> 'Creative Voice File\032':
+ if h[:20] != 'Creative Voice File\032':
return None
sbseek = get_short_le(h[20:22])
rate = 0
def test_wav(h, f):
# '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
style = get_short_le(h[20:22])
nchannels = get_short_le(h[22:24])
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
# Should decode it to get #channels -- assume always 1
return '8svx', 0, 1, 0, 8
def forget_dir(prefix):
"""Forget about a directory and all entries in it, but not about
entries in subdirectories."""
- if prefix[-1:] == '/' and prefix <> '/':
+ if prefix[-1:] == '/' and prefix != '/':
prefix = prefix[:-1]
forget(prefix)
- if prefix[-1:] <> '/':
+ if prefix[-1:] != '/':
prefix = prefix + '/'
n = len(prefix)
for path in cache.keys():
Normally used with prefix = '/' after a chdir()."""
n = len(prefix)
for path in cache.keys():
- if path[:n] <> prefix:
+ if path[:n] != prefix:
del cache[path]
def gethdr(fp):
"""Read a sound header from an open file."""
- if fp.read(4) <> MAGIC:
+ if fp.read(4) != MAGIC:
raise error, 'gethdr: bad magic word'
hdr_size = get_long_be(fp.read(4))
data_size = get_long_be(fp.read(4))
ret = _toaiff(filename, temps)
finally:
for temp in temps[:]:
- if temp <> ret:
+ if temp != ret:
try:
os.unlink(temp)
except os.error:
if type(msg) == type(()) and len(msg) == 2 and \
type(msg[0]) == type(0) and type(msg[1]) == type(''):
msg = msg[1]
- if type(msg) <> type(''):
+ if type(msg) != type(''):
msg = `msg`
raise error, filename + ': ' + msg
if ftype == 'aiff':
return fname
- if ftype == None or not table.has_key(ftype):
+ if ftype is None or not table.has_key(ftype):
raise error, \
filename + ': unsupported audio file type ' + `ftype`
temp = tempfile.mktemp()
timezone, and 'daystart'/'hourstart' and 'dayend'/'hourend'
specify the starting and ending points for daylight saving time."""
global tzprog
- if tzprog == None:
+ if tzprog is None:
import re
tzprog = re.compile(tzpat)
match = tzprog.match(tzstr)
if in_file == '-':
in_file = sys.stdin
elif type(in_file) == type(''):
- if name == None:
+ if name is None:
name = os.path.basename(in_file)
- if mode == None:
+ if mode is None:
try:
mode = os.stat(in_file)[0]
except AttributeError:
#
# Set defaults for name and mode
#
- if name == None:
+ if name is None:
name = '-'
- if mode == None:
+ if mode is None:
mode = 0666
#
# Write the data
break
except ValueError:
pass
- if out_file == None:
+ if out_file is None:
out_file = hdrfields[2]
- if mode == None:
+ if mode is None:
mode = string.atoi(hdrfields[1], 8)
#
# Open the output file
self.pack_uint(0)
def pack_farray(self, n, list, pack_item):
- if len(list) <> n:
+ if len(list) != n:
raise ValueError, 'wrong array size'
for item in list:
pack_item(item)
while 1:
x = self.unpack_uint()
if x == 0: break
- if x <> 1:
+ if x != 1:
raise ConversionError, '0 or 1 expected, got ' + `x`
item = unpack_item()
list.append(item)
# Internal -- parse comment, return length or -1 if not terminated
def parse_comment(self, i):
rawdata = self.rawdata
- if rawdata[i:i+4] <> '<!--':
+ if rawdata[i:i+4] != '<!--':
raise Error('unexpected call to handle_comment')
res = commentclose.search(rawdata, i+4)
if res is None:
# Internal -- handle CDATA tag, return length or -1 if not terminated
def parse_cdata(self, i):
rawdata = self.rawdata
- if rawdata[i:i+9] <> '<![CDATA[':
+ if rawdata[i:i+9] != '<![CDATA[':
raise Error('unexpected call to parse_cdata')
res = cdataclose.search(rawdata, i+9)
if res is None: