Fixed / overloading when enabling true division.
[tx] / sequence_misc.py
1 # -*- coding:utf-8 -*-
2
3 # Sequence misc
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         'printSequence'
22         ]
23
24 import sys
25 from decimal import Decimal
26
27 from sequence import Sequence
28 from nodes import Node
29 from nodes_misc import nodeToXpath
30
31 def printSequence( sequence , fullTree = False , displayLocation = False ) :
32
33         if not isinstance( sequence , Sequence ) :
34                 print 'Not a sequence' , `sequence`
35         elif not sequence :
36                 print 'EMPTY'
37         else :
38                 for i , item in enumerate( sequence ) :
39                         i += 1
40                         if isinstance( item , Node ) :
41                                 print i , 'NODE' ,
42                                 if displayLocation :
43                                         print nodeToXpath( item )
44                                 else :
45                                         print '' , # Needed to insert a space before the asDebug() output !
46                                 if not fullTree :
47                                         item.asDebug( maxDepth = 2 , maxChildren = 0 , file = sys.stdout )
48                                 else :
49                                         item.asDebug( file = sys.stdout )
50                         elif isinstance( item , basestring ) :
51                                 print i , 'STRING' , item
52                         elif isinstance( item , bool ) :
53                                 print i , 'BOOLEAN' , item
54                         elif isinstance( item , ( int , long ) ) :
55                                 print i , 'INTEGER' , item
56                         elif isinstance( item , Decimal ) :
57                                 print i , 'DECIMAL' , item
58                         elif isinstance( item , float ) :
59                                 print i , 'FLOAT|DOUBLE' , item
60                         else :
61                                 print i , '*UNKNOWN*' , `item`
62
63 # Local Variables:
64 # tab-width: 4
65 # python-indent: 4
66 # End: