Code

Ticket #17516: #17516-memoized_safe_join.diff

File #17516-memoized_safe_join.diff, 776 bytes (added by Kronuz, 3 years ago)
Line 
1--- django/utils/_os.py
2+++ django/utils/_os.py
3@@ -2,6 +2,9 @@ import os
4 import stat
5 from os.path import join, normcase, normpath, abspath, isabs, sep
6 from django.utils.encoding import force_unicode
7+from django.utils.functional import memoize
8+
9+_safe_join_cache = {} # Saves already safe-joined paths.
10 
11 # Define our own abspath function that can handle joining
12 # unicode paths to a current working directory that has non-ASCII
13@@ -45,6 +48,7 @@ def safe_join(base, *paths):
14         raise ValueError('The joined path (%s) is located outside of the base '
15                          'path component (%s)' % (final_path, base_path))
16     return final_path
17+safe_join = memoize(safe_join, _safe_join_cache, 10)
18 
19 def rmtree_errorhandler(func, path, exc_info):
20     """