-
-
Notifications
You must be signed in to change notification settings - Fork 187
Expand file tree
/
Copy pathzipfs.py
More file actions
47 lines (36 loc) · 1.1 KB
/
zipfs.py
File metadata and controls
47 lines (36 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# coding: utf-8
"""`ZipFS` opener definition.
"""
from __future__ import absolute_import
from __future__ import print_function
from __future__ import unicode_literals
import typing
from .base import Opener
from .registry import registry
from .errors import NotWriteable
if typing.TYPE_CHECKING:
from typing import Text
from .parse import ParseResult
from ..zipfs import ZipFS # noqa: F401
@registry.install
class ZipOpener(Opener):
"""`ZipFS` opener.
"""
protocols = ["zip"]
def open_fs(
self,
fs_url, # type: Text
parse_result, # type: ParseResult
writeable, # type: bool
create, # type: bool
cwd, # type: Text
):
# type: (...) -> ZipFS
from ..zipfs import ZipFS
if not create and writeable:
raise NotWriteable("Unable to open existing ZIP file for writing")
password = parse_result.params.get("password")
if password is not None:
password = password.encode()
zip_fs = ZipFS(parse_result.resource, write=create, password=password)
return zip_fs