mitsuhiko/werkzeug — pull request #380 by miracle2k (2013-06-03 03:45:02+00:00)
Title: Make SharedDataMiddleware support overlapping paths

I have a setup where I might have static dir mappings like this:

/static/cms/ => DirA
/static/cms/plugin => DirB

In other words, they overlap. To handle such a scenario properly, one would need to search the path by prefix length, trying the longest one first.

This seems like something the would be reasonable to support in the StaticMiddleware. I see two possible approaches:

(1) Make StaticMiddleware sort by prefix length while searching.

(2) Use a OrderedDict to maintain whatever order the user specified.

I went with (2) because it's the "don't involve yourself / don't introduce behaviour" option. The downside is that it requires a OrderedDict implementation, which werkzeug does not include as far as I can tell; so I made this optional: If OrderedDict is not available, it works as it always has.

I also allow the list of exports to be passed as a list of 2-tuples, so that the caller does not have to construct an additional OrderedDict.