LEFT | RIGHT |
1 # -*- coding: utf-8 -*- | 1 # -*- coding: utf-8 -*- |
2 """The gzip file entry implementation.""" | 2 """The gzip file entry implementation.""" |
| 3 |
| 4 from __future__ import unicode_literals |
3 | 5 |
4 from dfdatetime import posix_time as dfdatetime_posix_time | 6 from dfdatetime import posix_time as dfdatetime_posix_time |
5 | 7 |
6 from dfvfs.lib import definitions | 8 from dfvfs.lib import definitions |
7 from dfvfs.lib import errors | 9 from dfvfs.lib import errors |
8 from dfvfs.resolver import resolver | 10 from dfvfs.resolver import resolver |
9 from dfvfs.vfs import root_only_file_entry | 11 from dfvfs.vfs import root_only_file_entry |
10 | 12 |
11 | 13 |
12 class GzipFileEntry(root_only_file_entry.RootOnlyFileEntry): | 14 class GzipFileEntry(root_only_file_entry.RootOnlyFileEntry): |
(...skipping 13 matching lines...) Expand all Loading... |
26 is_root (Optional[bool]): True if the file entry is the root file entry | 28 is_root (Optional[bool]): True if the file entry is the root file entry |
27 of the corresponding file system. | 29 of the corresponding file system. |
28 is_virtual (Optional[bool]): True if the file entry is a virtual file | 30 is_virtual (Optional[bool]): True if the file entry is a virtual file |
29 | 31 |
30 Raises: | 32 Raises: |
31 BackEndError: when the gzip file is missing. | 33 BackEndError: when the gzip file is missing. |
32 """ | 34 """ |
33 gzip_file = resolver.Resolver.OpenFileObject( | 35 gzip_file = resolver.Resolver.OpenFileObject( |
34 path_spec, resolver_context=resolver_context) | 36 path_spec, resolver_context=resolver_context) |
35 if not gzip_file: | 37 if not gzip_file: |
36 raise errors.BackEndError(u'Missing gzip file.') | 38 raise errors.BackEndError('Missing gzip file.') |
37 | 39 |
38 super(GzipFileEntry, self).__init__( | 40 super(GzipFileEntry, self).__init__( |
39 resolver_context, file_system, path_spec, is_root=is_root, | 41 resolver_context, file_system, path_spec, is_root=is_root, |
40 is_virtual=is_virtual) | 42 is_virtual=is_virtual) |
41 self._gzip_file = gzip_file | 43 self._gzip_file = gzip_file |
42 self._type = definitions.FILE_ENTRY_TYPE_FILE | 44 self._type = definitions.FILE_ENTRY_TYPE_FILE |
43 | 45 |
44 def __del__(self): | 46 def __del__(self): |
45 """Cleans up the file entry.""" | 47 """Cleans up the file entry.""" |
46 # __del__ can be invoked before __init__ has completed. | 48 # __del__ can be invoked before __init__ has completed. |
47 if hasattr(self, u'_gzip_file'): | 49 if hasattr(self, '_gzip_file'): |
48 self._gzip_file.close() | 50 self._gzip_file.close() |
49 self._gzip_file = None | 51 self._gzip_file = None |
50 | 52 |
51 super(GzipFileEntry, self).__del__() | 53 super(GzipFileEntry, self).__del__() |
52 | 54 |
53 def _GetStat(self): | 55 def _GetStat(self): |
54 """Retrieves information about the file entry. | 56 """Retrieves information about the file entry. |
55 | 57 |
56 Returns: | 58 Returns: |
57 VFSStat: a stat object. | 59 VFSStat: a stat object. |
58 """ | 60 """ |
59 stat_object = super(GzipFileEntry, self)._GetStat() | 61 stat_object = super(GzipFileEntry, self)._GetStat() |
60 | 62 |
61 if self._gzip_file: | 63 if self._gzip_file: |
62 stat_object.size = self._gzip_file.uncompressed_data_size | 64 stat_object.size = self._gzip_file.uncompressed_data_size |
63 | 65 |
64 # Other stat information. | 66 # Other stat information. |
65 # gzip_file.comment | 67 # gzip_file.comment |
66 # gzip_file.operating_system | 68 # gzip_file.operating_system |
67 # gzip_file.original_filename | 69 # gzip_file.original_filename |
68 | 70 |
69 return stat_object | 71 return stat_object |
70 | 72 |
71 @property | 73 @property |
72 def modification_time(self): | 74 def modification_time(self): |
73 """dfdatetime.DateTimeValues: modification time or None if not available.""" | 75 """dfdatetime.DateTimeValues: modification time or None if not available.""" |
74 timestamp = getattr(self._gzip_file, u'modification_time', None) | 76 timestamp = getattr(self._gzip_file, 'modification_time', None) |
75 if timestamp is not None: | 77 if timestamp is not None: |
76 return dfdatetime_posix_time.PosixTime(timestamp=timestamp) | 78 return dfdatetime_posix_time.PosixTime(timestamp=timestamp) |
LEFT | RIGHT |