Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(72)

Side by Side Diff: Lib/genericpath.py

Issue 3055: combined patches from http://bugs.python.org/issue3187 (Closed) SVN Base: http://svn.python.org/view/*checkout*/python/branches/py3k/
Patch Set: One more tweak (fold some long lines) Created 1 year, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 """ 1 """
2 Path operations common to more than one OS 2 Path operations common to more than one OS
3 Do not use directly. The OS specific modules import the appropriate 3 Do not use directly. The OS specific modules import the appropriate
4 functions from this module themselves. 4 functions from this module themselves.
5 """ 5 """
6 import os 6 import os
7 import stat 7 import stat
8 8
9 __all__ = ['commonprefix', 'exists', 'getatime', 'getctime', 'getmtime', 9 __all__ = ['commonprefix', 'exists', 'getatime', 'getctime', 'getmtime',
10 'getsize', 'isdir', 'isfile'] 10 'getsize', 'isdir', 'isfile']
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 # pathname component; the root is everything before that. 80 # pathname component; the root is everything before that.
81 # It is always true that root + ext == p. 81 # It is always true that root + ext == p.
82 82
83 # Generic implementation of splitext, to be parametrized with 83 # Generic implementation of splitext, to be parametrized with
84 # the separators 84 # the separators
85 def _splitext(p, sep, altsep, extsep): 85 def _splitext(p, sep, altsep, extsep):
86 """Split the extension from a pathname. 86 """Split the extension from a pathname.
87 87
88 Extension is everything from the last dot to the end, ignoring 88 Extension is everything from the last dot to the end, ignoring
89 leading dots. Returns "(root, ext)"; ext may be empty.""" 89 leading dots. Returns "(root, ext)"; ext may be empty."""
90 # NOTE: This code must work for text and bytes strings.
90 91
91 sepIndex = p.rfind(sep) 92 sepIndex = p.rfind(sep)
92 if altsep: 93 if altsep:
93 altsepIndex = p.rfind(altsep) 94 altsepIndex = p.rfind(altsep)
94 sepIndex = max(sepIndex, altsepIndex) 95 sepIndex = max(sepIndex, altsepIndex)
95 96
96 dotIndex = p.rfind(extsep) 97 dotIndex = p.rfind(extsep)
97 if dotIndex > sepIndex: 98 if dotIndex > sepIndex:
98 # skip all leading dots 99 # skip all leading dots
99 filenameIndex = sepIndex + 1 100 filenameIndex = sepIndex + 1
100 while filenameIndex < dotIndex: 101 while filenameIndex < dotIndex:
101 if p[filenameIndex] != extsep: 102 if p[filenameIndex:filenameIndex+1] != extsep:
102 return p[:dotIndex], p[dotIndex:] 103 return p[:dotIndex], p[dotIndex:]
103 filenameIndex += 1 104 filenameIndex += 1
104 105
105 return p, '' 106 return p, p[:0]
OLDNEW

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld r497