changeset 1419:f7f415cc1332

replace most find() calls by in/index()
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 26 Aug 2006 14:58:24 +0200
parents 76cd1916b7e4
children aa8490f722fa
files MoinMoin/Page.py MoinMoin/action/AttachFile.py MoinMoin/action/test.py MoinMoin/auth/_PHPsessionParser.py MoinMoin/i18n/tools/mail_i18n-maintainers.py MoinMoin/logfile/editlog.py MoinMoin/parser/text_moin_wiki.py MoinMoin/parser/text_python.py MoinMoin/stats/useragents.py MoinMoin/theme/__init__.py
diffstat 10 files changed, 23 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/Page.py	Thu Aug 24 22:55:30 2006 +0200
+++ b/MoinMoin/Page.py	Sat Aug 26 14:58:24 2006 +0200
@@ -1121,7 +1121,7 @@
                             target = args[1]
                         else:
                             target = self.page_name
-                        if target.find('://') >= 0:
+                        if '://' in target:
                             if targetallowed == 'internal':
                                 raise ValueError
                             elif targetallowed == 'external':
--- a/MoinMoin/action/AttachFile.py	Thu Aug 24 22:55:30 2006 +0200
+++ b/MoinMoin/action/AttachFile.py	Sat Aug 26 14:58:24 2006 +0200
@@ -689,7 +689,7 @@
 
 def unzip_file(pagename, request):
     _ = request.getText
-    valid_pathname = lambda name: (name.find('/') == -1) and (name.find('\\') == -1)
+    valid_pathname = lambda name: ('/' not in name) and ('\\' not in name)
 
     filename, fpath = _access_file(pagename, request)
     if not filename:
--- a/MoinMoin/action/test.py	Thu Aug 24 22:55:30 2006 +0200
+++ b/MoinMoin/action/test.py	Sat Aug 26 14:58:24 2006 +0200
@@ -29,7 +29,7 @@
     # Try xml
     try:
         import xml
-        request.write('PyXML is %sinstalled\n' % ('NOT ', '')[xml.__file__.find('_xmlplus') != -1])
+        request.write('PyXML is %sinstalled\n' % ('NOT ', '')['_xmlplus' in xml.__file__])
     except ImportError:
         request.write('PyXML is missing\n')
 
--- a/MoinMoin/auth/_PHPsessionParser.py	Thu Aug 24 22:55:30 2006 +0200
+++ b/MoinMoin/auth/_PHPsessionParser.py	Sat Aug 26 14:58:24 2006 +0200
@@ -35,13 +35,14 @@
 
 def parseValue(string, start=0):
     """ Parses the inner structure. """
+    # TODO: replace "string" by something else
     #print "Parsing %r" % (string[start:], )
 
     val_type = string[start]
-    header_end = string.find(':', 3+start)
-    if header_end != -1:
+    try:
+        header_end = string.index(':', 3+start)
         first_data = string[start+2:header_end]
-    else:
+    except ValueError:
         first_data = None
 
     #print "Saw type %r, first_data is %r." % (val_type, first_data)
@@ -99,7 +100,7 @@
     current_pos = 0
     session_dict = {}
     while current_pos < len(boxed):
-        name_end = boxed.find("|", current_pos)
+        name_end = boxed.find("|", current_pos) # TODO: replace by .index()?
         name = boxed[current_pos:name_end]
         current_pos = name_end+1
         data, current_pos = parseValue(boxed, current_pos)
--- a/MoinMoin/i18n/tools/mail_i18n-maintainers.py	Thu Aug 24 22:55:30 2006 +0200
+++ b/MoinMoin/i18n/tools/mail_i18n-maintainers.py	Sat Aug 26 14:58:24 2006 +0200
@@ -73,7 +73,7 @@
 def notify_maintainer(lang, mail_text):
     mailaddr = languages[lang][4]
     rc = None
-    if mailaddr and mailaddr.find('***vacant***') < 0:
+    if mailaddr and '***vacant***' not in mailaddr:
         text = mail_text % locals()
         rc = sendmail(mail_from, [mailaddr], mail_subject, text)
     return rc
--- a/MoinMoin/logfile/editlog.py	Thu Aug 24 22:55:30 2006 +0200
+++ b/MoinMoin/logfile/editlog.py	Sat Aug 26 14:58:24 2006 +0200
@@ -112,8 +112,9 @@
                     request.formatter.text(name) +
                     request.formatter.url(0))
         elif kind == 'ip':
-            idx = info.find('.')
-            if idx == -1:
+            try:
+                idx = info.index('.')
+            except ValueError:
                 idx = len(info)
             title = wikiutil.escape('???' + title)
             text = wikiutil.escape(info[:idx])
--- a/MoinMoin/parser/text_moin_wiki.py	Thu Aug 24 22:55:30 2006 +0200
+++ b/MoinMoin/parser/text_moin_wiki.py	Sat Aug 26 14:58:24 2006 +0200
@@ -999,8 +999,9 @@
                         self.in_pre = 'no_parser'
                 if self.in_pre == 'found_parser':
                     # processing mode
-                    endpos = line.find("}}}")
-                    if endpos == -1:
+                    try:
+                        endpos = line.index("}}}")
+                    except ValueError:
                         self.parser_lines.append(line)
                         continue
                     if line[:endpos]:
--- a/MoinMoin/parser/text_python.py	Thu Aug 24 22:55:30 2006 +0200
+++ b/MoinMoin/parser/text_python.py	Sat Aug 26 14:58:24 2006 +0200
@@ -51,8 +51,10 @@
         self.lines = [0, 0]
         pos = 0
         while 1:
-            pos = self.raw.find('\n', pos) + 1
-            if not pos: break
+            try:
+                pos = self.raw.index('\n', pos) + 1
+            except ValueError:
+                break
             self.lines.append(pos)
         self.lines.append(len(self.raw))
 
--- a/MoinMoin/stats/useragents.py	Thu Aug 24 22:55:30 2006 +0200
+++ b/MoinMoin/stats/useragents.py	Sat Aug 26 14:58:24 2006 +0200
@@ -67,10 +67,10 @@
                 break
             ua = event[2].get('HTTP_USER_AGENT')
             if ua:
-                pos = ua.find(" (compatible; ")
-                if pos >= 0:
+                try:
+                    pos = ua.index(" (compatible; ")
                     ua = ua[pos:].split(';')[1].strip()
-                else:
+                except ValueError:
                     ua = ua.split()[0]
                 #ua = ua.replace(';', '\n')
                 data[ua] = data.get(ua, 0) + 1
--- a/MoinMoin/theme/__init__.py	Thu Aug 24 22:55:30 2006 +0200
+++ b/MoinMoin/theme/__init__.py	Sat Aug 26 14:58:24 2006 +0200
@@ -836,7 +836,7 @@
         # Stolen from wikitest.py
         try:
             import xml
-            return xml.__file__.find('_xmlplus') != -1
+            return '_xmlplus' in xml.__file__
         except ImportError:
             # This error reported on Python 2.2
             return False