Skip to content
Snippets Groups Projects
Commit 92b7dc6d authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

docs fix

Change-Id: Ie8979237f2c191ce066fa1892030cb1daecd07db
parent d8af4afe
No related branches found
No related tags found
No related merge requests found
...@@ -392,14 +392,6 @@ def close_file_after(fun): ...@@ -392,14 +392,6 @@ def close_file_after(fun):
return inner return inner
def open_file(fun):
@wraps(fun)
def inner(self, *args, **kwargs):
return fun(self, self._open_file(), *args, **kwargs)
return inner
class AutoflushFile(Proxy[io.FileIO]): class AutoflushFile(Proxy[io.FileIO]):
""" """
A file that is supposed to be closed after each write command issued. A file that is supposed to be closed after each write command issued.
...@@ -444,8 +436,7 @@ class AutoflushFile(Proxy[io.FileIO]): ...@@ -444,8 +436,7 @@ class AutoflushFile(Proxy[io.FileIO]):
@is_closed_getter @is_closed_getter
@close_file_after @close_file_after
@open_file def seek(self, offset: int, whence: int = os.SEEK_SET) -> int:
def seek(self, fle: AutoflushFile, offset: int, whence: int = os.SEEK_SET) -> int:
""" """
Seek to a provided position within the file Seek to a provided position within the file
...@@ -454,19 +445,20 @@ class AutoflushFile(Proxy[io.FileIO]): ...@@ -454,19 +445,20 @@ class AutoflushFile(Proxy[io.FileIO]):
:return: current pointer :return: current pointer
""" """
fle = self._open_file()
v = fle.seek(offset, whence) v = fle.seek(offset, whence)
self.__dict__['pointer'] = fle.tell() self.__dict__['pointer'] = fle.tell()
return v return v
@is_closed_getter @is_closed_getter
@close_file_after @close_file_after
@open_file def read(self, *args, **kwargs) -> tp.Union[str, bytes]:
def read(self, fle: AutoflushFile, *args, **kwargs) -> tp.Union[str, bytes]:
""" """
Read a file, returning the read-in data Read a file, returning the read-in data
:return: data readed :return: data readed
""" """
fle = self._open_file()
p = fle.read(*args, **kwargs) p = fle.read(*args, **kwargs)
self.__dict__['pointer'] = fle.tell() self.__dict__['pointer'] = fle.tell()
return p return p
...@@ -476,10 +468,10 @@ class AutoflushFile(Proxy[io.FileIO]): ...@@ -476,10 +468,10 @@ class AutoflushFile(Proxy[io.FileIO]):
@is_closed_getter @is_closed_getter
@close_file_after @close_file_after
@open_file def readall(self) -> tp.Union[str, bytes]:
def readall(self, fle) -> tp.Union[str, bytes]:
"""Read all contents into the file""" """Read all contents into the file"""
return file.readall() fle = self._open_file()
return fle.readall()
def _open_file(self) -> io.FileIO: def _open_file(self) -> io.FileIO:
file = self._get_file() file = self._get_file()
...@@ -499,7 +491,6 @@ class AutoflushFile(Proxy[io.FileIO]): ...@@ -499,7 +491,6 @@ class AutoflushFile(Proxy[io.FileIO]):
self.__dict__['_Proxy__obj'] = None self.__dict__['_Proxy__obj'] = None
@is_closed_getter @is_closed_getter
@open_file
@close_file_after @close_file_after
def close(self, fle) -> None: # pylint: disable=unused-argument def close(self, fle) -> None: # pylint: disable=unused-argument
""" """
...@@ -509,22 +500,22 @@ class AutoflushFile(Proxy[io.FileIO]): ...@@ -509,22 +500,22 @@ class AutoflushFile(Proxy[io.FileIO]):
@is_closed_getter @is_closed_getter
@close_file_after @close_file_after
@open_file def write(self, *args, **kwargs) -> int:
def write(self, fle, *args, **kwargs) -> int:
""" """
Write a particular value to the file, close it afterwards. Write a particular value to the file, close it afterwards.
:return: amount of bytes written :return: amount of bytes written
""" """
fle = self._open_file()
val = fle.write(*args, **kwargs) val = fle.write(*args, **kwargs)
self.__dict__['pointer'] = fle.tell() self.__dict__['pointer'] = fle.tell()
return val return val
@is_closed_getter @is_closed_getter
@close_file_after @close_file_after
@open_file def truncate(self, _size: tp.Optional[int] = None) -> int:
def truncate(self, fle, __size: tp.Optional[int] = None) -> int:
"""Truncate file to __size starting bytes""" """Truncate file to __size starting bytes"""
v = fle.truncate(__size) fle = self._open_file()
v = fle.truncate(_size)
self.__dict__['pointer'] = fle.tell() self.__dict__['pointer'] = fle.tell()
return v return v
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment