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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import constants
  5. import sys
  6. from constants import eStart, eError, eItsMe
  7. from charsetprober import CharSetProber
  8.  
  9. class MultiByteCharSetProber(CharSetProber):
  10.     
  11.     def __init__(self):
  12.         CharSetProber.__init__(self)
  13.         self._mDistributionAnalyzer = None
  14.         self._mCodingSM = None
  15.         self._mLastChar = [
  16.             '\x00',
  17.             '\x00']
  18.  
  19.     
  20.     def reset(self):
  21.         CharSetProber.reset(self)
  22.         if self._mCodingSM:
  23.             self._mCodingSM.reset()
  24.         
  25.         if self._mDistributionAnalyzer:
  26.             self._mDistributionAnalyzer.reset()
  27.         
  28.         self._mLastChar = [
  29.             '\x00',
  30.             '\x00']
  31.  
  32.     
  33.     def get_charset_name(self):
  34.         pass
  35.  
  36.     
  37.     def feed(self, aBuf):
  38.         aLen = len(aBuf)
  39.         for i in range(0, aLen):
  40.             codingState = self._mCodingSM.next_state(aBuf[i])
  41.             if codingState == eError:
  42.                 if constants._debug:
  43.                     sys.stderr.write(self.get_charset_name() + ' prober hit error at byte ' + str(i) + '\n')
  44.                 
  45.                 self._mState = constants.eNotMe
  46.                 break
  47.                 continue
  48.             if codingState == eItsMe:
  49.                 self._mState = constants.eFoundIt
  50.                 break
  51.                 continue
  52.             if codingState == eStart:
  53.                 charLen = self._mCodingSM.get_current_charlen()
  54.                 if i == 0:
  55.                     self._mLastChar[1] = aBuf[0]
  56.                     self._mDistributionAnalyzer.feed(self._mLastChar, charLen)
  57.                 else:
  58.                     self._mDistributionAnalyzer.feed(aBuf[i - 1:i + 1], charLen)
  59.             i == 0
  60.         
  61.         self._mLastChar[0] = aBuf[aLen - 1]
  62.         if self.get_state() == constants.eDetecting:
  63.             if self._mDistributionAnalyzer.got_enough_data() and self.get_confidence() > constants.SHORTCUT_THRESHOLD:
  64.                 self._mState = constants.eFoundIt
  65.             
  66.         
  67.         return self.get_state()
  68.  
  69.     
  70.     def get_confidence(self):
  71.         return self._mDistributionAnalyzer.get_confidence()
  72.  
  73.  
  74.