23 # License along with this library; if not, write to the Free Software |
23 # License along with this library; if not, write to the Free Software |
24 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
24 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
25 # 02110-1301 USA |
25 # 02110-1301 USA |
26 ######################### END LICENSE BLOCK ######################### |
26 ######################### END LICENSE BLOCK ######################### |
27 |
27 |
28 from constants import eStart, eError, eItsMe |
28 from .constants import eStart, eError, eItsMe |
29 |
29 |
30 class CodingStateMachine: |
30 class CodingStateMachine: |
31 def __init__(self, sm): |
31 def __init__(self, sm): |
32 self._mModel = sm |
32 self._mModel = sm |
33 self._mCurrentBytePos = 0 |
33 self._mCurrentBytePos = 0 |
38 self._mCurrentState = eStart |
38 self._mCurrentState = eStart |
39 |
39 |
40 def next_state(self, c): |
40 def next_state(self, c): |
41 # for each byte we get its class |
41 # for each byte we get its class |
42 # if it is first byte, we also get byte length |
42 # if it is first byte, we also get byte length |
43 byteCls = self._mModel['classTable'][ord(c)] |
43 # PY3K: aBuf is a byte stream, so c is an int, not a byte |
|
44 byteCls = self._mModel['classTable'][c] |
44 if self._mCurrentState == eStart: |
45 if self._mCurrentState == eStart: |
45 self._mCurrentBytePos = 0 |
46 self._mCurrentBytePos = 0 |
46 self._mCurrentCharLen = self._mModel['charLenTable'][byteCls] |
47 self._mCurrentCharLen = self._mModel['charLenTable'][byteCls] |
47 # from byte's class and stateTable, we get its next state |
48 # from byte's class and stateTable, we get its next state |
48 self._mCurrentState = self._mModel['stateTable'][self._mCurrentState * self._mModel['classFactor'] + byteCls] |
49 self._mCurrentState = self._mModel['stateTable'][self._mCurrentState * self._mModel['classFactor'] + byteCls] |