Nginx cache path function
Why you can't just hardcode cache path calculation?

&gt;&gt;&gt; _hash = '743a0e0c5c657d3295d347a1f0a66109'
&gt;&gt;&gt; def hash2path(_hash):
...     return "%s/%s/%s/%s" % (_hash[0], _hash[1:3], _hash[3:6], _hash)
... 
&gt;&gt;&gt; hash2path(_hash)
'7/43/a0e/743a0e0c5c657d3295d347a1f0a66109'


UPDATE: If you really need to pass level array there is a little bit faster version:

def hash2path(_hash, levels):
    prev = 0
    parts = []
    for level in levels:
        parts.append(_hash[prev:prev + level])
        prev += level
    parts.append(_hash)
    return "/".join(parts)