Split the extension from a pathname. Extension is everything from the last dot to the end, ignoring leading dots. Returns "(root, ext)"; ext may be empty.
(p, sep, altsep, extsep)
| 155 | # Generic implementation of splitext, to be parametrized with |
| 156 | # the separators |
| 157 | def _splitext(p, sep, altsep, extsep): |
| 158 | """Split the extension from a pathname. |
| 159 | |
| 160 | Extension is everything from the last dot to the end, ignoring |
| 161 | leading dots. Returns "(root, ext)"; ext may be empty.""" |
| 162 | # NOTE: This code must work for text and bytes strings. |
| 163 | |
| 164 | sepIndex = p.rfind(sep) |
| 165 | if altsep: |
| 166 | altsepIndex = p.rfind(altsep) |
| 167 | sepIndex = max(sepIndex, altsepIndex) |
| 168 | |
| 169 | dotIndex = p.rfind(extsep) |
| 170 | if dotIndex > sepIndex: |
| 171 | # skip all leading dots |
| 172 | filenameIndex = sepIndex + 1 |
| 173 | while filenameIndex < dotIndex: |
| 174 | if p[filenameIndex:filenameIndex+1] != extsep: |
| 175 | return p[:dotIndex], p[dotIndex:] |
| 176 | filenameIndex += 1 |
| 177 | |
| 178 | return p, p[:0] |
| 179 | |
| 180 | def _check_arg_types(funcname, *args): |
| 181 | hasstr = hasbytes = False |