async def grant(self, user_id, *permissions):
        " 给用户(user_id)授于权限(permission) "

        prefix = f"{self._prefix_perm}/{user_id}/"

        perm_names = [str(p) for p in permissions]        
        checkings = [
            KV.put.txn(prefix + p, b'\0', prev_kv=True) for p in perm_names
        ]
        success, response = await self._client.txn(compare=[], success=checkings)
        if not success:
            errmsg = f"无法授予用户({user_id})的权限: {{{', '.join(perm_names)}}}"
            raise Unprocessable(errmsg)

        if logger.isEnabledFor(logging.DEBUG):
            granted, ignored = set(), set()
            for i, (perm, _)  in enumerate(response):
                if perm is None:
                    granted.add(perm_names[i])
                else:
                    ignored.add(perm_names[i])
            
            logger.debug(f"授予用户({user_id})权限({', '.join(granted)}), "
                            f"忽略已授权({', '.join(ignored)})")
async def grant ( self , user_id , * permissions ) : prefix = f"{self._prefix_perm}/{user_id}/" perm_names = [ str ( p ) for p in permissions ] checkings = [ KV . put . txn ( prefix + p , b'\0' , prev_kv = True ) for p in perm_names ] success , response = await self . _client . txn ( compare = [ ] , success = checkings ) if not success : errmsg = f"无法授予用户({user_id})的权限: {{{', '.join(perm_names)}}}" raise Unprocessable ( errmsg ) if logger . isEnabledFor ( logging . DEBUG ) : granted , ignored = set ( ) , set ( ) for i , ( perm , _ ) in enumerate ( response ) : if perm is None : granted . add ( perm_names [ i ] ) else : ignored . add ( perm_names [ i ] ) logger . debug ( f"授予用户({user_id})权限({', '.join(granted)}), " f"忽略已授权({', '.join(ignored)})" )
给用户(user_id)授于权限(permission)