Skip to content

Commit

Permalink
fix nullcontext missing on python 3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
marian-code committed Nov 2, 2020
1 parent 4542aac commit 783ddcf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
5 changes: 4 additions & 1 deletion ssh_utilities/remote/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import logging
import os
from contextlib import nullcontext
try:
from contextlib import nullcontext
except ImportError:
from ..utils import NullContext as nullcontext # type: ignore
from pathlib import Path
from threading import RLock
from typing import TYPE_CHECKING, ContextManager, Optional, Union
Expand Down
11 changes: 10 additions & 1 deletion ssh_utilities/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

__all__ = ["ProgressBar", "bytes_2_human_readable", "CompletedProcess",
"lprint", "for_all_methods", "glob2re", "file_filter",
"config_parser", "context_timeit"]
"config_parser", "context_timeit", "NullContext"]


class CompletedProcess:
Expand Down Expand Up @@ -427,6 +427,15 @@ def context_timeit(quiet: bool = False):
pass


class NullContext:
"""Replacement for contextlib.nullcontext for python 3.6."""

def __enter__(self):
return self

def __exit__(self, *args):
pass

# \033[<L>;<C>H # Move the cursor to line L, column C
# \033[<N>A # Move the cursor up N lines
# \033[<N>B # Move the cursor down N lines
Expand Down
2 changes: 1 addition & 1 deletion ssh_utilities/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.5.3"
__version__ = "0.5.4"

0 comments on commit 783ddcf

Please sign in to comment.