summaryrefslogtreecommitdiff
path: root/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/chardet/escprober.py
diff options
context:
space:
mode:
authorShubham Saini <shubham6405@gmail.com>2019-08-05 08:32:33 +0000
committerShubham Saini <shubham6405@gmail.com>2019-08-05 08:32:33 +0000
commit227b2d30a8675b44918f9d9ca89b24144a938215 (patch)
tree9f8e6a28724514b6fdf463a9ab2067a7ef309b72 /venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/chardet/escprober.py
parent842a8cfbbbdb1f92889d892e4859dbd5d40c5be8 (diff)
removing venv files
Diffstat (limited to 'venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/chardet/escprober.py')
-rw-r--r--venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/chardet/escprober.py101
1 files changed, 0 insertions, 101 deletions
diff --git a/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/chardet/escprober.py b/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/chardet/escprober.py
deleted file mode 100644
index c52060d..0000000
--- a/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/chardet/escprober.py
+++ /dev/null
@@ -1,101 +0,0 @@
1######################## BEGIN LICENSE BLOCK ########################
2# The Original Code is mozilla.org code.
3#
4# The Initial Developer of the Original Code is
5# Netscape Communications Corporation.
6# Portions created by the Initial Developer are Copyright (C) 1998
7# the Initial Developer. All Rights Reserved.
8#
9# Contributor(s):
10# Mark Pilgrim - port to Python
11#
12# This library is free software; you can redistribute it and/or
13# modify it under the terms of the GNU Lesser General Public
14# License as published by the Free Software Foundation; either
15# version 2.1 of the License, or (at your option) any later version.
16#
17# This library is distributed in the hope that it will be useful,
18# but WITHOUT ANY WARRANTY; without even the implied warranty of
19# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20# Lesser General Public License for more details.
21#
22# You should have received a copy of the GNU Lesser General Public
23# License along with this library; if not, write to the Free Software
24# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
25# 02110-1301 USA
26######################### END LICENSE BLOCK #########################
27
28from .charsetprober import CharSetProber
29from .codingstatemachine import CodingStateMachine
30from .enums import LanguageFilter, ProbingState, MachineState
31from .escsm import (HZ_SM_MODEL, ISO2022CN_SM_MODEL, ISO2022JP_SM_MODEL,
32 ISO2022KR_SM_MODEL)
33
34
35class EscCharSetProber(CharSetProber):
36 """
37 This CharSetProber uses a "code scheme" approach for detecting encodings,
38 whereby easily recognizable escape or shift sequences are relied on to
39 identify these encodings.
40 """
41
42 def __init__(self, lang_filter=None):
43 super(EscCharSetProber, self).__init__(lang_filter=lang_filter)
44 self.coding_sm = []
45 if self.lang_filter & LanguageFilter.CHINESE_SIMPLIFIED:
46 self.coding_sm.append(CodingStateMachine(HZ_SM_MODEL))
47 self.coding_sm.append(CodingStateMachine(ISO2022CN_SM_MODEL))
48 if self.lang_filter & LanguageFilter.JAPANESE:
49 self.coding_sm.append(CodingStateMachine(ISO2022JP_SM_MODEL))
50 if self.lang_filter & LanguageFilter.KOREAN:
51 self.coding_sm.append(CodingStateMachine(ISO2022KR_SM_MODEL))
52 self.active_sm_count = None
53 self._detected_charset = None
54 self._detected_language = None
55 self._state = None
56 self.reset()
57
58 def reset(self):
59 super(EscCharSetProber, self).reset()
60 for coding_sm in self.coding_sm:
61 if not coding_sm:
62 continue
63 coding_sm.active = True
64 coding_sm.reset()
65 self.active_sm_count = len(self.coding_sm)
66 self._detected_charset = None
67 self._detected_language = None
68
69 @property
70 def charset_name(self):
71 return self._detected_charset
72
73 @property
74 def language(self):
75 return self._detected_language
76
77 def get_confidence(self):
78 if self._detected_charset:
79 return 0.99
80 else:
81 return 0.00
82
83 def feed(self, byte_str):
84 for c in byte_str:
85 for coding_sm in self.coding_sm:
86 if not coding_sm or not coding_sm.active:
87 continue
88 coding_state = coding_sm.next_state(c)
89 if coding_state == MachineState.ERROR:
90 coding_sm.active = False
91 self.active_sm_count -= 1
92 if self.active_sm_count <= 0:
93 self._state = ProbingState.NOT_ME
94 return self.state
95 elif coding_state == MachineState.ITS_ME:
96 self._state = ProbingState.FOUND_IT
97 self._detected_charset = coding_sm.get_coding_state_machine()
98 self._detected_language = coding_sm.language
99 return self.state
100
101 return self.state