mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	Move compile_string into the Engine class.
This commit is contained in:
		| @@ -69,7 +69,7 @@ from django.template.base import (Context, FilterExpression, Lexer, Node,  # NOQ | ||||
|     filter_raw_string) | ||||
|  | ||||
| # Compiling templates | ||||
| from django.template.base import (compile_string, resolve_variable,  # NOQA | ||||
| from django.template.base import (resolve_variable,  # NOQA | ||||
|     unescape_string_literal, generic_tag_compiler) | ||||
|  | ||||
| # Library management | ||||
| @@ -77,4 +77,4 @@ from django.template.base import (Library, add_to_builtins, builtins,  # NOQA | ||||
|     get_library, get_templatetags_modules, get_text_list, import_library, | ||||
|     libraries) | ||||
|  | ||||
| __all__ = ('Template', 'Context', 'RequestContext', 'compile_string') | ||||
| __all__ = ('Template', 'Context', 'RequestContext') | ||||
|   | ||||
| @@ -135,7 +135,7 @@ class Template(object): | ||||
|         if engine is None: | ||||
|             from .engine import Engine | ||||
|             engine = Engine.get_default() | ||||
|         self.nodelist = compile_string(template_string, origin) | ||||
|         self.nodelist = engine.compile_string(template_string, origin) | ||||
|         self.name = name | ||||
|         self.origin = origin | ||||
|         self.engine = engine | ||||
| @@ -165,18 +165,6 @@ class Template(object): | ||||
|                 context.engine = None | ||||
|  | ||||
|  | ||||
| def compile_string(template_string, origin): | ||||
|     "Compiles template_string into NodeList ready for rendering" | ||||
|     if settings.TEMPLATE_DEBUG: | ||||
|         from django.template.debug import DebugLexer, DebugParser | ||||
|         lexer_class, parser_class = DebugLexer, DebugParser | ||||
|     else: | ||||
|         lexer_class, parser_class = Lexer, Parser | ||||
|     lexer = lexer_class(template_string, origin) | ||||
|     parser = parser_class(lexer.tokenize()) | ||||
|     return parser.parse() | ||||
|  | ||||
|  | ||||
| class Token(object): | ||||
|     def __init__(self, token_type, contents): | ||||
|         # token_type must be TOKEN_TEXT, TOKEN_VAR, TOKEN_BLOCK or | ||||
|   | ||||
| @@ -8,7 +8,7 @@ from django.utils.deprecation import RemovedInDjango20Warning | ||||
| from django.utils.functional import cached_property | ||||
| from django.utils.module_loading import import_string | ||||
|  | ||||
| from .base import Context, Template, TemplateDoesNotExist | ||||
| from .base import Context, Lexer, Parser, Template, TemplateDoesNotExist | ||||
|  | ||||
|  | ||||
| _dirs_undefined = object() | ||||
| @@ -200,3 +200,17 @@ class Engine(object): | ||||
|                 continue | ||||
|         # If we get here, none of the templates could be loaded | ||||
|         raise TemplateDoesNotExist(', '.join(not_found)) | ||||
|  | ||||
|     def compile_string(self, template_string, origin): | ||||
|         """ | ||||
|         Compiles template_string into a NodeList ready for rendering. | ||||
|         """ | ||||
|         if settings.TEMPLATE_DEBUG: | ||||
|             from .debug import DebugLexer, DebugParser | ||||
|             lexer_class, parser_class = DebugLexer, DebugParser | ||||
|         else: | ||||
|             lexer_class, parser_class = Lexer, Parser | ||||
|         lexer = lexer_class(template_string, origin) | ||||
|         tokens = lexer.tokenize() | ||||
|         parser = parser_class(tokens) | ||||
|         return parser.parse() | ||||
|   | ||||
| @@ -772,6 +772,8 @@ Miscellaneous | ||||
|   delete a key if ``set()`` fails. This is necessary to ensure the ``cache_db`` | ||||
|   session store always fetches the most current session data. | ||||
|  | ||||
| * Private API ``django.template.compile_string`` was removed. | ||||
|  | ||||
| * Private APIs ``override_template_loaders`` and ``override_with_test_loader`` | ||||
|   in ``django.test.utils`` were removed. Override ``TEMPLATE_LOADERS`` with | ||||
|   ``override_settings`` instead. | ||||
|   | ||||
		Reference in New Issue
	
	Block a user