def __init__(self, *options, **kwargs):
     self.options = {}
     self.breakpoints = []
     current_breakpoint = None
     self.options[current_breakpoint] = []
     self.all_argument_names = []
     for value in options:
         if isinstance(value, basestring):
             self.breakpoints.append(value)
             current_breakpoint = value
             self.options[current_breakpoint] = []
         else:
             self.options[current_breakpoint].append(value)
             self.all_argument_names.append(value.name)
     self.blocks = []
     for block in kwargs.get('blocks', []):
         if isinstance(block, BlockDefinition):
             block_definition = block
         elif isinstance(block, basestring):
             block_definition = BlockDefinition(block, block)
         else:
             block_definition = BlockDefinition(block[1], block[0])
         block_definition.validate(self)
         self.blocks.append(block_definition)
     if 'parser_class' in kwargs:
         self.parser_class = kwargs['parser_class']
     else:
         self.parser_class = Parser
Exemple #2
0
 def __init__(self, *options, **kwargs):
     self.options = {}
     self.breakpoints = []
     self.combined_breakpoints = {}
     current_breakpoint = None
     last = None
     self.options[current_breakpoint] = []
     self.all_argument_names = []
     for value in options:
         if isinstance(value, compat_basestring):
             if isinstance(last, compat_basestring):
                 self.combined_breakpoints[last] = value
             self.breakpoints.append(value)
             current_breakpoint = value
             self.options[current_breakpoint] = []
         else:
             self.options[current_breakpoint].append(value)
             self.all_argument_names.append(value.name)
         last = value
     self.blocks = []
     for block in kwargs.get("blocks", []):
         if isinstance(block, BlockDefinition):
             block_definition = block
         elif isinstance(block, compat_basestring):
             block_definition = BlockDefinition(block, block)
         else:
             block_definition = BlockDefinition(block[1], block[0])
         block_definition.validate(self)
         self.blocks.append(block_definition)
     if "parser_class" in kwargs:
         self.parser_class = kwargs["parser_class"]
     else:
         self.parser_class = Parser
Exemple #3
0
 def __init__(self, *options, **kwargs):
     self.options = {}
     self.breakpoints = []
     self.combined_breakpoints = {}
     current_breakpoint = None
     last = None
     self.options[current_breakpoint] = []
     self.all_argument_names = []
     for value in options:
         if isinstance(value, basestring):
             if isinstance(last, basestring):
                 self.combined_breakpoints[last] = value
             self.breakpoints.append(value)
             current_breakpoint = value
             self.options[current_breakpoint] = []
         else:
             self.options[current_breakpoint].append(value)
             self.all_argument_names.append(value.name)
         last = value
     self.blocks = []
     for block in kwargs.get('blocks', []):
         if isinstance(block, BlockDefinition):
             block_definition = block
         elif isinstance(block, basestring):
             block_definition = BlockDefinition(block, block)
         else:
             block_definition = BlockDefinition(block[1], block[0])
         block_definition.validate(self)
         self.blocks.append(block_definition)
     if 'parser_class' in kwargs:
         self.parser_class = kwargs['parser_class']
     else:
         self.parser_class = Parser
Exemple #4
0
        class StartBlock(core.Tag):
            options = core.Options(arguments.Argument("myarg", resolve=False),
                                   blocks=[
                                       BlockDefinition(
                                           "nodelist",
                                           VariableBlockName(
                                               "end_block %(value)s", 'myarg'),
                                           "end_block")
                                   ])

            def render_tag(self, context, myarg, nodelist):
                return "nodelist:%s;myarg:%s" % (nodelist.render(context),
                                                 myarg)
Exemple #5
0
 def test_28_fail_named_block(self):
     vbn = VariableBlockName('endblock %(value)s', 'myarg')
     self.assertRaises(ImproperlyConfigured, core.Options,
                       blocks=[BlockDefinition('nodelist', vbn)])