Convert the private file attribute to a property to allow for cloning.

This commit is contained in:
Mike Auty
2016-08-14 01:09:36 +01:00
parent e02feed16e
commit 8089a03f81
+10 -2
View File
@@ -66,10 +66,18 @@ class FileLayer(interfaces.layers.DataLayerInterface):
def __init__(self, context, config_path, name, filename):
super().__init__(context, config_path, name)
self._filename = filename
self._file_ = None
self._size = os.path.getsize(filename)
@property
def _file(self):
"""Property to prevent the intializer storing an unserializable open file (for context cloning)"""
# FIXME: Add "+" to the mode once we've determined whether write mode is enabled
mode = "rb"
self._file = open(filename, mode)
self._size = os.path.getsize(filename)
if not self._file_:
self._file_ = open(self._filename, mode)
return self._file_
@property
def maximum_address(self):