1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
15- """Simple library for managing Linux users and groups.
15+ """Legacy Charmhub-hosted passwd library, deprecated in favour of ``charmlibs.passwd``.
16+
17+ WARNING: This library is deprecated and will no longer receive feature updates or bugfixes.
18+ ``charmlibs.passwd`` version 1.0 is a bug-for-bug compatible migration of this library.
19+ Add 'charmlibs-passwd~=1.0' to your charm's dependencies, and remove this Charmhub-hosted library.
20+ Then replace `from charms.operator_libs_linux.v0 import passwd` with
21+ `from charmlibs import passwd`.
22+ Read more:
23+ - https://documentation.ubuntu.com/charmlibs
24+ - https://pypi.org/project/charmlibs-passwd
25+
26+ ---
27+
28+ Simple library for managing Linux users and groups.
1629
1730The `passwd` module provides convenience methods and abstractions around users and groups on a
1831Linux system, in order to make adding and managing users and groups easy.
4558
4659# Increment this PATCH version before using `charmcraft publish-lib` or reset
4760# to 0 if you are raising the major API version
48- LIBPATCH = 4
61+ LIBPATCH = 5
4962
5063
5164def user_exists (user : Union [str , int ]) -> Optional [pwd .struct_passwd ]:
@@ -58,9 +71,9 @@ def user_exists(user: Union[str, int]) -> Optional[pwd.struct_passwd]:
5871 TypeError: where neither a string or int is passed as the first argument
5972 """
6073 try :
61- if type (user ) is int :
74+ if isinstance (user , int ) and not isinstance ( user , bool ) :
6275 return pwd .getpwuid (user )
63- elif type (user ) is str :
76+ elif isinstance (user , str ) :
6477 return pwd .getpwnam (user )
6578 else :
6679 raise TypeError ("specified argument '%r' should be a string or int" , user )
@@ -79,9 +92,9 @@ def group_exists(group: Union[str, int]) -> Optional[grp.struct_group]:
7992 TypeError: where neither a string or int is passed as the first argument
8093 """
8194 try :
82- if type (group ) is int :
95+ if isinstance (group , int ) and not isinstance ( group , bool ) :
8396 return grp .getgrgid (group )
84- elif type (group ) is str :
97+ elif isinstance (group , str ) :
8598 return grp .getgrnam (group )
8699 else :
87100 raise TypeError ("specified argument '%r' should be a string or int" , group )
0 commit comments