| Name | Size | Mode | Actions |
|---|---|---|---|
| __pycache__/ | - | 0755 | rm |
| asyncfilters.py | 4250 | 0644 | editdlrm |
| asyncsupport.py | 7209 | 0644 | editdlrm |
| bccache.py | 12139 | 0644 | editdlrm |
| compiler.py | 66284 | 0644 | editdlrm |
| constants.py | 1458 | 0644 | editdlrm |
| debug.py | 8529 | 0644 | editdlrm |
| defaults.py | 1126 | 0644 | editdlrm |
| environment.py | 50629 | 0644 | editdlrm |
| exceptions.py | 5425 | 0644 | editdlrm |
| ext.py | 26441 | 0644 | editdlrm |
| filters.py | 41415 | 0644 | editdlrm |
| idtracking.py | 9211 | 0644 | editdlrm |
| lexer.py | 30331 | 0644 | editdlrm |
| loaders.py | 17666 | 0644 | editdlrm |
| meta.py | 4131 | 0644 | editdlrm |
| nativetypes.py | 2753 | 0644 | editdlrm |
| nodes.py | 31095 | 0644 | editdlrm |
| optimizer.py | 1457 | 0644 | editdlrm |
| parser.py | 35660 | 0644 | editdlrm |
| runtime.py | 30618 | 0644 | editdlrm |
| sandbox.py | 17127 | 0644 | editdlrm |
| tests.py | 4799 | 0644 | editdlrm |
| utils.py | 22522 | 0644 | editdlrm |
| visitor.py | 3240 | 0644 | editdlrm |
| _compat.py | 3191 | 0644 | editdlrm |
| _identifier.py | 1775 | 0644 | editdlrm |
| __init__.py | 1549 | 0644 | editdlrm |
/opt/imunify360/venv/lib/python3.11/site-packages/jinja2/utils.py (22522B)
%s
" % escape(x) for x in result)) def unicode_urlencode(obj, charset="utf-8", for_qs=False): """Quote a string for use in a URL using the given charset. This function is misnamed, it is a wrapper around :func:`urllib.parse.quote`. :param obj: String or bytes to quote. Other types are converted to string then encoded to bytes using the given charset. :param charset: Encode text to bytes using this charset. :param for_qs: Quote "/" and use "+" for spaces. """ if not isinstance(obj, string_types): obj = text_type(obj) if isinstance(obj, text_type): obj = obj.encode(charset) safe = b"" if for_qs else b"/" rv = url_quote(obj, safe) if not isinstance(rv, text_type): rv = rv.decode("utf-8") if for_qs: rv = rv.replace("%20", "+") return rv class LRUCache(object): """A simple LRU Cache implementation.""" # this is fast for small capacities (something below 1000) but doesn't # scale. But as long as it's only used as storage for templates this # won't do any harm. def __init__(self, capacity): self.capacity = capacity self._mapping = {} self._queue = deque() self._postinit() def _postinit(self): # alias all queue methods for faster lookup self._popleft = self._queue.popleft self._pop = self._queue.pop self._remove = self._queue.remove self._wlock = Lock() self._append = self._queue.append def __getstate__(self): return { "capacity": self.capacity, "_mapping": self._mapping, "_queue": self._queue, } def __setstate__(self, d): self.__dict__.update(d) self._postinit() def __getnewargs__(self): return (self.capacity,) def copy(self): """Return a shallow copy of the instance.""" rv = self.__class__(self.capacity) rv._mapping.update(self._mapping) rv._queue.extend(self._queue) return rv def get(self, key, default=None): """Return an item from the cache dict or `default`""" try: return self[key] except KeyError: return default def setdefault(self, key, default=None): """Set `default` if the key is not in the cache otherwise leave unchanged. Return the value of this key. """ try: return self[key] except KeyError: self[key] = default return default def clear(self): """Clear the cache.""" self._wlock.acquire() try: self._mapping.clear() self._queue.clear() finally: self._wlock.release() def __contains__(self, key): """Check if a key exists in this cache.""" return key in self._mapping def __len__(self): """Return the current size of the cache.""" return len(self._mapping) def __repr__(self): return "<%s %r>" % (self.__class__.__name__, self._mapping) def __getitem__(self, key): """Get an item from the cache. Moves the item up so that it has the highest priority then. Raise a `KeyError` if it does not exist. """ self._wlock.acquire() try: rv = self._mapping[key] if self._queue[-1] != key: try: self._remove(key) except ValueError: # if something removed the key from the container # when we read, ignore the ValueError that we would # get otherwise. pass self._append(key) return rv finally: self._wlock.release() def __setitem__(self, key, value): """Sets the value for an item. Moves the item up so that it has the highest priority then. """ self._wlock.acquire() try: if key in self._mapping: self._remove(key) elif len(self._mapping) == self.capacity: del self._mapping[self._popleft()] self._append(key) self._mapping[key] = value finally: self._wlock.release() def __delitem__(self, key): """Remove an item from the cache dict. Raise a `KeyError` if it does not exist. """ self._wlock.acquire() try: del self._mapping[key] try: self._remove(key) except ValueError: pass finally: self._wlock.release() def items(self): """Return a list of items.""" result = [(key, self._mapping[key]) for key in list(self._queue)] result.reverse() return result def iteritems(self): """Iterate over all items.""" warnings.warn( "'iteritems()' will be removed in version 3.0. Use" " 'iter(cache.items())' instead.", DeprecationWarning, stacklevel=2, ) return iter(self.items()) def values(self): """Return a list of all values.""" return [x[1] for x in self.items()] def itervalue(self): """Iterate over all values.""" warnings.warn( "'itervalue()' will be removed in version 3.0. Use" " 'iter(cache.values())' instead.", DeprecationWarning, stacklevel=2, ) return iter(self.values()) def itervalues(self): """Iterate over all values.""" warnings.warn( "'itervalues()' will be removed in version 3.0. Use" " 'iter(cache.values())' instead.", DeprecationWarning, stacklevel=2, ) return iter(self.values()) def keys(self): """Return a list of all keys ordered by most recent usage.""" return list(self) def iterkeys(self): """Iterate over all keys in the cache dict, ordered by the most recent usage. """ warnings.warn( "'iterkeys()' will be removed in version 3.0. Use" " 'iter(cache.keys())' instead.", DeprecationWarning, stacklevel=2, ) return iter(self) def __iter__(self): return reversed(tuple(self._queue)) def __reversed__(self): """Iterate over the keys in the cache dict, oldest items coming first. """ return iter(tuple(self._queue)) __copy__ = copy abc.MutableMapping.register(LRUCache) def select_autoescape( enabled_extensions=("html", "htm", "xml"), disabled_extensions=(), default_for_string=True, default=False, ): """Intelligently sets the initial value of autoescaping based on the filename of the template. This is the recommended way to configure autoescaping if you do not want to write a custom function yourself. If you want to enable it for all templates created from strings or for all templates with `.html` and `.xml` extensions:: from jinja2 import Environment, select_autoescape env = Environment(autoescape=select_autoescape( enabled_extensions=('html', 'xml'), default_for_string=True, )) Example configuration to turn it on at all times except if the template ends with `.txt`:: from jinja2 import Environment, select_autoescape env = Environment(autoescape=select_autoescape( disabled_extensions=('txt',), default_for_string=True, default=True, )) The `enabled_extensions` is an iterable of all the extensions that autoescaping should be enabled for. Likewise `disabled_extensions` is a list of all templates it should be disabled for. If a template is loaded from a string then the default from `default_for_string` is used. If nothing matches then the initial value of autoescaping is set to the value of `default`. For security reasons this function operates case insensitive. .. versionadded:: 2.9 """ enabled_patterns = tuple("." + x.lstrip(".").lower() for x in enabled_extensions) disabled_patterns = tuple("." + x.lstrip(".").lower() for x in disabled_extensions) def autoescape(template_name): if template_name is None: return default_for_string template_name = template_name.lower() if template_name.endswith(enabled_patterns): return True if template_name.endswith(disabled_patterns): return False return default return autoescape def htmlsafe_json_dumps(obj, dumper=None, **kwargs): """Works exactly like :func:`dumps` but is safe for use in ``