Make consistent use of str.startswith() in conditionals.
# HG changeset patch
# User chad.netzer@gmail.com
# Node ID 45db196de89a15fd045cd789f701b0180fd276f1
# Parent fafc16f705b6cb413897577b67918af55e1baafe
Make consistent use of str.startswith() in conditionals.
--- a/mercurial/byterange.py Sun Jul 10 16:14:41 2005 -0800
+++ b/mercurial/byterange.py Sun Jul 10 16:14:56 2005 -0800
@@ -361,12 +361,12 @@
cmd = 'RETR ' + file
conn = self.ftp.ntransfercmd(cmd, rest)
except ftplib.error_perm, reason:
- if str(reason)[:3] == '501':
+ if str(reason).startswith('501'):
# workaround for REST not supported error
fp, retrlen = self.retrfile(file, type)
fp = RangeableFileObject(fp, (rest,''))
return (fp, retrlen)
- elif str(reason)[:3] != '550':
+ elif not str(reason).startswith('550'):
raise IOError, ('ftp error', reason), sys.exc_info()[2]
if not conn:
# Set transfer mode to ASCII!
--- a/mercurial/commands.py Sun Jul 10 16:14:41 2005 -0800
+++ b/mercurial/commands.py Sun Jul 10 16:14:56 2005 -0800
@@ -606,10 +606,10 @@
ui.debug(t,'\n')
if t == '# HG changeset patch' or hgpatch == True:
hgpatch = True
- if t[:7] == "# User ":
+ if t.startswith("# User "):
user = t[7:]
ui.debug('User: %s\n' % user)
- if t[:2] <> "# " and t.strip() and not snippet: snippet = t
+ if not t.startswith("# ") and t.strip() and not snippet: snippet = t
if snippet: text = snippet + '\n' + text
ui.debug('text:\n%s\n' % text)
@@ -621,7 +621,7 @@
for l in f.read().splitlines():
l.rstrip('\r\n');
ui.status("%s\n" % l)
- if l[:14] == 'patching file ':
+ if l.startswith('patching file '):
pf = l[14:]
if pf not in files:
files.append(pf)
--- a/mercurial/hg.py Sun Jul 10 16:14:41 2005 -0800
+++ b/mercurial/hg.py Sun Jul 10 16:14:56 2005 -0800
@@ -21,14 +21,14 @@
def read(self, node):
t = self.revision(node)
- if t[:2] != '\1\n':
+ if not t.startswith('\1\n'):
return t
s = t.find('\1\n', 2)
return t[s+2:]
def readmeta(self, node):
t = self.revision(node)
- if t[:2] != '\1\n':
+ if not t.startswith('\1\n'):
return t
s = t.find('\1\n', 2)
mt = t[2:s]
@@ -38,7 +38,7 @@
return m
def add(self, text, meta, transaction, link, p1=None, p2=None):
- if meta or text[:2] == '\1\n':
+ if meta or text.startswith('\1\n'):
mt = ""
if meta:
mt = [ "%s: %s\n" % (k, v) for k,v in meta.items() ]
@@ -436,7 +436,7 @@
def opener(base):
p = base
def o(path, mode="r"):
- if p[:7] == "http://":
+ if p.startswith("http://"):
f = os.path.join(p, urllib.quote(path))
return httprangereader.httprangereader(f)
@@ -465,7 +465,7 @@
class localrepository:
def __init__(self, ui, path=None, create=0):
self.remote = 0
- if path and path[:7] == "http://":
+ if path and path.startswith("http://"):
self.remote = 1
self.path = path
else: