Method: gzip.GzipFile.__init__
Calls: 375, Exceptions: 4, Paths: 15Back
Path 1: 235 calls (0.63)
'@test_23421_tmpæ' (232) PosixPath (2) '/Users/andrehora/Desktop/xxx/@test_23421_tmpæ-gzdir/testgzip.gz' (1)
'ab' (203) 'wb' (30) 'xb' (2)
9 (235)
None (235)
None (235)
1def __init__(self, filename=None, mode=None,
2 compresslevel=_COMPRESS_LEVEL_BEST, fileobj=None, mtime=None):
3 """Constructor for the GzipFile class.
4
5 At least one of fileobj and filename must be given a
6 non-trivial value.
7
8 The new class instance is based on fileobj, which can be a regular
9 file, an io.BytesIO object, or any other object which simulates a file.
10 It defaults to None, in which case filename is opened to provide
11 a file object.
12
13 When fileobj is not None, the filename argument is only used to be
14 included in the gzip file header, which may include the original
15 filename of the uncompressed file. It defaults to the filename of
16 fileobj, if discernible; otherwise, it defaults to the empty string,
17 and in this case the original filename is not included in the header.
18
19 The mode argument can be any of 'r', 'rb', 'a', 'ab', 'w', 'wb', 'x', or
20 'xb' depending on whether the file will be read or written. The default
21 is the mode of fileobj if discernible; otherwise, the default is 'rb'.
22 A mode of 'r' is equivalent to one of 'rb', and similarly for 'w' and
23 'wb', 'a' and 'ab', and 'x' and 'xb'.
24
25 The compresslevel argument is an integer from 0 to 9 controlling the
26 level of compression; 1 is fastest and produces the least compression,
27 and 9 is slowest and produces the most compression. 0 is no compression
28 at all. The default is 9.
29
30 The mtime argument is an optional numeric timestamp to be written
31 to the last modification time field in the stream when compressing.
32 If omitted or None, the current time is used.
33
34 """
35
36 if mode and ('t' in mode or 'U' in mode):
37 raise ValueError("Invalid mode: {!r}".format(mode))
38 if mode and 'b' not in mode:
39 mode += 'b'
40 if fileobj is None:
41 fileobj = self.myfileobj = builtins.open(filename, mode or 'rb')
42 if filename is None:
43 filename = getattr(fileobj, 'name', '')
44 if not isinstance(filename, (str, bytes)):
45 filename = ''
46 else:
47 filename = os.fspath(filename)
48 origmode = mode
49 if mode is None:
50 mode = getattr(fileobj, 'mode', 'rb')
51
52 if mode.startswith('r'):
53 self.mode = READ
54 raw = _GzipReader(fileobj)
55 self._buffer = io.BufferedReader(raw)
56 self.name = filename
57
58 elif mode.startswith(('w', 'a', 'x')):
59 if origmode is None:
60 import warnings
61 warnings.warn(
62 "GzipFile was opened for writing, but this will "
63 "change in future Python releases. "
64 "Specify the mode argument for opening it for writing.",
65 FutureWarning, 2)
66 self.mode = WRITE
67 self._init_write(filename)
68 self.compress = zlib.compressobj(compresslevel,
69 zlib.DEFLATED,
70 -zlib.MAX_WBITS,
71 zlib.DEF_MEM_LEVEL,
72 0)
73 self._write_mtime = mtime
74 else:
75 raise ValueError("Invalid mode: {!r}".format(mode))
76
77 self.fileobj = fileobj
78
79 if self.mode == WRITE:
80 self._write_gzip_header(compresslevel)
Path 2: 27 calls (0.07)
None (27)
None (27)
9 (27)
BytesIO (25) BufferedReader (1) BufferedRandom (1)
None (27)
1def __init__(self, filename=None, mode=None,
2 compresslevel=_COMPRESS_LEVEL_BEST, fileobj=None, mtime=None):
3 """Constructor for the GzipFile class.
4
5 At least one of fileobj and filename must be given a
6 non-trivial value.
7
8 The new class instance is based on fileobj, which can be a regular
9 file, an io.BytesIO object, or any other object which simulates a file.
10 It defaults to None, in which case filename is opened to provide
11 a file object.
12
13 When fileobj is not None, the filename argument is only used to be
14 included in the gzip file header, which may include the original
15 filename of the uncompressed file. It defaults to the filename of
16 fileobj, if discernible; otherwise, it defaults to the empty string,
17 and in this case the original filename is not included in the header.
18
19 The mode argument can be any of 'r', 'rb', 'a', 'ab', 'w', 'wb', 'x', or
20 'xb' depending on whether the file will be read or written. The default
21 is the mode of fileobj if discernible; otherwise, the default is 'rb'.
22 A mode of 'r' is equivalent to one of 'rb', and similarly for 'w' and
23 'wb', 'a' and 'ab', and 'x' and 'xb'.
24
25 The compresslevel argument is an integer from 0 to 9 controlling the
26 level of compression; 1 is fastest and produces the least compression,
27 and 9 is slowest and produces the most compression. 0 is no compression
28 at all. The default is 9.
29
30 The mtime argument is an optional numeric timestamp to be written
31 to the last modification time field in the stream when compressing.
32 If omitted or None, the current time is used.
33
34 """
35
36 if mode and ('t' in mode or 'U' in mode):
37 raise ValueError("Invalid mode: {!r}".format(mode))
38 if mode and 'b' not in mode:
39 mode += 'b'
40 if fileobj is None:
41 fileobj = self.myfileobj = builtins.open(filename, mode or 'rb')
42 if filename is None:
43 filename = getattr(fileobj, 'name', '')
44 if not isinstance(filename, (str, bytes)):
45 filename = ''
46 else:
47 filename = os.fspath(filename)
48 origmode = mode
49 if mode is None:
50 mode = getattr(fileobj, 'mode', 'rb')
51
52 if mode.startswith('r'):
53 self.mode = READ
54 raw = _GzipReader(fileobj)
55 self._buffer = io.BufferedReader(raw)
56 self.name = filename
57
58 elif mode.startswith(('w', 'a', 'x')):
59 if origmode is None:
60 import warnings
61 warnings.warn(
62 "GzipFile was opened for writing, but this will "
63 "change in future Python releases. "
64 "Specify the mode argument for opening it for writing.",
65 FutureWarning, 2)
66 self.mode = WRITE
67 self._init_write(filename)
68 self.compress = zlib.compressobj(compresslevel,
69 zlib.DEFLATED,
70 -zlib.MAX_WBITS,
71 zlib.DEF_MEM_LEVEL,
72 0)
73 self._write_mtime = mtime
74 else:
75 raise ValueError("Invalid mode: {!r}".format(mode))
76
77 self.fileobj = fileobj
78
79 if self.mode == WRITE:
80 self._write_gzip_header(compresslevel)
Path 3: 26 calls (0.07)
None (26)
'wb' (26)
9 (17) 1 (5) 6 (4)
BytesIO (25) UnseekableIO (1)
None (18) 123456789 (8)
1def __init__(self, filename=None, mode=None,
2 compresslevel=_COMPRESS_LEVEL_BEST, fileobj=None, mtime=None):
3 """Constructor for the GzipFile class.
4
5 At least one of fileobj and filename must be given a
6 non-trivial value.
7
8 The new class instance is based on fileobj, which can be a regular
9 file, an io.BytesIO object, or any other object which simulates a file.
10 It defaults to None, in which case filename is opened to provide
11 a file object.
12
13 When fileobj is not None, the filename argument is only used to be
14 included in the gzip file header, which may include the original
15 filename of the uncompressed file. It defaults to the filename of
16 fileobj, if discernible; otherwise, it defaults to the empty string,
17 and in this case the original filename is not included in the header.
18
19 The mode argument can be any of 'r', 'rb', 'a', 'ab', 'w', 'wb', 'x', or
20 'xb' depending on whether the file will be read or written. The default
21 is the mode of fileobj if discernible; otherwise, the default is 'rb'.
22 A mode of 'r' is equivalent to one of 'rb', and similarly for 'w' and
23 'wb', 'a' and 'ab', and 'x' and 'xb'.
24
25 The compresslevel argument is an integer from 0 to 9 controlling the
26 level of compression; 1 is fastest and produces the least compression,
27 and 9 is slowest and produces the most compression. 0 is no compression
28 at all. The default is 9.
29
30 The mtime argument is an optional numeric timestamp to be written
31 to the last modification time field in the stream when compressing.
32 If omitted or None, the current time is used.
33
34 """
35
36 if mode and ('t' in mode or 'U' in mode):
37 raise ValueError("Invalid mode: {!r}".format(mode))
38 if mode and 'b' not in mode:
39 mode += 'b'
40 if fileobj is None:
41 fileobj = self.myfileobj = builtins.open(filename, mode or 'rb')
42 if filename is None:
43 filename = getattr(fileobj, 'name', '')
44 if not isinstance(filename, (str, bytes)):
45 filename = ''
46 else:
47 filename = os.fspath(filename)
48 origmode = mode
49 if mode is None:
50 mode = getattr(fileobj, 'mode', 'rb')
51
52 if mode.startswith('r'):
53 self.mode = READ
54 raw = _GzipReader(fileobj)
55 self._buffer = io.BufferedReader(raw)
56 self.name = filename
57
58 elif mode.startswith(('w', 'a', 'x')):
59 if origmode is None:
60 import warnings
61 warnings.warn(
62 "GzipFile was opened for writing, but this will "
63 "change in future Python releases. "
64 "Specify the mode argument for opening it for writing.",
65 FutureWarning, 2)
66 self.mode = WRITE
67 self._init_write(filename)
68 self.compress = zlib.compressobj(compresslevel,
69 zlib.DEFLATED,
70 -zlib.MAX_WBITS,
71 zlib.DEF_MEM_LEVEL,
72 0)
73 self._write_mtime = mtime
74 else:
75 raise ValueError("Invalid mode: {!r}".format(mode))
76
77 self.fileobj = fileobj
78
79 if self.mode == WRITE:
80 self._write_gzip_header(compresslevel)
Path 4: 20 calls (0.05)
'@test_23421_tmpæ' (19) PosixPath (1)
'rb' (20)
9 (20)
None (20)
None (20)
1def __init__(self, filename=None, mode=None,
2 compresslevel=_COMPRESS_LEVEL_BEST, fileobj=None, mtime=None):
3 """Constructor for the GzipFile class.
4
5 At least one of fileobj and filename must be given a
6 non-trivial value.
7
8 The new class instance is based on fileobj, which can be a regular
9 file, an io.BytesIO object, or any other object which simulates a file.
10 It defaults to None, in which case filename is opened to provide
11 a file object.
12
13 When fileobj is not None, the filename argument is only used to be
14 included in the gzip file header, which may include the original
15 filename of the uncompressed file. It defaults to the filename of
16 fileobj, if discernible; otherwise, it defaults to the empty string,
17 and in this case the original filename is not included in the header.
18
19 The mode argument can be any of 'r', 'rb', 'a', 'ab', 'w', 'wb', 'x', or
20 'xb' depending on whether the file will be read or written. The default
21 is the mode of fileobj if discernible; otherwise, the default is 'rb'.
22 A mode of 'r' is equivalent to one of 'rb', and similarly for 'w' and
23 'wb', 'a' and 'ab', and 'x' and 'xb'.
24
25 The compresslevel argument is an integer from 0 to 9 controlling the
26 level of compression; 1 is fastest and produces the least compression,
27 and 9 is slowest and produces the most compression. 0 is no compression
28 at all. The default is 9.
29
30 The mtime argument is an optional numeric timestamp to be written
31 to the last modification time field in the stream when compressing.
32 If omitted or None, the current time is used.
33
34 """
35
36 if mode and ('t' in mode or 'U' in mode):
37 raise ValueError("Invalid mode: {!r}".format(mode))
38 if mode and 'b' not in mode:
39 mode += 'b'
40 if fileobj is None:
41 fileobj = self.myfileobj = builtins.open(filename, mode or 'rb')
42 if filename is None:
43 filename = getattr(fileobj, 'name', '')
44 if not isinstance(filename, (str, bytes)):
45 filename = ''
46 else:
47 filename = os.fspath(filename)
48 origmode = mode
49 if mode is None:
50 mode = getattr(fileobj, 'mode', 'rb')
51
52 if mode.startswith('r'):
53 self.mode = READ
54 raw = _GzipReader(fileobj)
55 self._buffer = io.BufferedReader(raw)
56 self.name = filename
57
58 elif mode.startswith(('w', 'a', 'x')):
59 if origmode is None:
60 import warnings
61 warnings.warn(
62 "GzipFile was opened for writing, but this will "
63 "change in future Python releases. "
64 "Specify the mode argument for opening it for writing.",
65 FutureWarning, 2)
66 self.mode = WRITE
67 self._init_write(filename)
68 self.compress = zlib.compressobj(compresslevel,
69 zlib.DEFLATED,
70 -zlib.MAX_WBITS,
71 zlib.DEF_MEM_LEVEL,
72 0)
73 self._write_mtime = mtime
74 else:
75 raise ValueError("Invalid mode: {!r}".format(mode))
76
77 self.fileobj = fileobj
78
79 if self.mode == WRITE:
80 self._write_gzip_header(compresslevel)
Path 5: 19 calls (0.05)
None (19)
'rb' (19)
9 (19)
BytesIO (18) UnseekableIO (1)
None (19)
1def __init__(self, filename=None, mode=None,
2 compresslevel=_COMPRESS_LEVEL_BEST, fileobj=None, mtime=None):
3 """Constructor for the GzipFile class.
4
5 At least one of fileobj and filename must be given a
6 non-trivial value.
7
8 The new class instance is based on fileobj, which can be a regular
9 file, an io.BytesIO object, or any other object which simulates a file.
10 It defaults to None, in which case filename is opened to provide
11 a file object.
12
13 When fileobj is not None, the filename argument is only used to be
14 included in the gzip file header, which may include the original
15 filename of the uncompressed file. It defaults to the filename of
16 fileobj, if discernible; otherwise, it defaults to the empty string,
17 and in this case the original filename is not included in the header.
18
19 The mode argument can be any of 'r', 'rb', 'a', 'ab', 'w', 'wb', 'x', or
20 'xb' depending on whether the file will be read or written. The default
21 is the mode of fileobj if discernible; otherwise, the default is 'rb'.
22 A mode of 'r' is equivalent to one of 'rb', and similarly for 'w' and
23 'wb', 'a' and 'ab', and 'x' and 'xb'.
24
25 The compresslevel argument is an integer from 0 to 9 controlling the
26 level of compression; 1 is fastest and produces the least compression,
27 and 9 is slowest and produces the most compression. 0 is no compression
28 at all. The default is 9.
29
30 The mtime argument is an optional numeric timestamp to be written
31 to the last modification time field in the stream when compressing.
32 If omitted or None, the current time is used.
33
34 """
35
36 if mode and ('t' in mode or 'U' in mode):
37 raise ValueError("Invalid mode: {!r}".format(mode))
38 if mode and 'b' not in mode:
39 mode += 'b'
40 if fileobj is None:
41 fileobj = self.myfileobj = builtins.open(filename, mode or 'rb')
42 if filename is None:
43 filename = getattr(fileobj, 'name', '')
44 if not isinstance(filename, (str, bytes)):
45 filename = ''
46 else:
47 filename = os.fspath(filename)
48 origmode = mode
49 if mode is None:
50 mode = getattr(fileobj, 'mode', 'rb')
51
52 if mode.startswith('r'):
53 self.mode = READ
54 raw = _GzipReader(fileobj)
55 self._buffer = io.BufferedReader(raw)
56 self.name = filename
57
58 elif mode.startswith(('w', 'a', 'x')):
59 if origmode is None:
60 import warnings
61 warnings.warn(
62 "GzipFile was opened for writing, but this will "
63 "change in future Python releases. "
64 "Specify the mode argument for opening it for writing.",
65 FutureWarning, 2)
66 self.mode = WRITE
67 self._init_write(filename)
68 self.compress = zlib.compressobj(compresslevel,
69 zlib.DEFLATED,
70 -zlib.MAX_WBITS,
71 zlib.DEF_MEM_LEVEL,
72 0)
73 self._write_mtime = mtime
74 else:
75 raise ValueError("Invalid mode: {!r}".format(mode))
76
77 self.fileobj = fileobj
78
79 if self.mode == WRITE:
80 self._write_gzip_header(compresslevel)
Path 6: 18 calls (0.05)
'@test_23421_tmpæ' (15) PosixPath (2) '@test_23421_tmp' (1)
'w' (13) 'a' (3) 'x' (2)
9 (16) 1 (1) 6 (1)
None (18)
None (15) 123456789 (3)
1def __init__(self, filename=None, mode=None,
2 compresslevel=_COMPRESS_LEVEL_BEST, fileobj=None, mtime=None):
3 """Constructor for the GzipFile class.
4
5 At least one of fileobj and filename must be given a
6 non-trivial value.
7
8 The new class instance is based on fileobj, which can be a regular
9 file, an io.BytesIO object, or any other object which simulates a file.
10 It defaults to None, in which case filename is opened to provide
11 a file object.
12
13 When fileobj is not None, the filename argument is only used to be
14 included in the gzip file header, which may include the original
15 filename of the uncompressed file. It defaults to the filename of
16 fileobj, if discernible; otherwise, it defaults to the empty string,
17 and in this case the original filename is not included in the header.
18
19 The mode argument can be any of 'r', 'rb', 'a', 'ab', 'w', 'wb', 'x', or
20 'xb' depending on whether the file will be read or written. The default
21 is the mode of fileobj if discernible; otherwise, the default is 'rb'.
22 A mode of 'r' is equivalent to one of 'rb', and similarly for 'w' and
23 'wb', 'a' and 'ab', and 'x' and 'xb'.
24
25 The compresslevel argument is an integer from 0 to 9 controlling the
26 level of compression; 1 is fastest and produces the least compression,
27 and 9 is slowest and produces the most compression. 0 is no compression
28 at all. The default is 9.
29
30 The mtime argument is an optional numeric timestamp to be written
31 to the last modification time field in the stream when compressing.
32 If omitted or None, the current time is used.
33
34 """
35
36 if mode and ('t' in mode or 'U' in mode):
37 raise ValueError("Invalid mode: {!r}".format(mode))
38 if mode and 'b' not in mode:
39 mode += 'b'
40 if fileobj is None:
41 fileobj = self.myfileobj = builtins.open(filename, mode or 'rb')
42 if filename is None:
43 filename = getattr(fileobj, 'name', '')
44 if not isinstance(filename, (str, bytes)):
45 filename = ''
46 else:
47 filename = os.fspath(filename)
48 origmode = mode
49 if mode is None:
50 mode = getattr(fileobj, 'mode', 'rb')
51
52 if mode.startswith('r'):
53 self.mode = READ
54 raw = _GzipReader(fileobj)
55 self._buffer = io.BufferedReader(raw)
56 self.name = filename
57
58 elif mode.startswith(('w', 'a', 'x')):
59 if origmode is None:
60 import warnings
61 warnings.warn(
62 "GzipFile was opened for writing, but this will "
63 "change in future Python releases. "
64 "Specify the mode argument for opening it for writing.",
65 FutureWarning, 2)
66 self.mode = WRITE
67 self._init_write(filename)
68 self.compress = zlib.compressobj(compresslevel,
69 zlib.DEFLATED,
70 -zlib.MAX_WBITS,
71 zlib.DEF_MEM_LEVEL,
72 0)
73 self._write_mtime = mtime
74 else:
75 raise ValueError("Invalid mode: {!r}".format(mode))
76
77 self.fileobj = fileobj
78
79 if self.mode == WRITE:
80 self._write_gzip_header(compresslevel)
Path 7: 11 calls (0.03)
'@test_23421_tmpæ' (11)
'r' (11)
9 (11)
None (11)
None (11)
1def __init__(self, filename=None, mode=None,
2 compresslevel=_COMPRESS_LEVEL_BEST, fileobj=None, mtime=None):
3 """Constructor for the GzipFile class.
4
5 At least one of fileobj and filename must be given a
6 non-trivial value.
7
8 The new class instance is based on fileobj, which can be a regular
9 file, an io.BytesIO object, or any other object which simulates a file.
10 It defaults to None, in which case filename is opened to provide
11 a file object.
12
13 When fileobj is not None, the filename argument is only used to be
14 included in the gzip file header, which may include the original
15 filename of the uncompressed file. It defaults to the filename of
16 fileobj, if discernible; otherwise, it defaults to the empty string,
17 and in this case the original filename is not included in the header.
18
19 The mode argument can be any of 'r', 'rb', 'a', 'ab', 'w', 'wb', 'x', or
20 'xb' depending on whether the file will be read or written. The default
21 is the mode of fileobj if discernible; otherwise, the default is 'rb'.
22 A mode of 'r' is equivalent to one of 'rb', and similarly for 'w' and
23 'wb', 'a' and 'ab', and 'x' and 'xb'.
24
25 The compresslevel argument is an integer from 0 to 9 controlling the
26 level of compression; 1 is fastest and produces the least compression,
27 and 9 is slowest and produces the most compression. 0 is no compression
28 at all. The default is 9.
29
30 The mtime argument is an optional numeric timestamp to be written
31 to the last modification time field in the stream when compressing.
32 If omitted or None, the current time is used.
33
34 """
35
36 if mode and ('t' in mode or 'U' in mode):
37 raise ValueError("Invalid mode: {!r}".format(mode))
38 if mode and 'b' not in mode:
39 mode += 'b'
40 if fileobj is None:
41 fileobj = self.myfileobj = builtins.open(filename, mode or 'rb')
42 if filename is None:
43 filename = getattr(fileobj, 'name', '')
44 if not isinstance(filename, (str, bytes)):
45 filename = ''
46 else:
47 filename = os.fspath(filename)
48 origmode = mode
49 if mode is None:
50 mode = getattr(fileobj, 'mode', 'rb')
51
52 if mode.startswith('r'):
53 self.mode = READ
54 raw = _GzipReader(fileobj)
55 self._buffer = io.BufferedReader(raw)
56 self.name = filename
57
58 elif mode.startswith(('w', 'a', 'x')):
59 if origmode is None:
60 import warnings
61 warnings.warn(
62 "GzipFile was opened for writing, but this will "
63 "change in future Python releases. "
64 "Specify the mode argument for opening it for writing.",
65 FutureWarning, 2)
66 self.mode = WRITE
67 self._init_write(filename)
68 self.compress = zlib.compressobj(compresslevel,
69 zlib.DEFLATED,
70 -zlib.MAX_WBITS,
71 zlib.DEF_MEM_LEVEL,
72 0)
73 self._write_mtime = mtime
74 else:
75 raise ValueError("Invalid mode: {!r}".format(mode))
76
77 self.fileobj = fileobj
78
79 if self.mode == WRITE:
80 self._write_gzip_header(compresslevel)
Path 8: 4 calls (0.01)
None (4)
'w' (2) 'a' (1) 'x' (1)
9 (4)
BufferedRandom (3) BytesIO (1)
None (4)
1def __init__(self, filename=None, mode=None,
2 compresslevel=_COMPRESS_LEVEL_BEST, fileobj=None, mtime=None):
3 """Constructor for the GzipFile class.
4
5 At least one of fileobj and filename must be given a
6 non-trivial value.
7
8 The new class instance is based on fileobj, which can be a regular
9 file, an io.BytesIO object, or any other object which simulates a file.
10 It defaults to None, in which case filename is opened to provide
11 a file object.
12
13 When fileobj is not None, the filename argument is only used to be
14 included in the gzip file header, which may include the original
15 filename of the uncompressed file. It defaults to the filename of
16 fileobj, if discernible; otherwise, it defaults to the empty string,
17 and in this case the original filename is not included in the header.
18
19 The mode argument can be any of 'r', 'rb', 'a', 'ab', 'w', 'wb', 'x', or
20 'xb' depending on whether the file will be read or written. The default
21 is the mode of fileobj if discernible; otherwise, the default is 'rb'.
22 A mode of 'r' is equivalent to one of 'rb', and similarly for 'w' and
23 'wb', 'a' and 'ab', and 'x' and 'xb'.
24
25 The compresslevel argument is an integer from 0 to 9 controlling the
26 level of compression; 1 is fastest and produces the least compression,
27 and 9 is slowest and produces the most compression. 0 is no compression
28 at all. The default is 9.
29
30 The mtime argument is an optional numeric timestamp to be written
31 to the last modification time field in the stream when compressing.
32 If omitted or None, the current time is used.
33
34 """
35
36 if mode and ('t' in mode or 'U' in mode):
37 raise ValueError("Invalid mode: {!r}".format(mode))
38 if mode and 'b' not in mode:
39 mode += 'b'
40 if fileobj is None:
41 fileobj = self.myfileobj = builtins.open(filename, mode or 'rb')
42 if filename is None:
43 filename = getattr(fileobj, 'name', '')
44 if not isinstance(filename, (str, bytes)):
45 filename = ''
46 else:
47 filename = os.fspath(filename)
48 origmode = mode
49 if mode is None:
50 mode = getattr(fileobj, 'mode', 'rb')
51
52 if mode.startswith('r'):
53 self.mode = READ
54 raw = _GzipReader(fileobj)
55 self._buffer = io.BufferedReader(raw)
56 self.name = filename
57
58 elif mode.startswith(('w', 'a', 'x')):
59 if origmode is None:
60 import warnings
61 warnings.warn(
62 "GzipFile was opened for writing, but this will "
63 "change in future Python releases. "
64 "Specify the mode argument for opening it for writing.",
65 FutureWarning, 2)
66 self.mode = WRITE
67 self._init_write(filename)
68 self.compress = zlib.compressobj(compresslevel,
69 zlib.DEFLATED,
70 -zlib.MAX_WBITS,
71 zlib.DEF_MEM_LEVEL,
72 0)
73 self._write_mtime = mtime
74 else:
75 raise ValueError("Invalid mode: {!r}".format(mode))
76
77 self.fileobj = fileobj
78
79 if self.mode == WRITE:
80 self._write_gzip_header(compresslevel)
Path 9: 4 calls (0.01)
'@test_23421_tmpæ' (3) PosixPath (1)
None (4)
9 (4)
None (4)
None (4)
1def __init__(self, filename=None, mode=None,
2 compresslevel=_COMPRESS_LEVEL_BEST, fileobj=None, mtime=None):
3 """Constructor for the GzipFile class.
4
5 At least one of fileobj and filename must be given a
6 non-trivial value.
7
8 The new class instance is based on fileobj, which can be a regular
9 file, an io.BytesIO object, or any other object which simulates a file.
10 It defaults to None, in which case filename is opened to provide
11 a file object.
12
13 When fileobj is not None, the filename argument is only used to be
14 included in the gzip file header, which may include the original
15 filename of the uncompressed file. It defaults to the filename of
16 fileobj, if discernible; otherwise, it defaults to the empty string,
17 and in this case the original filename is not included in the header.
18
19 The mode argument can be any of 'r', 'rb', 'a', 'ab', 'w', 'wb', 'x', or
20 'xb' depending on whether the file will be read or written. The default
21 is the mode of fileobj if discernible; otherwise, the default is 'rb'.
22 A mode of 'r' is equivalent to one of 'rb', and similarly for 'w' and
23 'wb', 'a' and 'ab', and 'x' and 'xb'.
24
25 The compresslevel argument is an integer from 0 to 9 controlling the
26 level of compression; 1 is fastest and produces the least compression,
27 and 9 is slowest and produces the most compression. 0 is no compression
28 at all. The default is 9.
29
30 The mtime argument is an optional numeric timestamp to be written
31 to the last modification time field in the stream when compressing.
32 If omitted or None, the current time is used.
33
34 """
35
36 if mode and ('t' in mode or 'U' in mode):
37 raise ValueError("Invalid mode: {!r}".format(mode))
38 if mode and 'b' not in mode:
39 mode += 'b'
40 if fileobj is None:
41 fileobj = self.myfileobj = builtins.open(filename, mode or 'rb')
42 if filename is None:
43 filename = getattr(fileobj, 'name', '')
44 if not isinstance(filename, (str, bytes)):
45 filename = ''
46 else:
47 filename = os.fspath(filename)
48 origmode = mode
49 if mode is None:
50 mode = getattr(fileobj, 'mode', 'rb')
51
52 if mode.startswith('r'):
53 self.mode = READ
54 raw = _GzipReader(fileobj)
55 self._buffer = io.BufferedReader(raw)
56 self.name = filename
57
58 elif mode.startswith(('w', 'a', 'x')):
59 if origmode is None:
60 import warnings
61 warnings.warn(
62 "GzipFile was opened for writing, but this will "
63 "change in future Python releases. "
64 "Specify the mode argument for opening it for writing.",
65 FutureWarning, 2)
66 self.mode = WRITE
67 self._init_write(filename)
68 self.compress = zlib.compressobj(compresslevel,
69 zlib.DEFLATED,
70 -zlib.MAX_WBITS,
71 zlib.DEF_MEM_LEVEL,
72 0)
73 self._write_mtime = mtime
74 else:
75 raise ValueError("Invalid mode: {!r}".format(mode))
76
77 self.fileobj = fileobj
78
79 if self.mode == WRITE:
80 self._write_gzip_header(compresslevel)
Path 10: 3 calls (0.01)
None (3)
'r' (3)
9 (3)
BytesIO (2) BufferedRandom (1)
None (3)
1def __init__(self, filename=None, mode=None,
2 compresslevel=_COMPRESS_LEVEL_BEST, fileobj=None, mtime=None):
3 """Constructor for the GzipFile class.
4
5 At least one of fileobj and filename must be given a
6 non-trivial value.
7
8 The new class instance is based on fileobj, which can be a regular
9 file, an io.BytesIO object, or any other object which simulates a file.
10 It defaults to None, in which case filename is opened to provide
11 a file object.
12
13 When fileobj is not None, the filename argument is only used to be
14 included in the gzip file header, which may include the original
15 filename of the uncompressed file. It defaults to the filename of
16 fileobj, if discernible; otherwise, it defaults to the empty string,
17 and in this case the original filename is not included in the header.
18
19 The mode argument can be any of 'r', 'rb', 'a', 'ab', 'w', 'wb', 'x', or
20 'xb' depending on whether the file will be read or written. The default
21 is the mode of fileobj if discernible; otherwise, the default is 'rb'.
22 A mode of 'r' is equivalent to one of 'rb', and similarly for 'w' and
23 'wb', 'a' and 'ab', and 'x' and 'xb'.
24
25 The compresslevel argument is an integer from 0 to 9 controlling the
26 level of compression; 1 is fastest and produces the least compression,
27 and 9 is slowest and produces the most compression. 0 is no compression
28 at all. The default is 9.
29
30 The mtime argument is an optional numeric timestamp to be written
31 to the last modification time field in the stream when compressing.
32 If omitted or None, the current time is used.
33
34 """
35
36 if mode and ('t' in mode or 'U' in mode):
37 raise ValueError("Invalid mode: {!r}".format(mode))
38 if mode and 'b' not in mode:
39 mode += 'b'
40 if fileobj is None:
41 fileobj = self.myfileobj = builtins.open(filename, mode or 'rb')
42 if filename is None:
43 filename = getattr(fileobj, 'name', '')
44 if not isinstance(filename, (str, bytes)):
45 filename = ''
46 else:
47 filename = os.fspath(filename)
48 origmode = mode
49 if mode is None:
50 mode = getattr(fileobj, 'mode', 'rb')
51
52 if mode.startswith('r'):
53 self.mode = READ
54 raw = _GzipReader(fileobj)
55 self._buffer = io.BufferedReader(raw)
56 self.name = filename
57
58 elif mode.startswith(('w', 'a', 'x')):
59 if origmode is None:
60 import warnings
61 warnings.warn(
62 "GzipFile was opened for writing, but this will "
63 "change in future Python releases. "
64 "Specify the mode argument for opening it for writing.",
65 FutureWarning, 2)
66 self.mode = WRITE
67 self._init_write(filename)
68 self.compress = zlib.compressobj(compresslevel,
69 zlib.DEFLATED,
70 -zlib.MAX_WBITS,
71 zlib.DEF_MEM_LEVEL,
72 0)
73 self._write_mtime = mtime
74 else:
75 raise ValueError("Invalid mode: {!r}".format(mode))
76
77 self.fileobj = fileobj
78
79 if self.mode == WRITE:
80 self._write_gzip_header(compresslevel)
Path 11: 3 calls (0.01)
None (3)
None (3)
9 (3)
BufferedWriter (3)
None (3)
1def __init__(self, filename=None, mode=None,
2 compresslevel=_COMPRESS_LEVEL_BEST, fileobj=None, mtime=None):
3 """Constructor for the GzipFile class.
4
5 At least one of fileobj and filename must be given a
6 non-trivial value.
7
8 The new class instance is based on fileobj, which can be a regular
9 file, an io.BytesIO object, or any other object which simulates a file.
10 It defaults to None, in which case filename is opened to provide
11 a file object.
12
13 When fileobj is not None, the filename argument is only used to be
14 included in the gzip file header, which may include the original
15 filename of the uncompressed file. It defaults to the filename of
16 fileobj, if discernible; otherwise, it defaults to the empty string,
17 and in this case the original filename is not included in the header.
18
19 The mode argument can be any of 'r', 'rb', 'a', 'ab', 'w', 'wb', 'x', or
20 'xb' depending on whether the file will be read or written. The default
21 is the mode of fileobj if discernible; otherwise, the default is 'rb'.
22 A mode of 'r' is equivalent to one of 'rb', and similarly for 'w' and
23 'wb', 'a' and 'ab', and 'x' and 'xb'.
24
25 The compresslevel argument is an integer from 0 to 9 controlling the
26 level of compression; 1 is fastest and produces the least compression,
27 and 9 is slowest and produces the most compression. 0 is no compression
28 at all. The default is 9.
29
30 The mtime argument is an optional numeric timestamp to be written
31 to the last modification time field in the stream when compressing.
32 If omitted or None, the current time is used.
33
34 """
35
36 if mode and ('t' in mode or 'U' in mode):
37 raise ValueError("Invalid mode: {!r}".format(mode))
38 if mode and 'b' not in mode:
39 mode += 'b'
40 if fileobj is None:
41 fileobj = self.myfileobj = builtins.open(filename, mode or 'rb')
42 if filename is None:
43 filename = getattr(fileobj, 'name', '')
44 if not isinstance(filename, (str, bytes)):
45 filename = ''
46 else:
47 filename = os.fspath(filename)
48 origmode = mode
49 if mode is None:
50 mode = getattr(fileobj, 'mode', 'rb')
51
52 if mode.startswith('r'):
53 self.mode = READ
54 raw = _GzipReader(fileobj)
55 self._buffer = io.BufferedReader(raw)
56 self.name = filename
57
58 elif mode.startswith(('w', 'a', 'x')):
59 if origmode is None:
60 import warnings
61 warnings.warn(
62 "GzipFile was opened for writing, but this will "
63 "change in future Python releases. "
64 "Specify the mode argument for opening it for writing.",
65 FutureWarning, 2)
66 self.mode = WRITE
67 self._init_write(filename)
68 self.compress = zlib.compressobj(compresslevel,
69 zlib.DEFLATED,
70 -zlib.MAX_WBITS,
71 zlib.DEF_MEM_LEVEL,
72 0)
73 self._write_mtime = mtime
74 else:
75 raise ValueError("Invalid mode: {!r}".format(mode))
76
77 self.fileobj = fileobj
78
79 if self.mode == WRITE:
80 self._write_gzip_header(compresslevel)
Path 12: 2 calls (0.01)
'@test_23421_tmpæ' (2)
'xb' (2)
9 (2)
None (2)
None (2)
FileExistsError (2)
1def __init__(self, filename=None, mode=None,
2 compresslevel=_COMPRESS_LEVEL_BEST, fileobj=None, mtime=None):
3 """Constructor for the GzipFile class.
4
5 At least one of fileobj and filename must be given a
6 non-trivial value.
7
8 The new class instance is based on fileobj, which can be a regular
9 file, an io.BytesIO object, or any other object which simulates a file.
10 It defaults to None, in which case filename is opened to provide
11 a file object.
12
13 When fileobj is not None, the filename argument is only used to be
14 included in the gzip file header, which may include the original
15 filename of the uncompressed file. It defaults to the filename of
16 fileobj, if discernible; otherwise, it defaults to the empty string,
17 and in this case the original filename is not included in the header.
18
19 The mode argument can be any of 'r', 'rb', 'a', 'ab', 'w', 'wb', 'x', or
20 'xb' depending on whether the file will be read or written. The default
21 is the mode of fileobj if discernible; otherwise, the default is 'rb'.
22 A mode of 'r' is equivalent to one of 'rb', and similarly for 'w' and
23 'wb', 'a' and 'ab', and 'x' and 'xb'.
24
25 The compresslevel argument is an integer from 0 to 9 controlling the
26 level of compression; 1 is fastest and produces the least compression,
27 and 9 is slowest and produces the most compression. 0 is no compression
28 at all. The default is 9.
29
30 The mtime argument is an optional numeric timestamp to be written
31 to the last modification time field in the stream when compressing.
32 If omitted or None, the current time is used.
33
34 """
35
36 if mode and ('t' in mode or 'U' in mode):
37 raise ValueError("Invalid mode: {!r}".format(mode))
38 if mode and 'b' not in mode:
39 mode += 'b'
40 if fileobj is None:
41 fileobj = self.myfileobj = builtins.open(filename, mode or 'rb')
42 if filename is None:
43 filename = getattr(fileobj, 'name', '')
44 if not isinstance(filename, (str, bytes)):
45 filename = ''
46 else:
47 filename = os.fspath(filename)
48 origmode = mode
49 if mode is None:
50 mode = getattr(fileobj, 'mode', 'rb')
51
52 if mode.startswith('r'):
53 self.mode = READ
54 raw = _GzipReader(fileobj)
55 self._buffer = io.BufferedReader(raw)
56 self.name = filename
57
58 elif mode.startswith(('w', 'a', 'x')):
59 if origmode is None:
60 import warnings
61 warnings.warn(
62 "GzipFile was opened for writing, but this will "
63 "change in future Python releases. "
64 "Specify the mode argument for opening it for writing.",
65 FutureWarning, 2)
66 self.mode = WRITE
67 self._init_write(filename)
68 self.compress = zlib.compressobj(compresslevel,
69 zlib.DEFLATED,
70 -zlib.MAX_WBITS,
71 zlib.DEF_MEM_LEVEL,
72 0)
73 self._write_mtime = mtime
74 else:
75 raise ValueError("Invalid mode: {!r}".format(mode))
76
77 self.fileobj = fileobj
78
79 if self.mode == WRITE:
80 self._write_gzip_header(compresslevel)
Path 13: 1 calls (0.0)
None (1)
'w' (1)
9 (1)
BufferedWriter (1)
None (1)
1def __init__(self, filename=None, mode=None,
2 compresslevel=_COMPRESS_LEVEL_BEST, fileobj=None, mtime=None):
3 """Constructor for the GzipFile class.
4
5 At least one of fileobj and filename must be given a
6 non-trivial value.
7
8 The new class instance is based on fileobj, which can be a regular
9 file, an io.BytesIO object, or any other object which simulates a file.
10 It defaults to None, in which case filename is opened to provide
11 a file object.
12
13 When fileobj is not None, the filename argument is only used to be
14 included in the gzip file header, which may include the original
15 filename of the uncompressed file. It defaults to the filename of
16 fileobj, if discernible; otherwise, it defaults to the empty string,
17 and in this case the original filename is not included in the header.
18
19 The mode argument can be any of 'r', 'rb', 'a', 'ab', 'w', 'wb', 'x', or
20 'xb' depending on whether the file will be read or written. The default
21 is the mode of fileobj if discernible; otherwise, the default is 'rb'.
22 A mode of 'r' is equivalent to one of 'rb', and similarly for 'w' and
23 'wb', 'a' and 'ab', and 'x' and 'xb'.
24
25 The compresslevel argument is an integer from 0 to 9 controlling the
26 level of compression; 1 is fastest and produces the least compression,
27 and 9 is slowest and produces the most compression. 0 is no compression
28 at all. The default is 9.
29
30 The mtime argument is an optional numeric timestamp to be written
31 to the last modification time field in the stream when compressing.
32 If omitted or None, the current time is used.
33
34 """
35
36 if mode and ('t' in mode or 'U' in mode):
37 raise ValueError("Invalid mode: {!r}".format(mode))
38 if mode and 'b' not in mode:
39 mode += 'b'
40 if fileobj is None:
41 fileobj = self.myfileobj = builtins.open(filename, mode or 'rb')
42 if filename is None:
43 filename = getattr(fileobj, 'name', '')
44 if not isinstance(filename, (str, bytes)):
45 filename = ''
46 else:
47 filename = os.fspath(filename)
48 origmode = mode
49 if mode is None:
50 mode = getattr(fileobj, 'mode', 'rb')
51
52 if mode.startswith('r'):
53 self.mode = READ
54 raw = _GzipReader(fileobj)
55 self._buffer = io.BufferedReader(raw)
56 self.name = filename
57
58 elif mode.startswith(('w', 'a', 'x')):
59 if origmode is None:
60 import warnings
61 warnings.warn(
62 "GzipFile was opened for writing, but this will "
63 "change in future Python releases. "
64 "Specify the mode argument for opening it for writing.",
65 FutureWarning, 2)
66 self.mode = WRITE
67 self._init_write(filename)
68 self.compress = zlib.compressobj(compresslevel,
69 zlib.DEFLATED,
70 -zlib.MAX_WBITS,
71 zlib.DEF_MEM_LEVEL,
72 0)
73 self._write_mtime = mtime
74 else:
75 raise ValueError("Invalid mode: {!r}".format(mode))
76
77 self.fileobj = fileobj
78
79 if self.mode == WRITE:
80 self._write_gzip_header(compresslevel)
Path 14: 1 calls (0.0)
None (1)
'z' (1)
9 (1)
BufferedRandom (1)
None (1)
ValueError (1)
1def __init__(self, filename=None, mode=None,
2 compresslevel=_COMPRESS_LEVEL_BEST, fileobj=None, mtime=None):
3 """Constructor for the GzipFile class.
4
5 At least one of fileobj and filename must be given a
6 non-trivial value.
7
8 The new class instance is based on fileobj, which can be a regular
9 file, an io.BytesIO object, or any other object which simulates a file.
10 It defaults to None, in which case filename is opened to provide
11 a file object.
12
13 When fileobj is not None, the filename argument is only used to be
14 included in the gzip file header, which may include the original
15 filename of the uncompressed file. It defaults to the filename of
16 fileobj, if discernible; otherwise, it defaults to the empty string,
17 and in this case the original filename is not included in the header.
18
19 The mode argument can be any of 'r', 'rb', 'a', 'ab', 'w', 'wb', 'x', or
20 'xb' depending on whether the file will be read or written. The default
21 is the mode of fileobj if discernible; otherwise, the default is 'rb'.
22 A mode of 'r' is equivalent to one of 'rb', and similarly for 'w' and
23 'wb', 'a' and 'ab', and 'x' and 'xb'.
24
25 The compresslevel argument is an integer from 0 to 9 controlling the
26 level of compression; 1 is fastest and produces the least compression,
27 and 9 is slowest and produces the most compression. 0 is no compression
28 at all. The default is 9.
29
30 The mtime argument is an optional numeric timestamp to be written
31 to the last modification time field in the stream when compressing.
32 If omitted or None, the current time is used.
33
34 """
35
36 if mode and ('t' in mode or 'U' in mode):
37 raise ValueError("Invalid mode: {!r}".format(mode))
38 if mode and 'b' not in mode:
39 mode += 'b'
40 if fileobj is None:
41 fileobj = self.myfileobj = builtins.open(filename, mode or 'rb')
42 if filename is None:
43 filename = getattr(fileobj, 'name', '')
44 if not isinstance(filename, (str, bytes)):
45 filename = ''
46 else:
47 filename = os.fspath(filename)
48 origmode = mode
49 if mode is None:
50 mode = getattr(fileobj, 'mode', 'rb')
51
52 if mode.startswith('r'):
53 self.mode = READ
54 raw = _GzipReader(fileobj)
55 self._buffer = io.BufferedReader(raw)
56 self.name = filename
57
58 elif mode.startswith(('w', 'a', 'x')):
59 if origmode is None:
60 import warnings
61 warnings.warn(
62 "GzipFile was opened for writing, but this will "
63 "change in future Python releases. "
64 "Specify the mode argument for opening it for writing.",
65 FutureWarning, 2)
66 self.mode = WRITE
67 self._init_write(filename)
68 self.compress = zlib.compressobj(compresslevel,
69 zlib.DEFLATED,
70 -zlib.MAX_WBITS,
71 zlib.DEF_MEM_LEVEL,
72 0)
73 self._write_mtime = mtime
74 else:
75 raise ValueError("Invalid mode: {!r}".format(mode))
76
77 self.fileobj = fileobj
78
79 if self.mode == WRITE:
80 self._write_gzip_header(compresslevel)
Path 15: 1 calls (0.0)
'@test_23421_tmpæ' (1)
'x' (1)
9 (1)
None (1)
None (1)
FileExistsError (1)
1def __init__(self, filename=None, mode=None,
2 compresslevel=_COMPRESS_LEVEL_BEST, fileobj=None, mtime=None):
3 """Constructor for the GzipFile class.
4
5 At least one of fileobj and filename must be given a
6 non-trivial value.
7
8 The new class instance is based on fileobj, which can be a regular
9 file, an io.BytesIO object, or any other object which simulates a file.
10 It defaults to None, in which case filename is opened to provide
11 a file object.
12
13 When fileobj is not None, the filename argument is only used to be
14 included in the gzip file header, which may include the original
15 filename of the uncompressed file. It defaults to the filename of
16 fileobj, if discernible; otherwise, it defaults to the empty string,
17 and in this case the original filename is not included in the header.
18
19 The mode argument can be any of 'r', 'rb', 'a', 'ab', 'w', 'wb', 'x', or
20 'xb' depending on whether the file will be read or written. The default
21 is the mode of fileobj if discernible; otherwise, the default is 'rb'.
22 A mode of 'r' is equivalent to one of 'rb', and similarly for 'w' and
23 'wb', 'a' and 'ab', and 'x' and 'xb'.
24
25 The compresslevel argument is an integer from 0 to 9 controlling the
26 level of compression; 1 is fastest and produces the least compression,
27 and 9 is slowest and produces the most compression. 0 is no compression
28 at all. The default is 9.
29
30 The mtime argument is an optional numeric timestamp to be written
31 to the last modification time field in the stream when compressing.
32 If omitted or None, the current time is used.
33
34 """
35
36 if mode and ('t' in mode or 'U' in mode):
37 raise ValueError("Invalid mode: {!r}".format(mode))
38 if mode and 'b' not in mode:
39 mode += 'b'
40 if fileobj is None:
41 fileobj = self.myfileobj = builtins.open(filename, mode or 'rb')
42 if filename is None:
43 filename = getattr(fileobj, 'name', '')
44 if not isinstance(filename, (str, bytes)):
45 filename = ''
46 else:
47 filename = os.fspath(filename)
48 origmode = mode
49 if mode is None:
50 mode = getattr(fileobj, 'mode', 'rb')
51
52 if mode.startswith('r'):
53 self.mode = READ
54 raw = _GzipReader(fileobj)
55 self._buffer = io.BufferedReader(raw)
56 self.name = filename
57
58 elif mode.startswith(('w', 'a', 'x')):
59 if origmode is None:
60 import warnings
61 warnings.warn(
62 "GzipFile was opened for writing, but this will "
63 "change in future Python releases. "
64 "Specify the mode argument for opening it for writing.",
65 FutureWarning, 2)
66 self.mode = WRITE
67 self._init_write(filename)
68 self.compress = zlib.compressobj(compresslevel,
69 zlib.DEFLATED,
70 -zlib.MAX_WBITS,
71 zlib.DEF_MEM_LEVEL,
72 0)
73 self._write_mtime = mtime
74 else:
75 raise ValueError("Invalid mode: {!r}".format(mode))
76
77 self.fileobj = fileobj
78
79 if self.mode == WRITE:
80 self._write_gzip_header(compresslevel)