3 # Context object for XPath
4 # Copyright (C) 2005 Frédéric Jolliton <frederic@jolliton.com>
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 class Context( object ) :
29 __slots__ = [ 'item' , 'position' , 'last' , 'documents' , 'variables' , 'functions' , 'currentDatetime' ]
31 def __init__( self ) :
41 def resetDate( self ) :
43 self.currentDatetime = time.time()
45 def resetFocus( self ) :
51 def getFocus( self ) :
53 return self.item , self.position , self.last
55 def restoreFocus( self , state ) :
57 self.item , self.position , self.last = state
59 def getVariable( self , name ) :
61 '''Return value of variable named 'name'.'''
63 return self.variables.get( name , () )
65 def getFunction( self , name ) :
67 '''Return function named 'name'.'''
69 return self.functions.get( name , None )
71 def registerDocument( self , uri , doc ) :
73 '''Store document 'doc' with URI reference 'uri'.'''
75 self.documents[ uri ] = doc
77 def __repr__( self ) :
79 return '<Context item=%s position=%s last=%s>' \
80 % ( self.item , self.position , self.last )
82 nullContext = Context()