Templetor's _find_file method should be available to contributed template support code

Bug #542568 reported by foxbunny
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
web.py
New
Undecided
Unassigned

Bug Description

Most template engines by themselves do not support looking up templates without specifying an extension. Some of the patches that solve this for contributed template engine support code uses code similar to web.template.Render._find_file in order to provide Templetor-like behavior. It would be great if we didn't have this duplication by extracting _find_file and putting it somewhere like web.util where contrib template support code could use it.

For reference, _find_file currently looks like this:

def _findfile(self, path_prefix):
        p = [f for f in glob.glob(path_prefix + '.*') if not f.endswith('~')] # skip backup files
        p.sort() # sort the matches for deterministic order
        return p and p[0]

Revision history for this message
foxbunny (bg-branko) wrote :

If this is fixed, it would simplify fixes for these two tickets:

https://bugs.launchpad.net/webpy/+bug/252232
https://bugs.launchpad.net/webpy/+bug/525127

Revision history for this message
foxbunny (bg-branko) wrote :

Here's a patch that moves _findfile to web.utils, thus making it possible to reuse the code.

Revision history for this message
Anand Chitipothu (anandology) wrote :

Patch looks good.

findfile is too generic name. Can you think of anything better?

Revision history for this message
foxbunny (bg-branko) wrote :

How about prefix_lookup?

Revision history for this message
foxbunny (bg-branko) wrote :

prefixglob, globprefix, findbyprefix

Revision history for this message
foxbunny (bg-branko) wrote :

Settled for findbyprefix... Unique enough, but not too unique to scream for attention and raise questions. I think meaning can be derived from context.

Revision history for this message
foxbunny (bg-branko) wrote :

The last patch was not good. I forgot to fix the import in the template.py and add findbyprefix to __all__. Fixed now. Should work.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.