Пример #1
0
 def __init__(self, context, args):
     args = parse_params(args, name='', expr='')
     name, expr = name_param(context, args, 'call', 1)
     if expr is None:
         expr = name
     else:
         expr = expr.eval
     self.simple_form = expr, None
Пример #2
0
 def __init__(self, context, blocks):
     tname, args, section = blocks[0]
     self.section = section.blocks
     args = parse_params(args, type='', expr='')
     self.__name__, self.expr = name_param(context,
                                           args,
                                           'raise',
                                           1,
                                           attr='type')
Пример #3
0
 def __init__(self, context, blocks):
     tname, args, section = blocks[0]
     args = parse_params(args, name='', expr='')
     name, expr = name_param(context, args, 'unless', 1)
     if expr is None:
         cond = name
     else:
         cond = expr.eval
     self.simple_form = (cond, None, section.blocks)
Пример #4
0
    def __init__(self, context, blocks):
        tname, args, section = blocks[0]
        args = parse_params(args, name='', expr='')
        name, expr = name_param(context, args, 'if', 1)
        self.__name__ = name
        if expr is None:
            cond = name
        else:
            cond = expr.eval
        sections = [cond, section.blocks]

        if blocks[-1][0] == 'else':
            tname, args, section = blocks[-1]
            del blocks[-1]
            args = parse_params(args, name='')
            if args:
                ename, expr = name_param(context, args, 'else', 1)
                if ename != name:
                    raise ParseError, ('name in else does not match if', 'in')
            elses = section.blocks
        else:
            elses = None

        for tname, args, section in blocks[1:]:
            if tname == 'else':
                raise ParseError, (
                    'more than one else tag for a single if tag', 'in')
            args = parse_params(args, name='', expr='')
            name, expr = name_param(context, args, 'elif', 1)
            if expr is None:
                cond = name
            else:
                cond = expr.eval
            sections.append(cond)
            sections.append(section.blocks)

        if elses is not None:
            sections.append(elses)

        self.simple_form = tuple(sections)
Пример #5
0
 def __init__(self, context, blocks):
     tname, args, section = blocks[0]
     args = parse_params(args, name='', expr='', mapping=1, only=1)
     name, expr = name_param(context, args, 'with', 1)
     if expr is None:
         expr = name
     else:
         expr = expr.eval
     self.__name__, self.expr = name, expr
     self.section = section.blocks
     if args.has_key('mapping') and args['mapping']:
         self.mapping = 1
     if args.has_key('only') and args['only']:
         self.only = 1
Пример #6
0
    def __init__(self, context, blocks):
        tname, args, section = blocks[0]

        self.args = parse_params(args)
        self.section = section.blocks


        # Find out if this is a try..finally type
        if len(blocks) == 2 and blocks[1][0] == 'finally':
            self.finallyBlock = blocks[1][2].blocks

        # This is a try [except]* [else] block.
        else:
            # store handlers as tuples (name,block)
            self.handlers = []
            defaultHandlerFound = 0

            for tname, nargs, nsection in blocks[1:]:
                if tname == 'else':
                    if not self.elseBlock is None:
                        raise ParseError, (
                            'No more than one else block is allowed',
                            self.name)
                    self.elseBlock = nsection.blocks

                elif tname == 'finally':
                    raise ParseError, (
                        'A try..finally combination cannot contain '
                        'any other else, except or finally blocks',
                        self.name)

                else:
                    if not self.elseBlock is None:
                        raise ParseError, (
                            'The else block should be the last block '
                            'in a try tag', self.name)

                    for errname in nargs.split():
                        self.handlers.append((errname, nsection.blocks))
                    if nargs.strip() == '':
                        if defaultHandlerFound:
                            raise ParseError, (
                                'Only one default exception handler '
                                'is allowed', self.name)
                        else:
                            defaultHandlerFound = 1
                            self.handlers.append(('', nsection.blocks))
Пример #7
0
    def __init__(self, context, args, fmt='s'):
        if args[:4] == 'var ':
            args = args[4:]
        args = parse_params(args,
                            name='',
                            lower=1,
                            upper=1,
                            expr='',
                            capitalize=1,
                            spacify=1,
                            null='',
                            fmt='s',
                            size=0,
                            etc='...',
                            thousands_commas=1,
                            html_quote=1,
                            url_quote=1,
                            sql_quote=1,
                            url_quote_plus=1,
                            missing='',
                            newline_to_br=1,
                            url=1)
        self.args = args

        self.modifiers = tuple(
            map(
                lambda t: t[1],
                filter(lambda m, args=args, used=args.has_key: used(m[0]) and
                       args[m[0]],
                       modifiers)))

        name, expr = name_param(context, args, 'var', 1)

        self.__name__, self.expr = name, expr
        self.fmt = fmt

        if len(args) == 1 and fmt == 's':
            if expr is None:
                expr = name
            else:
                expr = expr.eval
            self.simple_form = expr,
Пример #8
0
    def __init__(self, context, blocks):
        tname, args, section = blocks[0]
        args=parse_params(args, name='', start='1',end='-1',size='10',
                          orphan='3',overlap='1',mapping=1,
                          skip_unauthorized=1,
                          previous=1, next=1, expr='', sort='',
                          reverse=1, sort_expr='', reverse_expr='')
        self.args=args
        has_key=args.has_key

        if has_key('sort'):
            self.sort=sort=args['sort']
            if sort=='sequence-item': self.sort=''

        if has_key('sort_expr'):
            self.sort_expr = Eval(context, args['sort_expr'])

        if has_key('reverse_expr'):
            self.reverse_expr = Eval(context, args['reverse_expr'])

        if has_key('reverse'):
            self.reverse = args['reverse']

        if has_key('mapping'):
            self.mapping = args['mapping']
        for n in 'start', 'size', 'end':
            if has_key(n):
                self.batch=1

        for n in 'orphan','overlap','previous','next':
            if has_key(n) and not self.batch:
                raise ParseError, (
                    """
                    The %s attribute was used but neither of the
                    <code>start</code>, <code>end</code>, or <code>size</code>
                    attributes were used.
                    """ % n, 'in')

        if has_key('start'):
            v = args['start']
            if isinstance(v, str):
                try: v.atoi()
                except:
                    self.start_name_re = re.compile(
                        '&+'+
                        ''.join(map(lambda c: "[%s]" % c, v))+
                        '=[0-9]+&+')

        name, expr = name_param(context, args, 'in', 1)
        if expr is not None:
            expr = expr.eval
        self.__name__, self.expr = name, expr
        self.section = section.blocks
        if len(blocks) > 1:
            if len(blocks) != 2: raise ParseError, (
                'too many else blocks', 'in')
            tname, args, section = blocks[1]
            args=parse_params(args, name='')
            if args:
                ename = name_param(context, args)
                if ename != name:
                    raise ParseError, (
                        'name in else does not match in', 'in')
            self.elses = section.blocks
Пример #9
0
 def __init__(self, context, args):
     args = parse_params(args, name='', expr='')
     name, expr = name_param(context, args, 'var', 1)
     self.__name__, self.expr = name, expr