4646)
4747
4848
49- class _ChRootContext :
49+ # noinspection PyProtectedMember
50+ class _ChRootContext : # pylint: disable=protected-access
5051 """Context manager for call commands with chroot.
5152
5253 .. versionadded:: 4.1.0
5354 """
5455
55- __slots__ = ("__conn " , "__chroot_status " , "__path " )
56+ __slots__ = ("_conn " , "_chroot_status " , "_path " )
5657
5758 def __init__ (self , conn : "ExecHelper" , path : typing .Optional [str ] = None ) -> None :
5859 """Context manager for call commands with sudo.
@@ -62,41 +63,33 @@ def __init__(self, conn: "ExecHelper", path: typing.Optional[str] = None) -> Non
6263 :param path: chroot path or None for no chroot
6364 :type path: typing.Optional[str]
6465 """
65- self .__conn = conn # type: ExecHelper
66- self .__chroot_status = conn .chroot_path # type: typing.Optional[str]
67- self .__path = path # type: typing.Optional[str]
66+ self ._conn = conn # type: ExecHelper
67+ self ._chroot_status = conn ._chroot_path # type: typing.Optional[str]
68+ self ._path = path # type: typing.Optional[str]
6869
6970 def __enter__ (self ) -> None :
70- self .__conn .__enter__ ()
71- self .__chroot_status = self .__conn . chroot_path
72- self .__conn . chroot_path = self .__path
71+ self ._conn .__enter__ ()
72+ self ._chroot_status = self ._conn . _chroot_path
73+ self ._conn . _chroot_path = self ._path
7374
7475 def __exit__ (self , exc_type : typing .Any , exc_val : typing .Any , exc_tb : typing .Any ) -> None :
75- self .__conn . chroot_path = self .__chroot_status
76- self .__conn .__exit__ (exc_type = exc_type , exc_val = exc_val , exc_tb = exc_tb ) # type: ignore
76+ self ._conn . _chroot_path = self ._chroot_status
77+ self ._conn .__exit__ (exc_type = exc_type , exc_val = exc_val , exc_tb = exc_tb ) # type: ignore
7778
7879
7980class ExecHelper (metaclass = abc .ABCMeta ):
8081 """ExecHelper global API."""
8182
8283 __slots__ = ("__lock" , "__logger" , "log_mask_re" , "__chroot_path" )
8384
84- def __init__ (
85- self ,
86- log_mask_re : typing .Optional [str ] = None ,
87- * ,
88- logger : logging .Logger ,
89- chroot_path : typing .Optional [str ] = None
90- ) -> None :
85+ def __init__ (self , log_mask_re : typing .Optional [str ] = None , * , logger : logging .Logger ) -> None :
9186 """Global ExecHelper API.
9287
9388 :param logger: logger instance to use
9489 :type logger: logging.Logger
9590 :param log_mask_re: regex lookup rule to mask command for logger.
9691 all MATCHED groups will be replaced by '<*masked*>'
9792 :type log_mask_re: typing.Optional[str]
98- :param chroot_path: chroot path (use chroot if set)
99- :type chroot_path: typing.Optional[str]
10093
10194 .. versionchanged:: 1.2.0 log_mask_re regex rule for masking cmd
10295 .. versionchanged:: 1.3.5 make API public to use as interface
@@ -105,7 +98,7 @@ def __init__(
10598 self .__lock = threading .RLock ()
10699 self .__logger = logger
107100 self .log_mask_re = log_mask_re
108- self .__chroot_path = chroot_path # type: typing.Optional[str]
101+ self .__chroot_path = None # type: typing.Optional[str]
109102
110103 @property
111104 def logger (self ) -> logging .Logger :
@@ -121,16 +114,16 @@ def lock(self) -> threading.RLock:
121114 return self .__lock
122115
123116 @property
124- def chroot_path (self ) -> typing .Optional [str ]:
117+ def _chroot_path (self ) -> typing .Optional [str ]:
125118 """Path for chroot if set.
126119
127120 :rtype: typing.Optional[str]
128121 .. versionadded:: 3.5.3
129122 """
130123 return self .__chroot_path
131124
132- @chroot_path .setter
133- def chroot_path (self , new_state : typing .Optional [str ]) -> None :
125+ @_chroot_path .setter
126+ def _chroot_path (self , new_state : typing .Optional [str ]) -> None :
134127 """Path for chroot if set.
135128
136129 :param new_state: new path
@@ -139,8 +132,8 @@ def chroot_path(self, new_state: typing.Optional[str]) -> None:
139132 """
140133 self .__chroot_path = new_state
141134
142- @chroot_path .deleter
143- def chroot_path (self ) -> None :
135+ @_chroot_path .deleter
136+ def _chroot_path (self ) -> None :
144137 """Remove Path for chroot.
145138
146139 .. versionadded:: 3.5.3
@@ -218,9 +211,9 @@ def mask(text: str, rules: str) -> str:
218211
219212 def _prepare_command (self , cmd : str , chroot_path : typing .Optional [str ] = None ) -> str :
220213 """Prepare command: cower chroot and other cases."""
221- if any ((chroot_path , self .chroot_path )):
214+ if any ((chroot_path , self ._chroot_path )):
222215 return "chroot {chroot_path} {cmd}" .format (
223- chroot_path = chroot_path if chroot_path else self .chroot_path ,
216+ chroot_path = chroot_path if chroot_path else self ._chroot_path ,
224217 cmd = cmd
225218 )
226219 return cmd
0 commit comments