X-Git-Url: http://git.tremily.us/?a=blobdiff_plain;f=jinja%2Fenvironment.py;h=e1a057cd2fa4762c267b529c14a603ff0f069512;hb=215809146c04657188b3617359e330b4fbd2bb12;hp=b390c01183ff9d48444169cfc8dc76e5292e5bcd;hpb=1f1823c6fe06e2d06b2d17a795458b13389eb817;p=jinja2.git diff --git a/jinja/environment.py b/jinja/environment.py index b390c01..e1a057c 100644 --- a/jinja/environment.py +++ b/jinja/environment.py @@ -24,7 +24,7 @@ __all__ = ['Environment'] class Environment(object): """ - The jinja environment. + The Jinja environment. The core component of Jinja is the `Environment`. It contains important shared variables like configuration, filters, tests, @@ -136,8 +136,10 @@ class Environment(object): self.friendly_traceback = friendly_traceback # global namespace - self.globals = namespace is None and DEFAULT_NAMESPACE.copy() \ - or namespace + if namespace is None: + self.globals = DEFAULT_NAMESPACE.copy() + else: + self.globals = namespace # jinja 1.0 compatibility if auto_escape: @@ -227,6 +229,13 @@ class Environment(object): """ return collect_translations(self.loader.parse(name)) + def get_translations_for_string(self, string): + """ + Like `get_translations`, but the translations are loaded from a + normal string that represents the template. + """ + return collect_translations(self.parse(string)) + def apply_filters(self, value, context, filters): """ Apply a list of filters on the variable. @@ -320,6 +329,8 @@ class Environment(object): """ if value is Undefined or value is None: return u'' + elif getattr(value, 'jinja_no_finalization', False): + return value val = self.to_unicode(value) if self.default_filters: val = self.apply_filters(val, ctx, self.default_filters)