示例#1
0
def p_literal(p):
    '''literal : NUMBER
               | stringLiteral
               '''
    p[0] = node.helper.expr(p[1])

    # strings with escaped non printable characters need to be treated with care. ESI doesn't have a means to address
    # this, so we will use a bit of a hack by representing the unprintable characters in base64 and use the decode function
    if 0 == 1 and isinstance(p[0], node.Literal) and p[0].value and isinstance(
            p[0].value, str):
        vals = []
        index = 0
        init_literal = p[0].value
        unprintable = re.compile(
            u'[\x00\x01\x02\x03\x04\x05\x06\x07\x08\x0b\x0c\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f'
            +
            '\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff]+'
        )
        for match in unprintable.finditer(init_literal):
            text = init_literal[index:match.start()]
            non_text = init_literal[match.start():match.end()]
            index = match.end()
            if text: vals.append(node.Literal(text))
            vals.append(
                node.FunctionCall(
                    "base64_decode",
                    node.Literal(
                        base64.b64encode(
                            non_text.encode('utf-8')).decode('utf-8'))))
        if index < len(init_literal):
            vals.append(node.Literal(init_literal[index:]))
        if len(vals) == 1:
            p[0] = vals[0]
        elif len(vals) > 1:
            p[0] = node.Add(*vals)
示例#2
0
def p_assign_incdec(p):
    '''assign : assignLvalue INCREMENT
              | assignLvalue DECREMENT
              '''
    op = p[2][0] == '+' and node.Plus or node.Minus
    p[0] = node.Assign(p[1][0],
                       op(node.Variable(p[1][0], key=p[1][1]),
                          node.Literal(1)),
                       key=p[1][1])
示例#3
0
def p_includeAttribute(p):
    '''includeAttribute : aSRC varsExpr
                        | aALT varsExpr
                        | aDCA varsExpr
                        | aONERROR varsExpr
                        | aMAXWAIT varsExpr
                        | aTTL varsExpr
                        | aNOSTORE varsExpr
                        | aAPPENDHEADER varsExpr
                        | aREMOVEHEADER varsExpr
                        | aSETHEADER varsExpr
                        | aMETHOD varsExpr
                        | aENTITY varsExpr
                        '''
    p[0] = (p[1], p[2])
    # tbd: this is a serious hack... but, then again, so is ESI...
    if p[1] == 'dca' and isinstance(p[2], node.Literal) and '\'' in p[2].value:
        p[0] = (p[1], node.Literal(p[2].value.replace('\'', '')))
    # tbd: this is somewhat of a hack as well... it indicates that
    #      includeAttribute should probably not be a varsExpr, but something
    #      a little smarter...
    if p[1] == 'maxwait' and isinstance(p[2], node.Literal):
        p[0] = (p[1], node.Literal(int(p[2].value)))
示例#4
0
def p_literal_bool(p):
    '''literal : TRUE
               | FALSE
               '''
    p[0] = node.Literal(p[1] == 'true')
示例#5
0
def p_literal(p):
    '''literal : NUMBER
               | string
               '''
    p[0] = node.Literal(p[1])
示例#6
0
def p_dictionaryEntry_symbol(p):
    'dictionaryEntry : SYMBOL COLON expression'
    p[0] = (node.Literal(p[1]), p[3])
示例#7
0
def p_factor_symbol(p):
    'factor : SYMBOL'
    p[0] = node.Literal(p[1])
示例#8
0
def p_varsExpr_literal(p):
    'varsExprElement : string'
    p[0] = node.Literal(p[1])