o aS@sddlmZddlmZddlmZddlmZddlm Z ddl m Z ddl m Z ddlmZd d lmZGd d d eZGd ddZdddZddZddZddZdS)) import_module) walk_packages)apps)settings)TemplateDoesNotExist) make_context)Engine)InvalidTemplateLibrary) BaseEnginecs8eZdZdZfddZddZddZdd ZZS) DjangoTemplates templatescs~|}|d}|dd|dtj|dd|di}|||d<t|t |j |j fi||_ dS)NOPTIONS autoescapeTdebug file_charsetzutf-8 libraries) copypop setdefaultrDEBUGgetget_templatetag_librariessuper__init__rdirsapp_dirsengine)selfparamsoptionsr __class__A/usr/lib/python3/dist-packages/django/template/backends/django.pyrs    zDjangoTemplates.__init__cCst|j||SN)Templater from_string)r template_coder#r#r$r'szDjangoTemplates.from_stringc CsFz t|j||WSty"}z t||WYd}~dSd}~wwr%)r&r get_templaterreraise)r template_nameexcr#r#r$r) s zDjangoTemplates.get_templatecCst}|||S)z Return a collation of template tag libraries from installed applications and the supplied custom_libraries argument. )get_installed_librariesupdate)rcustom_librariesrr#r#r$r&s z)DjangoTemplates.get_templatetag_libraries) __name__ __module__ __qualname__ app_dirnamerr'r)r __classcell__r#r#r!r$r s   r c@s*eZdZddZeddZdddZdS) r&cCs||_||_dSr%)templatebackend)rr5r6r#r#r$r2s zTemplate.__init__cCs|jjSr%)r5origin)rr#r#r$r76szTemplate.originNc CsVt|||jjjd}z|j|WSty*}z t||jWYd}~dSd}~ww)N)r)rr6rrr5renderrr*)rcontextrequestr,r#r#r$r8:szTemplate.render)NN)r0r1r2rpropertyr7r8r#r#r#r$r&0s  r&NcCs:|p|j}|j|j|j||jd}t|dr|j|_|S)z Create a new TemplateDoesNotExist. Preserve its declared attributes and template debug data but discard __traceback__, __context__, and __cause__ to make this object suitable for keeping around (in a cache, for example). )triedr6chaintemplate_debug)r6r"argsr<r=hasattrr>r,r6newr#r#r$copy_exceptionBs  rCcCst||}||)zT Reraise TemplateDoesNotExist while maintaining template debug information. )rCrAr#r#r$r*Os r*c Csi}dg}|ddtD|D]*}zt|}Wn ty$Yqwt|dr=t|D]}|||t|dd<q.q|S)a Return the built-in template tag libraries and those from installed applications. Libraries are stored in a dictionary where keys are the individual module names, not the full module paths. Example: django.templatetags.i18n is stored as i18n. zdjango.templatetagscss|]}d|jVqdS)z%s.templatetagsN)name).0 app_configr#r#r$ `s  z*get_installed_libraries..__path__r N)extendrget_app_configsr ImportErrorr@get_package_librarieslen)r candidates candidatepkgrDr#r#r$r-Ws      r-c csrt|j|jdD],}zt|d}Wnty+}z td|d|f|d}~wwt|dr6|dVq dS)zZ Recursively yield template tag libraries defined in submodules of a package. .r zSInvalid template library specified. ImportError raised when trying to load '%s': %sNregister)rrHr0rrKr r@)rPentrymoduleer#r#r$rLrs$   rLr%) importlibrpkgutilr django.appsr django.confrdjango.templaterdjango.template.contextrdjango.template.enginerdjango.template.libraryr baser r r&rCr*r-rLr#r#r#r$s        "