-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from aollier/merger-gzip
Merger gzip
- Loading branch information
Showing
5 changed files
with
162 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import abc | ||
import enum | ||
import gzip | ||
|
||
|
||
class AbstractFileManager(abc.ABC): | ||
|
||
@classmethod | ||
def open(cls, filename, mode): | ||
return cls._open(filename, | ||
**{"encoding": "UTF-8", "mode": mode, "newline": '\n'}) | ||
|
||
@staticmethod | ||
@abc.abstractmethod | ||
def _open(filename, **kwargs): | ||
pass | ||
|
||
@property | ||
def READ(self): | ||
return self.Mode.READ.value | ||
|
||
@property | ||
def WRITE(self): | ||
return self.Mode.WRITE.value | ||
|
||
|
||
class GzipFileManager(AbstractFileManager): | ||
|
||
@enum.unique | ||
class Mode(enum.Enum): | ||
READ = "rt" | ||
WRITE = "wt" | ||
|
||
@staticmethod | ||
def _open(filename, **kwargs): | ||
return gzip.open(filename=filename, **kwargs) | ||
|
||
|
||
class TextFileManager(AbstractFileManager): | ||
|
||
@enum.unique | ||
class Mode(enum.Enum): | ||
READ = "r" | ||
WRITE = "w" | ||
|
||
@staticmethod | ||
def _open(filename, **kwargs): | ||
return open(file=filename, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.