MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / _zip_directory

Function _zip_directory

py/selenium/webdriver/remote/webdriver.py:111–125  ·  view source on GitHub ↗

Zip `directory` recursively and return the archive base64-encoded. Entry names are relative to `root`: passing the directory itself puts its contents at the archive root, passing the parent keeps the directory as the archive's single top-level entry.

(directory: str, root: str)

Source from the content-addressed store, hash-verified

109
110
111def _zip_directory(directory: str, root: str) -> str:
112 """Zip `directory` recursively and return the archive base64-encoded.
113
114 Entry names are relative to `root`: passing the directory itself puts its
115 contents at the archive root, passing the parent keeps the directory as the
116 archive's single top-level entry.
117 """
118 directory = os.path.normpath(directory)
119 buffer = BytesIO()
120 with zipfile.ZipFile(buffer, "w", zipfile.ZIP_DEFLATED, strict_timestamps=False) as archive:
121 for base, _, files in os.walk(directory):
122 for name in files:
123 filename = os.path.join(base, name)
124 archive.write(filename, os.path.relpath(filename, root))
125 return base64.b64encode(buffer.getvalue()).decode("utf-8")
126
127
128def _encode_extension(path: str) -> str:

Callers 2

_encode_extensionFunction · 0.85
_upload_web_extensionMethod · 0.85

Calls 2

decodeMethod · 0.65
writeMethod · 0.45

Tested by

no test coverage detected