MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / find_cookie

Function find_cookie

tools/python-3.11.9-amd64/Lib/tokenize.py:329–365  ·  view source on GitHub ↗
(line)

Source from the content-addressed store, hash-verified

327 return b''
328
329 def find_cookie(line):
330 try:
331 # Decode as UTF-8. Either the line is an encoding declaration,
332 # in which case it should be pure ASCII, or it must be UTF-8
333 # per default encoding.
334 line_string = line.decode('utf-8')
335 except UnicodeDecodeError:
336 msg = "invalid or missing encoding declaration"
337 if filename is not None:
338 msg = '{} for {!r}'.format(msg, filename)
339 raise SyntaxError(msg)
340
341 match = cookie_re.match(line_string)
342 if not match:
343 return None
344 encoding = _get_normal_name(match.group(1))
345 try:
346 codec = lookup(encoding)
347 except LookupError:
348 # This behaviour mimics the Python interpreter
349 if filename is None:
350 msg = "unknown encoding: " + encoding
351 else:
352 msg = "unknown encoding for {!r}: {}".format(filename,
353 encoding)
354 raise SyntaxError(msg)
355
356 if bom_found:
357 if encoding != 'utf-8':
358 # This behaviour mimics the Python interpreter
359 if filename is None:
360 msg = 'encoding problem: utf-8'
361 else:
362 msg = 'encoding problem for {!r}: utf-8'.format(filename)
363 raise SyntaxError(msg)
364 encoding += '-sig'
365 return encoding
366
367 first = read_or_stop()
368 if first.startswith(BOM_UTF8):

Callers 1

detect_encodingFunction · 0.70

Calls 6

_get_normal_nameFunction · 0.70
lookupFunction · 0.70
decodeMethod · 0.45
formatMethod · 0.45
matchMethod · 0.45
groupMethod · 0.45

Tested by

no test coverage detected