#NEWLINE# def visit_image( self , node ) : #NEWLINE# #INDENT# atts = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# uri = node [ 'uri' ] #NEWLINE# types = { #NEWLINE# #INDENT# '.swf' : 'application/x-shockwave-flash' , #NEWLINE# #UNINDENT# } #NEWLINE# ext = os . path . splitext ( uri ) [ 1 ] . lower ( ) #NEWLINE# if ( ext == '.swf' ) : #NEWLINE# #INDENT# atts [ 'data' ] = uri #NEWLINE# atts [ 'type' ] = types [ ext ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# atts [ 'src' ] = uri #NEWLINE# atts [ 'alt' ] = node . get ( 'alt' , uri ) #NEWLINE# #UNINDENT# if ( 'width' in node ) : #NEWLINE# #INDENT# atts [ 'width' ] = node [ 'width' ] #NEWLINE# #UNINDENT# if ( 'height' in node ) : #NEWLINE# #INDENT# atts [ 'height' ] = node [ 'height' ] #NEWLINE# #UNINDENT# if ( 'scale' in node ) : #NEWLINE# #INDENT# if ( PIL and ( not ( ( 'width' in node ) and ( 'height' in node ) ) ) and self . settings . file_insertion_enabled ) : #NEWLINE# #INDENT# imagepath = urllib . request . url2pathname ( uri ) #NEWLINE# try : #NEWLINE# #INDENT# img = PIL . Image . open ( imagepath . encode ( sys . getfilesystemencoding ( ) ) ) #NEWLINE# #UNINDENT# except ( IOError , UnicodeEncodeError ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . settings . record_dependencies . add ( imagepath . replace ( '\\' , '/' ) ) #NEWLINE# if ( 'width' not in atts ) : #NEWLINE# #INDENT# atts [ 'width' ] = str ( self . size [ 0 ] ) #NEWLINE# #UNINDENT# if ( 'height' not in atts ) : #NEWLINE# #INDENT# atts [ 'height' ] = str ( img . size [ 1 ] ) #NEWLINE# #UNINDENT# del img #NEWLINE# #UNINDENT# #UNINDENT# for att_name in ( 'width' , 'height' ) : #NEWLINE# #INDENT# if ( att_name in atts ) : #NEWLINE# #INDENT# match = re . match ( '([0-9.]+)(\\S*)$' , atts [ att_name ] ) #NEWLINE# assert match #NEWLINE# atts [ att_name ] = ( '%s%s' % ( ( float ( match . group ( 1 ) ) * ( float ( node [ 'scale' ] ) / 100 ) ) , match . group ( 2 ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# style = [ ] #NEWLINE# for att_name in ( 'width' , 'height' ) : #NEWLINE# #INDENT# if ( att_name in atts ) : #NEWLINE# #INDENT# if re . match ( '^[0-9.]+$' , atts [ att_name ] ) : #NEWLINE# #INDENT# atts [ att_name ] += 'px' #NEWLINE# #UNINDENT# style . append ( ( '%s: %s;' % ( att_name , atts [ att_name ] ) ) ) #NEWLINE# del atts [ att_name ] #NEWLINE# #UNINDENT# #UNINDENT# if style : #NEWLINE# #INDENT# atts [ 'style' ] = ' ' . join ( style ) #NEWLINE# #UNINDENT# if ( isinstance ( node . parent , nodes . TextElement ) or ( isinstance ( node . parent , nodes . reference ) and ( not isinstance ( node . parent . parent , nodes . TextElement ) ) ) ) : #NEWLINE# #INDENT# suffix = '' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# suffix = '\n' #NEWLINE# #UNINDENT# if ( 'align' in node ) : #NEWLINE# #INDENT# atts [ 'class' ] = ( 'align-%s' % node [ 'align' ] ) #NEWLINE# #UNINDENT# self . context . append ( '' ) #NEWLINE# if ( ext == '.swf' ) : #NEWLINE# #INDENT# self . body . append ( ( ( ( self . starttag ( node , 'object' , suffix , ** atts ) + node . get ( 'alt' , uri ) ) + '</object>' ) + suffix ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . body . append ( self . emptytag ( node , 'img' , suffix , ** atts ) )