Fixed / overloading when enabling true division.
[tx] / context.py
1 # -*- coding:utf-8 -*-
2
3 # Context object for XPath
4 # Copyright (C) 2005  Frédéric Jolliton <frederic@jolliton.com>
5
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.
10
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.
15
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
19
20 __all__ = [
21           'Context'
22         , 'nullContext'
23         ]
24
25 import time
26
27 class Context( object ) :
28
29         __slots__ = [ 'item' , 'position' , 'last' , 'documents' , 'variables' , 'functions' , 'currentDatetime' ]
30
31         def __init__( self ) :
32
33                 self.item = None
34                 self.position = None
35                 self.last = None
36                 self.documents = {}
37                 self.variables = {}
38                 self.functions = {}
39                 self.resetDate()
40
41         def resetDate( self ) :
42
43                 self.currentDatetime = time.time()
44
45         def resetFocus( self ) :
46
47                 self.item = None
48                 self.position = None
49                 self.last = None
50
51         def getFocus( self ) :
52
53                 return self.item , self.position , self.last
54
55         def restoreFocus( self , state ) :
56
57                 self.item , self.position , self.last = state
58
59         def getVariable( self , name ) :
60
61                 '''Return value of variable named 'name'.'''
62
63                 return self.variables.get( name , () )
64
65         def getFunction( self , name ) :
66
67                 '''Return function named 'name'.'''
68
69                 return self.functions.get( name , None )
70
71         def registerDocument( self , uri , doc ) :
72
73                 '''Store document 'doc' with URI reference 'uri'.'''
74
75                 self.documents[ uri ] = doc
76
77         def __repr__( self ) :
78
79                 return '<Context item=%s position=%s last=%s>' \
80                         % ( self.item , self.position , self.last )
81
82 nullContext = Context()
83
84 # Local Variables:
85 # tab-width: 4
86 # python-indent: 4
87 # End: