-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove compat layers for unsupported python versions
- Loading branch information
Showing
17 changed files
with
42 additions
and
136 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
This file was deleted.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,59 +1,17 @@ | ||
# rohmu - compatibility functions to support older Python 3 versions | ||
# rohmu - This module used to contain compatible implementations for older | ||
# python version. | ||
# | ||
# Code mostly copied from Python 3.4.3 under the Python license. | ||
|
||
# suppress: call or simulate Pyhon 3.4 contextlib.suppress | ||
|
||
try: | ||
from contextlib import \ | ||
suppress # pylint: disable=import-error, no-name-in-module, unused-import | ||
except ImportError: | ||
|
||
class suppress: | ||
"""Context manager to suppress specified exceptions | ||
After the exception is suppressed, execution proceeds with the next | ||
statement following the with statement. | ||
with suppress(FileNotFoundError): | ||
os.remove(somefile) | ||
# Execution still resumes here if the file was already removed | ||
""" | ||
def __init__(self, *exceptions): | ||
self._exceptions = exceptions | ||
|
||
def __enter__(self): | ||
pass | ||
|
||
def __exit__(self, exctype, excinst, exctb): | ||
# Unlike isinstance and issubclass, CPython exception handling | ||
# currently only looks at the concrete type hierarchy (ignoring | ||
# the instance and subclass checking hooks). While Guido considers | ||
# that a bug rather than a feature, it's a fairly hard one to fix | ||
# due to various internal implementation details. suppress provides | ||
# the simpler issubclass based semantics, rather than trying to | ||
# exactly reproduce the limitations of the CPython interpreter. | ||
# | ||
# See http://bugs.python.org/issue12029 for more details | ||
return exctype is not None and issubclass(exctype, self._exceptions) | ||
|
||
|
||
# makedirs: call or simulate Pyhon 3.4.1 os.makedirs | ||
# Earlier Python versions raise an error if exist_ok flag is set and the | ||
# directory exists with different permissions. | ||
|
||
import os | ||
import sys | ||
|
||
if sys.version_info >= (3, 4, 1): | ||
makedirs = os.makedirs | ||
else: | ||
|
||
def makedirs(path, mode=0o777, exist_ok=False): | ||
if not exist_ok: | ||
return os.makedirs(path, mode) | ||
try: | ||
return os.makedirs(path, mode) | ||
except FileExistsError: | ||
pass | ||
return None | ||
# Since we don't support those older versions anymore, this module could be removed, | ||
# but as rohmu is used outside pghoard itself better keep the imports and throw | ||
# a deprecation warning. | ||
|
||
import warnings | ||
from contextlib import suppress # pylint: disable=unused-import | ||
from os import makedirs # pylint: disable=unused-import | ||
|
||
warnings.warn( | ||
"pghoard.rohmu.compat is deprecated, you should import " | ||
"from the standard library directly instead", | ||
DeprecationWarning, | ||
stacklevel=2 | ||
) |
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
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
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
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.