| 1 | import os.path |
| 2 | import string |
| 3 | from .compat import unicode |
| 4 | |
| 5 | letters = None |
| 6 | try: |
| 7 | letters = string.ascii_letters |
| 8 | except AttributeError: |
| 9 | letters = string.letters |
| 10 | |
| 11 | _l = ['_'] * 256 |
| 12 | for c in string.digits + letters: |
| 13 | _l[ord(c)] = c |
| 14 | _pathNameTransChars = ''.join(_l) |
| 15 | del _l, c |
| 16 | |
| 17 | |
| 18 | def convertTmplPathToModuleName(tmplPath, |
| 19 | _pathNameTransChars=_pathNameTransChars, |
| 20 | splitdrive=os.path.splitdrive, |
| 21 | ): |
| 22 | try: |
| 23 | moduleName = splitdrive(tmplPath)[1].translate(_pathNameTransChars) |
| 24 | except (UnicodeError, TypeError): |
| 25 | moduleName = unicode(splitdrive(tmplPath)[1])\ |
| 26 | .translate(unicode(_pathNameTransChars)) |
| 27 | return moduleName |