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