Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
b19693e6
Kaydet (Commit)
b19693e6
authored
Kas 10, 2014
tarafından
Aymeric Augustin
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Imported BaseEngine from the DEP.
i18n is left aside for now.
üst
7eefdbf7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
80 additions
and
0 deletions
+80
-0
__init__.py
django/template/backends/__init__.py
+0
-0
base.py
django/template/backends/base.py
+80
-0
No files found.
django/template/backends/__init__.py
0 → 100644
Dosyayı görüntüle @
b19693e6
django/template/backends/base.py
0 → 100644
Dosyayı görüntüle @
b19693e6
from
django.core.exceptions
import
(
ImproperlyConfigured
,
SuspiciousFileOperation
)
from
django.template.utils
import
get_app_template_dirs
from
django.utils._os
import
safe_join
from
django.utils.functional
import
cached_property
class
BaseEngine
(
object
):
# Core methods: engines have to provide their own implementation
# (except for from_string which is optional).
def
__init__
(
self
,
params
):
"""
Initializes the template engine.
Receives the configuration settings as a dict.
"""
params
=
params
.
copy
()
self
.
name
=
params
.
pop
(
'NAME'
)
self
.
dirs
=
list
(
params
.
pop
(
'DIRS'
))
self
.
app_dirs
=
bool
(
params
.
pop
(
'APP_DIRS'
))
if
params
:
raise
ImproperlyConfigured
(
"Unknown parameters: {}"
.
format
(
", "
.
join
(
params
)))
@property
def
app_dirname
(
self
):
raise
ImproperlyConfigured
(
"{} doesn't support loading templates from installed "
"applications."
.
format
(
self
.
__class__
.
__name__
))
def
from_string
(
self
,
template_code
):
"""
Creates and returns a template for the given source code.
This method is optional.
"""
raise
NotImplementedError
(
"subclasses of BaseEngine should provide "
"a from_string() method"
)
def
get_template
(
self
,
template_name
):
"""
Loads and returns a template for the given name.
Raises TemplateDoesNotExist if no such template exists.
"""
raise
NotImplementedError
(
"subclasses of BaseEngine must provide "
"a get_template() method"
)
# Utility methods: they are provided to minimize code duplication and
# security issues in third-party backends.
@cached_property
def
template_dirs
(
self
):
"""
Returns a list of directories to search for templates.
"""
# Immutable return value because it's cached and shared by callers.
template_dirs
=
tuple
(
self
.
dirs
)
if
self
.
app_dirs
:
template_dirs
+=
get_app_template_dirs
(
self
.
app_dirname
)
return
template_dirs
def
iter_template_filenames
(
self
,
template_name
):
"""
Iterates over candidate files for template_name.
Ignores files that don't lie inside configured template dirs to avoid
directory traversal attacks.
"""
for
template_dir
in
self
.
template_dirs
:
try
:
yield
safe_join
(
template_dir
,
template_name
)
except
SuspiciousFileOperation
:
# The joined path was located outside of this template_dir
# (it might be inside another one, so this isn't fatal).
pass
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment