Skip to content
Myr

variables starting with one or more underscores are not exported

Before adoption: this commit came in with the history the project adopted, so no landing records it.

--HG-- branch : trunk

authored by Armin Ronacher · committed by Armin Ronacher · parent d8b8c3e · Browse files · 3 files+13 added−10 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+13 added−10 removed

  • other:+13 added−10 removed

3 files+13 added−10 removed

modified:docs/templates.rst+3 added
704 unmodified lines
705 <dd>{{ input_field('password', type='password') }}</dd>706 </dl>707 <p>{{ textarea('comment') }}</p>708709Macros and variables starting with one ore more underscores are private and710cannot be imported.711712713.. _import-visibility:714715Import Context Behavior716-----------------------
311 unmodified lines
modified:jinja2/compiler.py+8 added-8 removed
622 unmodified lines
623 (name, arg_tuple))624 for arg in node.defaults:625 self.visit(arg, frame)626 self.write(', ')627 self.write('), %s, %s, %s)' % (628 frame.accesses_kwargs and '1' or '0',629 frame.accesses_varargs and '1' or '0',630 frame.accesses_caller and '1' or '0'627 self.write('), %r, %r, %r)' % (628 bool(frame.accesses_kwargs),629 bool(frame.accesses_varargs),630 bool(frame.accesses_caller)631 ))632633 # -- Statement Visitors634
179 unmodified lines
814 if node.with_context:815 self.write('make_module(context.parent, True)')816 else:817 self.write('module')818 if frame.toplevel and not node.target.startswith('__'):818 if frame.toplevel and not node.target.startswith('_'):819 self.writeline('context.exported_vars.discard(%r)' % node.target)820821 def visit_FromImport(self, node, frame):822 """Visit named imports."""
24 unmodified lines
847 'the requested name ' + repr(name), name))848 self.outdent()849 if frame.toplevel:850 var_names.append(alias)851 if not alias.startswith('__'):851 if not alias.startswith('_'):852 discarded_names.append(alias)853854 if var_names:855 if len(var_names) == 1:
139 unmodified lines
995 def visit_Macro(self, node, frame):996 macro_frame = self.macro_body(node, frame)997 self.newline()998 if frame.toplevel:999 if not node.name.startswith('__'):999 if not node.name.startswith('_'):1000 self.write('context.exported_vars.add(%r)' % node.name)1001 self.writeline('context.vars[%r] = ' % node.name)1002 self.write('l_%s = ' % node.name)1003 self.macro_def(node, macro_frame)
144 unmodified lines
11481149 # make sure toplevel assignments are added to the context.1150 if frame.toplevel:1151 public_names = [x for x in assignment_frame.assigned_names1152 if not x.startswith('__')]1152 if not x.startswith('_')]1153 if len(assignment_frame.assigned_names) == 1:1154 name = iter(assignment_frame.assigned_names).next()1155 self.writeline('context.vars[%r] = l_%s' % (name, name))1156 else:
209 unmodified lines
modified:jinja2/parser.py+2 added-2 removed
197 unmodified lines
198 if self.stream.current.type is 'name':199 if parse_context():200 break201 target = self.parse_assign_target(name_only=True)202 if target.name.startswith('__'):203 self.fail('names starting with two underscores can not '202 if target.name.startswith('_'):203 self.fail('names starting with an underline can not '204 'be imported', target.lineno,205 exc=TemplateAssertionError)206 if self.stream.skip_if('name:as'):207 alias = self.parse_assign_target(name_only=True)
546 unmodified lines