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
21 import cStringIO as StringIO
23 import StringIO as StringIO
27 assert isinstance( e , tuple ) and e , 'expected a non empty tuple'
28 s = StringIO.StringIO()
37 parens.append( x[ 0 ] )
40 last[ 0 ] = parens.pop()
44 prt( ' ' * ( last[ 0 ] - 1 ) )
54 if isinstance( e[ 0 ] , tuple ) :
57 t = e[ 0 ].replace( '\\' , '\\\\' ).replace( '\n' , '\\n' )
60 for item in e[ 1 : ] :
62 if isinstance( item , tuple ) :
66 if s[ 0 ].startswith( 'u' ) :
68 if s[ 0 ] == "'" : # force double-quote style
69 s = '"%s"' % ( s[ 1 : -1 ].replace( '"' , '\\"' ) )