Package pyffi :: Package object_models :: Package xml :: Module expression :: Class Expression
[hide private]
[frames] | no frames]

Class Expression

source code

object --+
         |
        Expression

This class represents an expression.

>>> class A(object):
...     x = False
...     y = True
>>> a = A()
>>> e = Expression('x || y')
>>> e.eval(a)
1
>>> Expression('99 & 15').eval(a)
3
>>> bool(Expression('(99&15)&&y').eval(a))
True
>>> a.hello_world = False
>>> def nameFilter(s):
...     return 'hello_' + s.lower()
>>> bool(Expression('(99 &15) &&WoRlD', name_filter = nameFilter).eval(a))
False
>>> Expression('c && d').eval(a)
Traceback (most recent call last):
    ...
AttributeError: 'A' object has no attribute 'c'
>>> bool(Expression('1 == 1').eval())
True
>>> bool(Expression('(1 == 1)').eval())
True
>>> bool(Expression('1 != 1').eval())
False
>>> bool(Expression('!(1 == 1)').eval())
False
>>> bool(Expression('!((1 <= 2) && (2 <= 3))').eval())
False
>>> bool(Expression('(1 <= 2) && (2 <= 3) && (3 <= 4)').eval())
True
Instance Methods [hide private]
 
__init__(self, expr_str, name_filter=None)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
eval(self, data=None)
Evaluate the expression to an integer.
source code
 
__str__(self)
Reconstruct the expression to a string.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __subclasshook__

Class Methods [hide private]
 
_parse(cls, expr_str, name_filter=None)
Returns an Expression, string, or int, depending on the contents of <expr_str>.
source code
 
_partition(cls, expr_str)
Partitions expr_str.
source code
Static Methods [hide private]
 
_scanBrackets(expr_str, fromIndex=0)
Looks for matching brackets.
source code
Class Variables [hide private]
  operators = ['==', '!=', '>=', '<=', '&&', '||', '&', '|', '-'...
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, expr_str, name_filter=None)
(Constructor)

source code 
x.__init__(...) initializes x; see help(type(x)) for signature
Overrides: object.__init__
(inherited documentation)

__str__(self)
(Informal representation operator)

source code 
Reconstruct the expression to a string.
Overrides: object.__str__

_partition(cls, expr_str)
Class Method

source code 

Partitions expr_str. See examples below.

>>> Expression._partition('abc || efg')
('abc', '||', 'efg')
>>> Expression._partition('abc||efg')
('abc', '||', 'efg')
>>> Expression._partition('abcdefg')
('abcdefg', '', '')
>>> Expression._partition(' abcdefg ')
('abcdefg', '', '')
>>> Expression._partition(' (a | b) & c ')
('a | b', '&', 'c')
>>> Expression._partition('(a | b)!=(b&c)')
('a | b', '!=', 'b&c')
>>> Expression._partition('(a== b) &&(( b!=c)||d )')
('a== b', '&&', '( b!=c)||d')
>>> Expression._partition('!(1 <= 2)')
('', '!', '(1 <= 2)')
>>> Expression._partition('')
('', '', '')
>>> Expression._partition('(1 == 1)')
('1 == 1', '', '')

Class Variable Details [hide private]

operators

Value:
['==',
 '!=',
 '>=',
 '<=',
 '&&',
 '||',
 '&',
 '|',
...