Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8152d32

Browse files
committed
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.
1 parent c140131 commit 8152d32

36 files changed

Lines changed: 101 additions & 99 deletions

Lib/Cookie.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ def OutputString(self, attrs=None):
489489
RA("%s=%s;" % (self.key, self.coded_value))
490490

491491
# Now add any defined attributes
492-
if attrs == None:
492+
if attrs is None:
493493
attrs = self._reserved_keys
494494
for K,V in self.items():
495495
if V == "": continue

Lib/binhex.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def __init__(self, (name, finfo, dlen, rlen), ofp):
189189
hqxer = _Hqxcoderengine(ofp)
190190
self.ofp = _Rlecoderengine(hqxer)
191191
self.crc = 0
192-
if finfo == None:
192+
if finfo is None:
193193
finfo = FInfo()
194194
self.dlen = dlen
195195
self.rlen = rlen
@@ -228,7 +228,7 @@ def write(self, data):
228228
self._write(data)
229229

230230
def close_data(self):
231-
if self.dlen <> 0:
231+
if self.dlen != 0:
232232
raise Error, 'Incorrect data size, diff='+`self.rlen`
233233
self._writecrc()
234234
self.state = _DID_DATA
@@ -246,7 +246,7 @@ def close(self):
246246
self.close_data()
247247
if self.state != _DID_DATA:
248248
raise Error, 'Close at the wrong time'
249-
if self.rlen <> 0:
249+
if self.rlen != 0:
250250
raise Error, \
251251
"Incorrect resource-datasize, diff="+`self.rlen`
252252
self._writecrc()

Lib/calendar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def setfirstweekday(weekday):
5050

5151
def isleap(year):
5252
"""Return 1 for leap years, 0 for non-leap years."""
53-
return year % 4 == 0 and (year % 100 <> 0 or year % 400 == 0)
53+
return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)
5454

5555
def leapdays(y1, y2):
5656
"""Return number of leap years in range [y1, y2).

Lib/cmd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def __init__(self): pass
5757

5858
def cmdloop(self, intro=None):
5959
self.preloop()
60-
if intro != None:
60+
if intro is not None:
6161
self.intro = intro
6262
if self.intro:
6363
print self.intro

Lib/commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def getstatusoutput(cmd):
5151
pipe = os.popen('{ ' + cmd + '; } 2>&1', 'r')
5252
text = pipe.read()
5353
sts = pipe.close()
54-
if sts == None: sts = 0
54+
if sts is None: sts = 0
5555
if text[-1:] == '\n': text = text[:-1]
5656
return sts, text
5757

Lib/dircache.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def listdir(path):
1919
mtime = os.stat(path)[8]
2020
except os.error:
2121
return []
22-
if mtime <> cached_mtime:
22+
if mtime != cached_mtime:
2323
try:
2424
list = os.listdir(path)
2525
except os.error:

Lib/dospath.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def commonprefix(m):
108108
prefix = m[0]
109109
for item in m:
110110
for i in range(len(prefix)):
111-
if prefix[:i+1] <> item[:i+1]:
111+
if prefix[:i+1] != item[:i+1]:
112112
prefix = prefix[:i]
113113
if i == 0: return ''
114114
break
@@ -210,7 +210,7 @@ def expanduser(path):
210210
(A function should also be defined to do full *sh-style environment
211211
variable expansion.)"""
212212

213-
if path[:1] <> '~':
213+
if path[:1] != '~':
214214
return path
215215
i, n = 1, len(path)
216216
while i < n and path[i] not in '/\\':
@@ -303,7 +303,7 @@ def normpath(path):
303303
comps[i-1] not in ('', '..'):
304304
del comps[i-1:i+1]
305305
i = i - 1
306-
elif comps[i] == '' and i > 0 and comps[i-1] <> '':
306+
elif comps[i] == '' and i > 0 and comps[i-1] != '':
307307
del comps[i]
308308
elif '.' in comps[i]:
309309
comp = comps[i].split('.')

Lib/filecmp.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def phase2(self): # Distinguish files, directories, funnies
199199
if ok:
200200
a_type = stat.S_IFMT(a_stat[stat.ST_MODE])
201201
b_type = stat.S_IFMT(b_stat[stat.ST_MODE])
202-
if a_type <> b_type:
202+
if a_type != b_type:
203203
self.common_funny.append(x)
204204
elif stat.S_ISDIR(a_type):
205205
self.common_dirs.append(x)
@@ -317,7 +317,8 @@ def demo():
317317
import sys
318318
import getopt
319319
options, args = getopt.getopt(sys.argv[1:], 'r')
320-
if len(args) <> 2: raise getopt.error, 'need exactly two args'
320+
if len(args) != 2:
321+
raise getopt.error, 'need exactly two args'
321322
dd = dircmp(args[0], args[1])
322323
if ('-r', '') in options:
323324
dd.report_full_closure()

