<s> try : <EOL> import keyutils as _keyutils <EOL> _keyring = _keyutils . KEY_SPEC_USER_KEYRING <EOL> except ImportError : <EOL> _keyutils = None <EOL> def _setupSession ( ) : <EOL> """<STR_LIT>""" <EOL> global _keyring <EOL> try : <EOL> _keyutils . link ( _keyutils . KEY_SPEC_USER_KEYRING , <EOL> _keyutils . KEY_SPEC_SESSION_KEYRING ) <EOL> except AttributeError : <EOL> _keyring = _keyutils . KEY_SPEC_SESSION_KEYRING <EOL> return <EOL> except _keyutils . Error as err : <EOL> if err . args [ <NUM_LIT:0> ] != _keyutils . EKEYREVOKED : <EOL> raise <EOL> _keyutils . join_session_keyring ( ) <EOL> _keyutils . link ( _keyutils . KEY_SPEC_USER_KEYRING , <EOL> _keyutils . KEY_SPEC_SESSION_KEYRING ) <EOL> def getPassword ( keyDesc ) : <EOL> if not _keyutils : <EOL> return None <EOL> _setupSession ( ) <EOL> try : <EOL> keyId = _keyutils . request_key ( keyDesc , _keyring ) <EOL> except _keyutils . Error as err : <EOL> if err . args [ <NUM_LIT:0> ] != _keyutils . EKEYREVOKED : <EOL> raise <EOL> return None <EOL> if keyId is not None : <EOL> return _keyutils . read_key ( keyId ) <EOL> return None <EOL> def setPassword ( keyDesc , passwd ) : <EOL> if not _keyutils : <EOL> return passwd <EOL> _setupSession ( ) <EOL> try : <EOL> _keyutils . add_key ( keyDesc , passwd , _keyring ) <EOL> except _keyutils . Error as err : <EOL> if err . args [ <NUM_LIT:0> ] != _keyutils . EKEYREVOKED : <EOL> raise <EOL> return passwd <EOL> def invalidatePassword ( keyDesc ) : <EOL> if not _keyutils : <EOL> return <EOL> try : <EOL> keyId = _keyutils . search ( _keyring , keyDesc ) <EOL> _keyutils . revoke ( keyId ) <EOL> except AttributeError : <EOL> return <EOL> except _keyutils . Error as err : <EOL> if err . args [ <NUM_LIT:0> ] != _keyutils . EKEYREVOKED : <EOL> raise </s>
