Issues

Issue #128 resolved

module_directory not handled properly when given an absolute template path on Windows

guest
created an issue

When an absolute path is given on windows (i.e. c:\ or d:\) for the filename parameter to Template.init, then the module_directory parameter is ignored because of how os.path.join works.

A patch is attached to emulate the way absolute paths work on posix systems.

Comments (2)

  1. Mike Bayer repo owner
    • changed milestone to 0.3

    I'd prefer this:

    1. !diff Index: mako/template.py

    --- mako/template.py (revision 473) +++ mako/template.py (working copy) @@ -57,7 +57,9 @@ self.uri = uri elif filename: self.module_id = re.sub(r'\W', "_", filename) - self.uri = filename + drive, path = os.path.splitdrive(filename) + path = os.path.normpath(path).replace(os.path.sep, "/") + self.uri = path else: self.module_id = "memory:" + hex(id(self)) self.uri = self.module_id @@ -95,8 +97,8 @@ u = u[1:] path = os.path.abspath( os.path.join( - module_directory.replace('/', os.path.sep), - u + ".py" + os.path.normpath(module_directory), + os.path.normpath(u) + ".py" ) ) else:

    can you test ? This should have a platform independent unit test in order to be committed (i.e. set os.path to os.ntpath, check desired output, set os.path to os.posixpath, etc.).

  2. Log in to comment