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

Function is_zipfile

Lib/zipfile/__init__.py:254–270  ·  view source on GitHub ↗

Quickly see if a file is a ZIP file by checking the magic number. The filename argument may be a file or file-like object too.

(filename)

Source from the content-addressed store, hash-verified

252 return False
253
254def is_zipfile(filename):
255 """Quickly see if a file is a ZIP file by checking the magic number.
256
257 The filename argument may be a file or file-like object too.
258 """
259 result = False
260 try:
261 if hasattr(filename, "read"):
262 pos = filename.tell()
263 result = _check_zipfile(fp=filename)
264 filename.seek(pos)
265 else:
266 with open(filename, "rb") as fp:
267 result = _check_zipfile(fp)
268 except (OSError, BadZipFile):
269 pass
270 return result
271
272def _handle_prepended_data(endrec, debug=0):
273 size_cd = endrec[_ECD_SIZE] # bytes in central directory

Callers

nothing calls this directly

Calls 4

_check_zipfileFunction · 0.85
openFunction · 0.50
tellMethod · 0.45
seekMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…