Changeset 3455:32328d691b0a in livinglogic.python.xist

Show
Ignore:
Timestamp:
07/04/08 17:06:06 (11 years ago)
Author:
Walter Doerwald <walter@…>
Branch:
default
Message:

Add a function vars() that returns a dictionary with all variables.

Files:
3 modified

Legend:

Unmodified
Added
Removed
  • docs/UL4.rst

    r3454 r3455  
    400400 
    401401 
     402``vars()`` 
     403::::::: 
     404 
     405``vars()`` returns a dictionary containing all currently defined variables 
     406(i.e. variables passed to the template, defined via ``<?code?>`` tags or as 
     407loop variables). 
     408 
     409 
    402410``isnone`` 
    403411:::::::::: 
  • src/ll/ul4c.py

    r3446 r3455  
    827827                    if opcode.arg == "now": 
    828828                        _code("reg%d = datetime.datetime.now()" % (opcode.r1)) 
     829                    elif opcode.arg == "vars": 
     830                        _code("reg%d = variables" % opcode.r1) 
    829831                    else: 
    830832                        raise UnknownFunctionError(opcode.arg) 
  • test/test_ul4.py

    r3447 r3455  
    367367    now = unicode(datetime.datetime.now()) 
    368368    checkle(now, "<?print now()?>") 
     369 
     370 
     371def test_function_vars(): 
     372    checkrunerror("function u?'vars' unknown", "<?print vars(1)?>") 
     373    checkrunerror("function u?'vars' unknown", "<?print vars(1, 2)?>") 
     374    check("yes", "<?if 'spam' in vars()?>yes<?else?>no<?end if?>", spam="eggs") 
    369375 
    370376