LEFT | RIGHT |
1 # -*- coding: utf-8 -*- | 1 # -*- coding: utf-8 -*- |
2 """The encoded stream file entry implementation.""" | 2 """The encoded stream file entry implementation.""" |
| 3 |
| 4 from __future__ import unicode_literals |
3 | 5 |
4 from dfvfs.lib import definitions | 6 from dfvfs.lib import definitions |
5 from dfvfs.lib import errors | 7 from dfvfs.lib import errors |
6 from dfvfs.resolver import resolver | 8 from dfvfs.resolver import resolver |
7 from dfvfs.vfs import root_only_file_entry | 9 from dfvfs.vfs import root_only_file_entry |
8 from dfvfs.vfs import vfs_stat | 10 from dfvfs.vfs import vfs_stat |
9 | 11 |
10 | 12 |
11 class EncodedStreamFileEntry(root_only_file_entry.RootOnlyFileEntry): | 13 class EncodedStreamFileEntry(root_only_file_entry.RootOnlyFileEntry): |
12 """Class that implements an encoded stream file entry object.""" | 14 """Class that implements an encoded stream file entry object.""" |
(...skipping 12 matching lines...) Expand all Loading... |
25 is_root (Optional[bool]): True if the file entry is the root file entry | 27 is_root (Optional[bool]): True if the file entry is the root file entry |
26 of the corresponding file system. | 28 of the corresponding file system. |
27 is_virtual (Optional[bool]): True if the file entry is a virtual file | 29 is_virtual (Optional[bool]): True if the file entry is a virtual file |
28 | 30 |
29 Raises: | 31 Raises: |
30 BackEndError: when the encoded stream is missing. | 32 BackEndError: when the encoded stream is missing. |
31 """ | 33 """ |
32 encoded_stream = resolver.Resolver.OpenFileObject( | 34 encoded_stream = resolver.Resolver.OpenFileObject( |
33 path_spec, resolver_context=resolver_context) | 35 path_spec, resolver_context=resolver_context) |
34 if not encoded_stream: | 36 if not encoded_stream: |
35 raise errors.BackEndError(u'Missing encoded stream.') | 37 raise errors.BackEndError( |
| 38 'Unable to open encoded stream: {0:s}.'.format( |
| 39 self.path_spec.comparable)) |
36 | 40 |
37 super(EncodedStreamFileEntry, self).__init__( | 41 super(EncodedStreamFileEntry, self).__init__( |
38 resolver_context, file_system, path_spec, is_root=is_root, | 42 resolver_context, file_system, path_spec, is_root=is_root, |
39 is_virtual=is_virtual) | 43 is_virtual=is_virtual) |
40 self._encoded_stream = encoded_stream | 44 self._encoded_stream = encoded_stream |
41 self._type = definitions.FILE_ENTRY_TYPE_FILE | 45 self._type = definitions.FILE_ENTRY_TYPE_FILE |
42 | 46 |
43 def __del__(self): | 47 def __del__(self): |
44 """Cleans up the file entry.""" | 48 """Cleans up the file entry.""" |
45 # __del__ can be invoked before __init__ has completed. | 49 # __del__ can be invoked before __init__ has completed. |
46 if hasattr(self, u'_encoded_stream'): | 50 if hasattr(self, '_encoded_stream'): |
47 self._encoded_stream.close() | 51 self._encoded_stream.close() |
48 self._encoded_stream = None | 52 self._encoded_stream = None |
49 | 53 |
50 super(EncodedStreamFileEntry, self).__del__() | 54 super(EncodedStreamFileEntry, self).__del__() |
51 | 55 |
52 def _GetStat(self): | 56 def _GetStat(self): |
53 """Retrieves information about the file entry. | 57 """Retrieves information about the file entry. |
54 | 58 |
55 Returns: | 59 Returns: |
56 VFSStat: a stat object. | 60 VFSStat: a stat object. |
57 """ | 61 """ |
58 stat_object = vfs_stat.VFSStat() | 62 stat_object = vfs_stat.VFSStat() |
59 | 63 |
60 if self._encoded_stream: | 64 if self._encoded_stream: |
61 stat_object.size = self._encoded_stream.get_size() | 65 stat_object.size = self._encoded_stream.get_size() |
62 | 66 |
63 stat_object.type = self._type | 67 stat_object.type = self._type |
64 | 68 |
65 return stat_object | 69 return stat_object |
LEFT | RIGHT |