]> granicus.if.org Git - python/commitdiff
Make use of new str.startswith/endswith semantics.
authorGeorg Brandl <georg@python.org>
Fri, 9 Jun 2006 20:43:48 +0000 (20:43 +0000)
committerGeorg Brandl <georg@python.org>
Fri, 9 Jun 2006 20:43:48 +0000 (20:43 +0000)
Occurences in email and compiler were ignored due to backwards compat requirements.

Lib/_MozillaCookieJar.py
Lib/difflib.py
Lib/idlelib/EditorWindow.py
Lib/idlelib/configHandler.py
Lib/idlelib/configHelpSourceEdit.py
Lib/test/test_compiler.py
Lib/test/test_inspect.py
Lib/test/test_tcl.py
Lib/trace.py
Lib/warnings.py
Lib/webbrowser.py

index 1776b930f6d190da46714577ef2331ef6a891605..4fd6de32cb0a35527ac16eb48f4869178bbff7e2 100644 (file)
@@ -63,8 +63,7 @@ class MozillaCookieJar(FileCookieJar):
                 if line.endswith("\n"): line = line[:-1]
 
                 # skip comments and blank lines XXX what is $ for?
-                if (line.strip().startswith("#") or
-                    line.strip().startswith("$") or
+                if (line.strip().startswith(("#", "$")) or
                     line.strip() == ""):
                     continue
 
index 55f69bac791aa7f24851546309f5340ea864f0ea..39bb2d9728742fc14198e1b8bc564592bee4bc00 100644 (file)
@@ -1422,8 +1422,7 @@ def _mdiff(fromlines, tolines, context=None, linejunk=None,
                 num_blanks_pending -= 1
                 yield _make_line(lines,'-',0), None, True
                 continue
-            elif s.startswith('--?+') or s.startswith('--+') or \
-                 s.startswith('- '):
+            elif s.startswith(('--?+', '--+', '- ')):
                 # in delete block and see a intraline change or unchanged line
                 # coming: yield the delete line and then blanks
                 from_line,to_line = _make_line(lines,'-',0), None
@@ -1447,7 +1446,7 @@ def _mdiff(fromlines, tolines, context=None, linejunk=None,
                 num_blanks_pending += 1
                 yield None, _make_line(lines,'+',1), True
                 continue
-            elif s.startswith('+ ') or s.startswith('+-'):
+            elif s.startswith(('+ ', '+-')):
                 # will be leaving an add block: yield blanks then add line
                 from_line, to_line = None, _make_line(lines,'+',1)
                 num_blanks_to_yield,num_blanks_pending = num_blanks_pending+1,0
index 59440f09b21e43aae53950e8ec5521dea7e03975..76042933bb6d8d69510791c76e854947b41f32ea 100644 (file)
@@ -649,7 +649,7 @@ class EditorWindow(object):
     def __extra_help_callback(self, helpfile):
         "Create a callback with the helpfile value frozen at definition time"
         def display_extra_help(helpfile=helpfile):
-            if not (helpfile.startswith('www') or helpfile.startswith('http')):
+            if not helpfile.startswith(('www', 'http')):
                 url = os.path.normpath(helpfile)
             if sys.platform[:3] == 'win':
                 os.startfile(helpfile)
index 191a87c67ad6f752011f711b720bc497fe4d8378..dcd9321ad7aade24d557c2c5a7ba8e5ddb779b7d 100644 (file)
@@ -406,7 +406,7 @@ class IdleConf:
         names=extnNameList
         kbNameIndicies=[]
         for name in names:
-            if name.endswith('_bindings') or name.endswith('_cfgBindings'):
+            if name.endswith(('_bindings', '_cfgBindings')):
                 kbNameIndicies.append(names.index(name))
         kbNameIndicies.sort()
         kbNameIndicies.reverse()
index 8924f792bb57550746cfaf66b98dc79192fc79b6..661162196c7fa40bee4dc53edb9458e2fbb5a010 100644 (file)
@@ -127,7 +127,7 @@ class GetHelpSourceDialog(Toplevel):
                                    parent=self)
             self.entryPath.focus_set()
             pathOk = False
-        elif path.startswith('www.') or path.startswith('http'):
+        elif path.startswith(('www.', 'http')):
             pass
         else:
             if path[:5] == 'file:':
@@ -146,8 +146,7 @@ class GetHelpSourceDialog(Toplevel):
                            self.path.get().strip())
             if sys.platform == 'darwin':
                 path = self.result[1]
-                if (path.startswith('www') or path.startswith('file:')
-                    or path.startswith('http:')):
+                if path.startswith(('www', 'file:', 'http:')):
                     pass
                 else:
                     # Mac Safari insists on using the URI form for local files
index 48f1643be89122bf7c21390af6b7ed72f45373fa..6fb20c8bf295f26bc6f218a763520b3aae286f4b 100644 (file)
@@ -62,7 +62,7 @@ class CompilerTest(unittest.TestCase):
     def testLineNo(self):
         # Test that all nodes except Module have a correct lineno attribute.
         filename = __file__
-        if filename.endswith(".pyc") or filename.endswith(".pyo"):
+        if filename.endswith((".pyc", ".pyo")):
             filename = filename[:-1]
         tree = compiler.parseFile(filename)
         self.check_lineno(tree)
index 79be3694ab14d3ebc7b0fed192d2578f0f6e8c18..62c40eba4d78b4056d79b017778119e8cbbd2a82 100644 (file)
@@ -15,7 +15,7 @@ from test import inspect_fodder2 as mod2
 # isdatadescriptor
 
 modfile = mod.__file__
-if modfile.endswith('c') or modfile.endswith('o'):
+if modfile.endswith(('c', 'o')):
     modfile = modfile[:-1]
 
 import __builtin__
index e3fbf98eb7510d7b1f93c90c7617d7801762ad49..fa170ef58dd660de756afc47c38ea43a823a1782 100644 (file)
@@ -130,10 +130,8 @@ class TclTest(unittest.TestCase):
         import os
         old_display = None
         import sys
-        if (sys.platform.startswith('win') or
-                sys.platform.startswith('darwin') or
-                sys.platform.startswith('cygwin')):
-            return # no failure possible on windows?
+        if sys.platform.startswith(('win', 'darwin', 'cygwin')):
+            return  # no failure possible on windows?
         if 'DISPLAY' in os.environ:
             old_display = os.environ['DISPLAY']
             del os.environ['DISPLAY']
index ca6294e031f8822b5baf7351e7637ab71e2f71b2..db36e1d21dd94b8db47f6f270a5365545b8c82bf 100644 (file)
@@ -285,7 +285,7 @@ class CoverageResults:
             if filename == "<string>":
                 continue
 
-            if filename.endswith(".pyc") or filename.endswith(".pyo"):
+            if filename.endswith((".pyc", ".pyo")):
                 filename = filename[:-1]
 
             if coverdir is None:
index b5d75e45010a2f56ca1e08dbed1b5513e7182455..4b4119dd94e7593ad8ecc85a3e9e756442e0f7d9 100644 (file)
@@ -46,7 +46,7 @@ def warn(message, category=None, stacklevel=1):
     filename = globals.get('__file__')
     if filename:
         fnl = filename.lower()
-        if fnl.endswith(".pyc") or fnl.endswith(".pyo"):
+        if fnl.endswith((".pyc", ".pyo")):
             filename = filename[:-1]
     else:
         if module == "__main__":
index 4693fe7568eeeebcc734fdcd6791c4d5cbe60365..bae0caf4a096fbcf3c7627e5c970e14ebddb1709 100644 (file)
@@ -98,8 +98,7 @@ def _synthesize(browser, update_tryorder=1):
 if sys.platform[:3] == "win":
     def _isexecutable(cmd):
         cmd = cmd.lower()
-        if os.path.isfile(cmd) and (cmd.endswith(".exe") or
-                                    cmd.endswith(".bat")):
+        if os.path.isfile(cmd) and cmd.endswith((".exe", ".bat")):
             return True
         for ext in ".exe", ".bat":
             if os.path.isfile(cmd + ext):