[Python-checkins] r46805 - in python/trunk/Lib: _MozillaCookieJar.py difflib.py idlelib/EditorWindow.py idlelib/configHandler.py idlelib/configHelpSourceEdit.py test/test_compiler.py test/test_inspect.py test/test_tcl.py trace.py warnings.py webbrowser.py

georg.brandl python-checkins at python.org
Fri Jun 9 22:43:50 CEST 2006


Author: georg.brandl
Date: Fri Jun  9 22:43:48 2006
New Revision: 46805

Modified:
   python/trunk/Lib/_MozillaCookieJar.py
   python/trunk/Lib/difflib.py
   python/trunk/Lib/idlelib/EditorWindow.py
   python/trunk/Lib/idlelib/configHandler.py
   python/trunk/Lib/idlelib/configHelpSourceEdit.py
   python/trunk/Lib/test/test_compiler.py
   python/trunk/Lib/test/test_inspect.py
   python/trunk/Lib/test/test_tcl.py
   python/trunk/Lib/trace.py
   python/trunk/Lib/warnings.py
   python/trunk/Lib/webbrowser.py
Log:
Make use of new str.startswith/endswith semantics.
Occurences in email and compiler were ignored due to backwards compat requirements.


Modified: python/trunk/Lib/_MozillaCookieJar.py
==============================================================================
--- python/trunk/Lib/_MozillaCookieJar.py	(original)
+++ python/trunk/Lib/_MozillaCookieJar.py	Fri Jun  9 22:43:48 2006
@@ -63,8 +63,7 @@
                 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
 

Modified: python/trunk/Lib/difflib.py
==============================================================================
--- python/trunk/Lib/difflib.py	(original)
+++ python/trunk/Lib/difflib.py	Fri Jun  9 22:43:48 2006
@@ -1422,8 +1422,7 @@
                 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 @@
                 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

Modified: python/trunk/Lib/idlelib/EditorWindow.py
==============================================================================
--- python/trunk/Lib/idlelib/EditorWindow.py	(original)
+++ python/trunk/Lib/idlelib/EditorWindow.py	Fri Jun  9 22:43:48 2006
@@ -649,7 +649,7 @@
     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)

Modified: python/trunk/Lib/idlelib/configHandler.py
==============================================================================
--- python/trunk/Lib/idlelib/configHandler.py	(original)
+++ python/trunk/Lib/idlelib/configHandler.py	Fri Jun  9 22:43:48 2006
@@ -406,7 +406,7 @@
         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()

Modified: python/trunk/Lib/idlelib/configHelpSourceEdit.py
==============================================================================
--- python/trunk/Lib/idlelib/configHelpSourceEdit.py	(original)
+++ python/trunk/Lib/idlelib/configHelpSourceEdit.py	Fri Jun  9 22:43:48 2006
@@ -127,7 +127,7 @@
                                    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 @@
                            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

Modified: python/trunk/Lib/test/test_compiler.py
==============================================================================
--- python/trunk/Lib/test/test_compiler.py	(original)
+++ python/trunk/Lib/test/test_compiler.py	Fri Jun  9 22:43:48 2006
@@ -62,7 +62,7 @@
     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)

Modified: python/trunk/Lib/test/test_inspect.py
==============================================================================
--- python/trunk/Lib/test/test_inspect.py	(original)
+++ python/trunk/Lib/test/test_inspect.py	Fri Jun  9 22:43:48 2006
@@ -15,7 +15,7 @@
 # isdatadescriptor
 
 modfile = mod.__file__
-if modfile.endswith('c') or modfile.endswith('o'):
+if modfile.endswith(('c', 'o')):
     modfile = modfile[:-1]
 
 import __builtin__

Modified: python/trunk/Lib/test/test_tcl.py
==============================================================================
--- python/trunk/Lib/test/test_tcl.py	(original)
+++ python/trunk/Lib/test/test_tcl.py	Fri Jun  9 22:43:48 2006
@@ -130,10 +130,8 @@
         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']

Modified: python/trunk/Lib/trace.py
==============================================================================
--- python/trunk/Lib/trace.py	(original)
+++ python/trunk/Lib/trace.py	Fri Jun  9 22:43:48 2006
@@ -285,7 +285,7 @@
             if filename == "<string>":
                 continue
 
-            if filename.endswith(".pyc") or filename.endswith(".pyo"):
+            if filename.endswith((".pyc", ".pyo")):
                 filename = filename[:-1]
 
             if coverdir is None:

Modified: python/trunk/Lib/warnings.py
==============================================================================
--- python/trunk/Lib/warnings.py	(original)
+++ python/trunk/Lib/warnings.py	Fri Jun  9 22:43:48 2006
@@ -46,7 +46,7 @@
     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__":

Modified: python/trunk/Lib/webbrowser.py
==============================================================================
--- python/trunk/Lib/webbrowser.py	(original)
+++ python/trunk/Lib/webbrowser.py	Fri Jun  9 22:43:48 2006
@@ -98,8 +98,7 @@
 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):


More information about the Python-checkins mailing list