Let us walk on the 3-isogeny graph
Loading...
Searching...
No Matches
codingstatemachine.py
Go to the documentation of this file.
1
27
28
import
logging
29
30
from
.codingstatemachinedict
import
CodingStateMachineDict
31
from
.enums
import
MachineState
32
33
34
class
CodingStateMachine
:
35
"""
36
A state machine to verify a byte sequence for a particular encoding. For
37
each byte the detector receives, it will feed that byte to every active
38
state machine available, one byte at a time. The state machine changes its
39
state based on its previous state and the byte it receives. There are 3
40
states in a state machine that are of interest to an auto-detector:
41
42
START state: This is the state to start with, or a legal byte sequence
43
(i.e. a valid code point) for character has been identified.
44
45
ME state: This indicates that the state machine identified a byte sequence
46
that is specific to the charset it is designed for and that
47
there is no other possible encoding which can contain this byte
48
sequence. This will to lead to an immediate positive answer for
49
the detector.
50
51
ERROR state: This indicates the state machine identified an illegal byte
52
sequence for that encoding. This will lead to an immediate
53
negative answer for this encoding. Detector will exclude this
54
encoding from consideration from here on.
55
"""
56
57
def
__init__
(self, sm: CodingStateMachineDict) ->
None
:
58
self.
_model
= sm
59
self.
_curr_byte_pos
= 0
60
self.
_curr_char_len
= 0
61
self.
_curr_state
=
MachineState.START
62
self.
active
=
True
63
self.
logger
=
logging.getLogger
(__name__)
64
self.
reset
()
65
66
def
reset
(self) -> None:
67
self.
_curr_state
=
MachineState.START
68
69
def
next_state
(self, c: int) -> int:
70
# for each byte we get its class
71
# if it is first byte, we also get byte length
72
byte_class = self.
_model
[
"class_table"
][c]
73
if
self.
_curr_state
==
MachineState.START
:
74
self.
_curr_byte_pos
= 0
75
self.
_curr_char_len
= self.
_model
[
"char_len_table"
][byte_class]
76
# from byte's class and state_table, we get its next state
77
curr_state = self.
_curr_state
* self.
_model
[
"class_factor"
] + byte_class
78
self.
_curr_state
= self.
_model
[
"state_table"
][curr_state]
79
self.
_curr_byte_pos
+= 1
80
return
self.
_curr_state
81
82
def
get_current_charlen
(self) -> int:
83
return
self.
_curr_char_len
84
85
def
get_coding_state_machine
(self) -> str:
86
return
self.
_model
[
"name"
]
87
88
@property
89
def
language
(self) -> str:
90
return
self.
_model
[
"language"
]
pip._vendor.chardet.codingstatemachine.CodingStateMachine
Definition
codingstatemachine.py:34
pip._vendor.chardet.codingstatemachine.CodingStateMachine.logger
logger
Definition
codingstatemachine.py:63
pip._vendor.chardet.codingstatemachine.CodingStateMachine.next_state
int next_state(self, int c)
Definition
codingstatemachine.py:69
pip._vendor.chardet.codingstatemachine.CodingStateMachine._curr_byte_pos
_curr_byte_pos
Definition
codingstatemachine.py:59
pip._vendor.chardet.codingstatemachine.CodingStateMachine._curr_char_len
_curr_char_len
Definition
codingstatemachine.py:60
pip._vendor.chardet.codingstatemachine.CodingStateMachine.get_current_charlen
int get_current_charlen(self)
Definition
codingstatemachine.py:82
pip._vendor.chardet.codingstatemachine.CodingStateMachine.reset
None reset(self)
Definition
codingstatemachine.py:66
pip._vendor.chardet.codingstatemachine.CodingStateMachine.get_coding_state_machine
str get_coding_state_machine(self)
Definition
codingstatemachine.py:85
pip._vendor.chardet.codingstatemachine.CodingStateMachine._curr_state
_curr_state
Definition
codingstatemachine.py:61
pip._vendor.chardet.codingstatemachine.CodingStateMachine.active
active
Definition
codingstatemachine.py:62
pip._vendor.chardet.codingstatemachine.CodingStateMachine.__init__
None __init__(self, CodingStateMachineDict sm)
Definition
codingstatemachine.py:57
pip._vendor.chardet.codingstatemachine.CodingStateMachine.language
str language(self)
Definition
codingstatemachine.py:89
pip._vendor.chardet.codingstatemachine.CodingStateMachine._model
_model
Definition
codingstatemachine.py:58
i
for i
Definition
prime_search.m:10
venv
lib
python3.12
site-packages
pip
_vendor
chardet
codingstatemachine.py
Generated by
1.9.8