Lib/ftplib.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def getmultiline(self):
185185
nextline = self.getline()
186186
line = line + ('\n' + nextline)
187187
if nextline[:3] == code and \
188-
nextline[3:4] <> '-':
188+
nextline[3:4] != '-':
189189
break
190190
return line
191191

@@ -207,7 +207,7 @@ def getresp(self):
207207
def voidresp(self):
208208
"""Expect a response beginning with '2'."""
209209
resp = self.getresp()
210-
if resp[0] <> '2':
210+
if resp[0] != '2':
211211
raise error_reply, resp
212212
return resp
213213

@@ -277,14 +277,14 @@ def ntransfercmd(self, cmd, rest=None):
277277
if rest is not None:
278278
self.sendcmd("REST %s" % rest)
279279
resp = self.sendcmd(cmd)
280-
if resp[0] <> '1':
280+
if resp[0] != '1':
281281
raise error_reply, resp
282282
else:
283283
sock = self.makeport()
284284
if rest is not None:
285285
self.sendcmd("REST %s" % rest)
286286
resp = self.sendcmd(cmd)
287-
if resp[0] <> '1':
287+
if resp[0] != '1':
288288
raise error_reply, resp
289289
conn, sockaddr = sock.accept()
290290
if resp[:3] == '150':
@@ -318,7 +318,7 @@ def login(self, user = '', passwd = '', acct = ''):
318318
resp = self.sendcmd('USER ' + user)
319319
if resp[0] == '3': resp = self.sendcmd('PASS ' + passwd)
320320
if resp[0] == '3': resp = self.sendcmd('ACCT ' + acct)
321-
if resp[0] <> '2':
321+
if resp[0] != '2':
322322
raise error_reply, resp
323323
return resp
324324

@@ -384,7 +384,7 @@ def storlines(self, cmd, fp):
384384
while 1:
385385
buf = fp.readline()
386386
if not buf: break
387-
if buf[-2:] <> CRLF:
387+
if buf[-2:] != CRLF:
388388
if buf[-1] in CRLF: buf = buf[:-1]
389389
buf = buf + CRLF
390390
conn.send(buf)
@@ -423,7 +423,7 @@ def dir(self, *args):
423423
def rename(self, fromname, toname):
424424
'''Rename a file.'''
425425
resp = self.sendcmd('RNFR ' + fromname)
426-
if resp[0] <> '3':
426+
if resp[0] != '3':
427427
raise error_reply, resp
428428
return self.voidcmd('RNTO ' + toname)
429429

@@ -508,15 +508,15 @@ def parse227(resp):
508508
Raises error_proto if it does not contain '(h1,h2,h3,h4,p1,p2)'
509509
Return ('host.addr.as.numbers', port#) tuple.'''
510510

511-
if resp[:3] <> '227':
511+
if resp[:3] != '227':
512512
raise error_reply, resp
513513
left = string.find(resp, '(')
514514
if left < 0: raise error_proto, resp
515515
right = string.find(resp, ')', left + 1)
516516
if right < 0:
517517
raise error_proto, resp # should contain '(h1,h2,h3,h4,p1,p2)'
518518
numbers = string.split(resp[left+1:right], ',')
519-
if len(numbers) <> 6:
519+
if len(numbers) != 6:
520520
raise error_proto, resp
521521
host = string.join(numbers[:4], '.')
522522
port = (string.atoi(numbers[4]) << 8) + string.atoi(numbers[5])
@@ -528,9 +528,9 @@ def parse257(resp):
528528
This is a response to a MKD or PWD request: a directory name.
529529
Returns the directoryname in the 257 reply.'''
530530

531-
if resp[:3] <> '257':
531+
if resp[:3] != '257':
532532
raise error_reply, resp
533-
if resp[3:5] <> ' "':
533+
if resp[3:5] != ' "':
534534
return '' # Not compliant to RFC 959, but UNIX ftpd does this
535535
dirname = ''
536536
i = 5
@@ -539,7 +539,7 @@ def parse257(resp):
539539
c = resp[i]
540540
i = i+1
541541
if c == '"':
542-
if i >= n or resp[i] <> '"':
542+
if i >= n or resp[i] != '"':
543543
break
544544
i = i+1
545545
dirname = dirname + c

Lib/imputil.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ def join(a, b):
434434
path = s
435435
if ':' not in a:
436436
a = ':' + a
437-
if a[-1:] <> ':':
437+
if a[-1:] != ':':
438438
a = a + ':'
439439
return a + b
440440
else:
@@ -643,7 +643,7 @@ def _test_revamp():
643643
# from Guido:
644644
# need to change sys.* references for rexec environs
645645
# need hook for MAL's walk-me-up import strategy, or Tim's absolute strategy
646-
# watch out for sys.modules[...] == None
646+
# watch out for sys.modules[...] is None
647647
# flag to force absolute imports? (speeds _determine_import_context and
648648
# checking for a relative module)
649649
# insert names of archives into sys.path (see quote below)

0 commit comments

Comments
 (0)