MCPcopy Index your code
hub / github.com/python/cpython / find_cookie

Function find_cookie

Lib/tokenize.py:400–425  ·  view source on GitHub ↗
(line)

Source from the content-addressed store, hash-verified

398 raise SyntaxError(msg)
399
400 def find_cookie(line):
401 match = cookie_re.match(line)
402 if not match:
403 return None
404 encoding = _get_normal_name(match.group(1).decode())
405 try:
406 lookup(encoding)
407 except LookupError:
408 # This behaviour mimics the Python interpreter
409 if filename is None:
410 msg = "unknown encoding: " + encoding
411 else:
412 msg = "unknown encoding for {!r}: {}".format(filename,
413 encoding)
414 raise SyntaxError(msg)
415
416 if bom_found:
417 if encoding != 'utf-8':
418 # This behaviour mimics the Python interpreter
419 if filename is None:
420 msg = 'encoding problem: utf-8'
421 else:
422 msg = 'encoding problem for {!r}: utf-8'.format(filename)
423 raise SyntaxError(msg)
424 encoding += '-sig'
425 return encoding
426
427 first = read_or_stop()
428 if first.startswith(BOM_UTF8):

Callers 1

detect_encodingFunction · 0.85

Calls 6

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…