root/galaxy-central/lib/galaxy/util/expressions.py

リビジョン 2, 0.9 KB (コミッタ: hatakeyama, 14 年 前)

import galaxy-central

行番号 
1"""
2Expression evaluation support.
3
4For the moment this depends on python's eval. In the future it should be
5replaced with a "safe" parser.
6"""
7
8from UserDict import DictMixin
9
10class ExpressionContext( object, DictMixin ):
11    def __init__( self, dict, parent=None ):
12        """
13        Create a new expression context that looks for values in the
14        container object 'dict', and falls back to 'parent'
15        """
16        self.dict = dict
17        self.parent = parent
18    def __getitem__( self, key ):
19        if key in self.dict:
20            return self.dict[key]
21        if self.parent is not None and key in self.parent:
22            return self.parent[key]
23        raise KeyError( key )
24    def __contains__( self, key ):
25        if key in self.dict:
26            return True
27        if self.parent is not None and key in self.parent:
28            return True
29        return False
30    def __str__( self ):
31        return str( self.dict )
32       
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。