parameters: (self, root)
docstring: Fix the path of the images to match with IMAGES_DIR
docstring_summary: Fix the path of the images to match with IMAGES_DIR
docstring_tokens: Fix the path of the images to match with IMAGES_DIR
function: def _fix_images(self, root):
          """Fix the path of the images to match with IMAGES_DIR"""
  
          for element in root.iter('img'):
              src = element.get('src')
  
              # move to next element if there no src attribute
              if not src:
                  continue
  
              path = urllib.unquote(src)
  
              # if hostname, then it is an image with absolute url
              if urlparse.urlparse(path).hostname:
                  continue
  
              try:
                  path = path.decode('utf-8')
              except:
                  pass
  
              file_name = os.path.basename(path)
              element.set('src', "../{}/{}".format(IMAGES_DIR, file_name))
  
              # remove not allowed attributes from image element
              for attr in frozenset(element.keys()) - EPUB_VALID_IMG_ATTRS:
                  del element.attrib[attr]
  
              # make sure the alt attribute is valid
              alt = element.get('alt')
              not_valid = ['none', 'nothing', 'image']
  
              if (alt is None) or alt in not_valid:
                  element.set('alt', '')
function_tokens: def _fix_images ( self , root ) : for element in root . iter ( 'img' ) : src = element . get ( 'src' ) # move to next element if there no src attribute if not src : continue path = urllib . unquote ( src ) # if hostname, then it is an image with absolute url if urlparse . urlparse ( path ) . hostname : continue try : path = path . decode ( 'utf-8' ) except : pass file_name = os . path . basename ( path ) element . set ( 'src' , "../{}/{}" . format ( IMAGES_DIR , file_name ) ) # remove not allowed attributes from image element for attr in frozenset ( element . keys ( ) ) - EPUB_VALID_IMG_ATTRS : del element . attrib [ attr ] # make sure the alt attribute is valid alt = element . get ( 'alt' ) not_valid = [ 'none' , 'nothing' , 'image' ] if ( alt is None ) or alt in not_valid : element . set ( 'alt' , '' )