MCPcopy Create free account
hub / github.com/sqlmapproject/sqlmap / close

Method close

thirdparty/chardet/universaldetector.py:220–286  ·  view source on GitHub ↗

Stop analyzing the current document and come up with a final prediction. :returns: The ``result`` attribute, a ``dict`` with the keys `encoding`, `confidence`, and `language`.

(self)

Source from the content-addressed store, hash-verified

218 self._has_win_bytes = True
219
220 def close(self):
221 """
222 Stop analyzing the current document and come up with a final
223 prediction.
224
225 :returns: The ``result`` attribute, a ``dict`` with the keys
226 `encoding`, `confidence`, and `language`.
227 """
228 # Don't bother with checks if we're already done
229 if self.done:
230 return self.result
231 self.done = True
232
233 if not self._got_data:
234 self.logger.debug('no data received!')
235
236 # Default to ASCII if it is all we've seen so far
237 elif self._input_state == InputState.PURE_ASCII:
238 self.result = {'encoding': 'ascii',
239 'confidence': 1.0,
240 'language': ''}
241
242 # If we have seen non-ASCII, return the best that met MINIMUM_THRESHOLD
243 elif self._input_state == InputState.HIGH_BYTE:
244 prober_confidence = None
245 max_prober_confidence = 0.0
246 max_prober = None
247 for prober in self._charset_probers:
248 if not prober:
249 continue
250 prober_confidence = prober.get_confidence()
251 if prober_confidence > max_prober_confidence:
252 max_prober_confidence = prober_confidence
253 max_prober = prober
254 if max_prober and (max_prober_confidence > self.MINIMUM_THRESHOLD):
255 charset_name = max_prober.charset_name
256 lower_charset_name = max_prober.charset_name.lower()
257 confidence = max_prober.get_confidence()
258 # Use Windows encoding name instead of ISO-8859 if we saw any
259 # extra Windows-specific bytes
260 if lower_charset_name.startswith('iso-8859'):
261 if self._has_win_bytes:
262 charset_name = self.ISO_WIN_MAP.get(lower_charset_name,
263 charset_name)
264 self.result = {'encoding': charset_name,
265 'confidence': confidence,
266 'language': max_prober.language}
267
268 # Log all prober confidences if none met MINIMUM_THRESHOLD
269 if self.logger.getEffectiveLevel() == logging.DEBUG:
270 if self.result['encoding'] is None:
271 self.logger.debug('no probers hit minimum threshold')
272 for group_prober in self._charset_probers:
273 if not group_prober:
274 continue
275 if isinstance(group_prober, CharSetGroupProber):
276 for prober in group_prober.probers:
277 self.logger.debug('%s %s confidence = %s',

Callers 1

detectFunction · 0.95

Calls 3

debugMethod · 0.80
get_confidenceMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected