Ticket #17516: #17516-memoized_safe_join.diff

File #17516-memoized_safe_join.diff, 776 bytes (added by German M. Bravo, 5 years ago)
  • django/utils/_os.py

    import os 
    22import stat
    33from os.path import join, normcase, normpath, abspath, isabs, sep
    44from django.utils.encoding import force_unicode
     5from django.utils.functional import memoize
     7_safe_join_cache = {} # Saves already safe-joined paths.
    69# Define our own abspath function that can handle joining
    710# unicode paths to a current working directory that has non-ASCII
    def safe_join(base, *paths): 
    4548        raise ValueError('The joined path (%s) is located outside of the base '
    4649                         'path component (%s)' % (final_path, base_path))
    4750    return final_path
     51safe_join = memoize(safe_join, _safe_join_cache, 10)
    4953def rmtree_errorhandler(func, path, exc_info):
    5054    """
Back to Top