[Python-checkins] python/nondist/sandbox/string alt292.py, 1.1, 1.2 curry292.py, 1.1, 1.2

rhettinger at users.sourceforge.net rhettinger at users.sourceforge.net
Tue Sep 7 06:26:47 CEST 2004


Update of /cvsroot/python/python/nondist/sandbox/string
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29241

Modified Files:
	alt292.py curry292.py 
Log Message:
Improve line numbering logic to handle \r, \n, and \r\n.



Index: alt292.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/string/alt292.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- alt292.py	28 Aug 2004 19:12:45 -0000	1.1
+++ alt292.py	7 Sep 2004 04:26:43 -0000	1.2
@@ -96,7 +96,7 @@
             return '%s' % mapping[named or braced]
         elif escaped:
             return '$'
-        lineno = template.count('\n', 0, mo.start(4)) + 1
+        lineno = len(template[:mo.start(4)].splitlines())
         raise ValueError('Invalid placeholder on line %d:  %r' %
                          (lineno, catchall))
     return _pattern.sub(convert, template)
@@ -124,7 +124,7 @@
                 return '${' + braced + '}'
         elif escaped:
             return '$'
-        lineno = template.count('\n', 0, mo.start(4)) + 1
+        lineno = len(template[:mo.start(4)].splitlines())
         raise ValueError('Invalid placeholder on line %d:  %r' %
                          (lineno, catchall))
     return _pattern.sub(convert, template)

Index: curry292.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/string/curry292.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- curry292.py	29 Aug 2004 21:28:41 -0000	1.1
+++ curry292.py	7 Sep 2004 04:26:44 -0000	1.2
@@ -113,7 +113,7 @@
                 return '%s' % mapping[named or braced]
             elif escaped:
                 return '$'
-            lineno = template.count('\n', 0, mo.start(4)) + 1
+            lineno = len(template[:mo.start(4)].splitlines())
             raise ValueError('Invalid placeholder on line %d:  %r' %
                              (lineno, catchall))
         return self.pattern.sub(convert, template)
@@ -151,7 +151,7 @@
                     return '${' + braced + '}'
             elif escaped:
                 return '$'
-            lineno = template.count('\n', 0, mo.start(4)) + 1
+            lineno = len(template[:mo.start(4)].splitlines())
             raise ValueError('Invalid placeholder on line %d:  %r' %
                              (lineno, catchall))
         return self.pattern.sub(convert, template)



More information about the Python-checkins mailing list