forked from flotpython/course
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ShipDict : gestion de l'option -z (--gzip) de merger.py
resolves flotpython#45
- Loading branch information
Showing
5 changed files
with
115 additions
and
29 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,24 @@ | ||
import abc | ||
|
||
# application import | ||
import file_manager | ||
|
||
|
||
class Factory(abc.ABC): | ||
|
||
@staticmethod | ||
@abc.abstractmethod | ||
def make_filemanager(): | ||
pass | ||
|
||
class GzipFileManagerFactory(Factory): | ||
|
||
@staticmethod | ||
def make_filemanager(): | ||
return file_manager.GzipFileManager() | ||
|
||
class TextFileManagerFactory(Factory): | ||
|
||
@staticmethod | ||
def make_filemanager(): | ||
return file_manager.TextFileManager() |
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,41 @@ | ||
import abc | ||
import gzip | ||
import contextlib | ||
|
||
|
||
class FileManager(abc.ABC): | ||
|
||
@staticmethod | ||
@abc.abstractmethod | ||
def open(filename, mode): | ||
pass | ||
|
||
|
||
class GzipFileManager(FileManager): | ||
|
||
READ = "rt" | ||
WRITE = "wt" | ||
|
||
@staticmethod | ||
@contextlib.contextmanager | ||
def open(filename, mode): | ||
file = gzip.open(filename, encoding="UTF-8", mode=mode, newline="\n") | ||
try: | ||
yield file | ||
finally: | ||
file.close() | ||
|
||
|
||
class TextFileManager(FileManager): | ||
|
||
READ = "r" | ||
WRITE = "w" | ||
|
||
@staticmethod | ||
@contextlib.contextmanager | ||
def open(filename, mode): | ||
file = open(filename, encoding="UTF-8", mode=mode, newline="\n") | ||
try: | ||
yield file | ||
finally: | ||
file.close() |
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