home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_933 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  1.2 KB  |  40 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4.  
  5. def _optimize(tagList, tagName, conversion):
  6.     newTagList = []
  7.     for tag in tagList:
  8.         if tag.name == tagName or tag.name == 'rawtext':
  9.             newTagList.append(tag)
  10.             continue
  11.     
  12.     for i, newTag in enumerate(newTagList[:-1]):
  13.         if newTag.name == tagName and newTagList[i + 1].name == tagName:
  14.             tagList.remove(newTag)
  15.             continue
  16.     
  17.     newTagList = []
  18.     for tag in tagList:
  19.         if tag.name == tagName:
  20.             newTagList.append(tag)
  21.             continue
  22.     
  23.     for i, newTag in enumerate(newTagList[:-1]):
  24.         value = conversion(newTag.parameter)
  25.         nextValue = conversion(newTagList[i + 1].parameter)
  26.         if value == nextValue:
  27.             tagList.remove(newTagList[i + 1])
  28.             continue
  29.     
  30.     while len(tagList) > 0 and tagList[-1].name == tagName:
  31.         del tagList[-1]
  32.  
  33.  
  34. def tagListOptimizer(tagList):
  35.     oldSize = len(tagList)
  36.     _optimize(tagList, 'fontsize', int)
  37.     _optimize(tagList, 'fontweight', int)
  38.     return oldSize - len(tagList)
  39.  
  40.