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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import constants
  5. from escsm import HZSMModel, ISO2022CNSMModel, ISO2022JPSMModel, ISO2022KRSMModel
  6. from charsetprober import CharSetProber
  7. from codingstatemachine import CodingStateMachine
  8.  
  9. class EscCharSetProber(CharSetProber):
  10.     
  11.     def __init__(self):
  12.         CharSetProber.__init__(self)
  13.         self._mCodingSM = [
  14.             CodingStateMachine(HZSMModel),
  15.             CodingStateMachine(ISO2022CNSMModel),
  16.             CodingStateMachine(ISO2022JPSMModel),
  17.             CodingStateMachine(ISO2022KRSMModel)]
  18.         self.reset()
  19.  
  20.     
  21.     def reset(self):
  22.         CharSetProber.reset(self)
  23.         for codingSM in self._mCodingSM:
  24.             if not codingSM:
  25.                 continue
  26.             
  27.             codingSM.active = constants.True
  28.             codingSM.reset()
  29.         
  30.         self._mActiveSM = len(self._mCodingSM)
  31.         self._mDetectedCharset = None
  32.  
  33.     
  34.     def get_charset_name(self):
  35.         return self._mDetectedCharset
  36.  
  37.     
  38.     def get_confidence(self):
  39.         if self._mDetectedCharset:
  40.             return 0.99
  41.         return 0
  42.  
  43.     
  44.     def feed(self, aBuf):
  45.         for c in aBuf:
  46.             for codingSM in self._mCodingSM:
  47.                 if not codingSM:
  48.                     continue
  49.                 
  50.                 if not codingSM.active:
  51.                     continue
  52.                 
  53.                 codingState = codingSM.next_state(c)
  54.                 if codingState == constants.eError:
  55.                     codingSM.active = constants.False
  56.                     self._mActiveSM -= 1
  57.                     if self._mActiveSM <= 0:
  58.                         self._mState = constants.eNotMe
  59.                         return self.get_state()
  60.                     continue
  61.                 self._mActiveSM <= 0
  62.                 if codingState == constants.eItsMe:
  63.                     self._mState = constants.eFoundIt
  64.                     self._mDetectedCharset = codingSM.get_coding_state_machine()
  65.                     return self.get_state()
  66.             
  67.         
  68.         return self.get_state()
  69.  
  70.  
  71.