File: convertTmplPathToModuleName.py

package info (click to toggle)
cheetah 3.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,052 kB
  • sloc: python: 10,653; ansic: 584; xml: 323; sh: 181; makefile: 87
file content (27 lines) | stat: -rw-r--r-- 748 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import os.path
import string
from .compat import unicode

letters = None
try:
    letters = string.ascii_letters
except AttributeError:
    letters = string.letters

_l = ['_'] * 256
for c in string.digits + letters:
    _l[ord(c)] = c
_pathNameTransChars = ''.join(_l)
del _l, c


def convertTmplPathToModuleName(tmplPath,
                                _pathNameTransChars=_pathNameTransChars,
                                splitdrive=os.path.splitdrive,
                                ):
    try:
        moduleName = splitdrive(tmplPath)[1].translate(_pathNameTransChars)
    except (UnicodeError, TypeError):
        moduleName = unicode(splitdrive(tmplPath)[1])\
            .translate(unicode(_pathNameTransChars))
    return moduleName