# Path: nappingcat/exceptions.py
# class NappingCatRejected(NappingCatException):
#     pass
# 
# Path: nappingcat/response.py
# def Success(content, response_type=Response):
#     return response_type(200, content)
# 
# Path: nappingcat/decorators.py
# def discoverable(params, help_text):
#     def inner(func):
#         return DiscoverableEndpoint(func.__name__, params, help_text, func)
#     return inner 


from nappingcat.exceptions import NappingCatRejected
from nappingcat.response import Success 
from nappingcat.decorators import discoverable
import sys
import os
        settings = dict(request.settings.items('kittyconfig'))
        auth.add_key_to_user(username, key) 
        return Success({'message':"You added the key '%s...' to the user '%s'" % (key[0:30], username)})
    raise NappingCatRejected("You don't have permission to modify users.")

@discoverable({'username':'string', 'permission':('tuple', PERMISSION_SEP)}, """
add_permission <username> '<permission list>'

    add a permission to an existing user.
    permission tuples should be provided as a series of strings; e.g.,

        {EXECUTABLE} add_permission <username> kittygit read <reponame>
        {EXECUTABLE} add_permission <username> auth modifyuser

""".strip())
def add_permission(request, username, permission):
    auth = request.auth_backend
    permission_tuple = permission.split(PERMISSION_SEP)
    # if you've got global rights to modifying users,
    # OR if you've already got the existing permission
    # you can pay it forward.
    if auth.has_permission(request.user, ('auth', 'modifyuser')) or auth.has_permission(request.user, permission_tuple):
        auth.add_permission(username, permission_tuple)
        return Success({'message':"You granted '%s' the permission '%s'" % (username, permission)})
    raise NappingCatRejected("You really don't have the right to do that. Sorry.")


@discoverable({'username':'string', 'permission':('tuple', PERMISSION_SEP)}, """
remove_permission <username> '<permission list>'


# Path: nappingcat/exceptions.py
# class NappingCatRejected(NappingCatException):
#     pass
# 
# Path: nappingcat/response.py
# def Success(content, response_type=Response):
#     return response_type(200, content)
# 
# Path: nappingcat/decorators.py
# def discoverable(params, help_text):
#     def inner(func):
#         return DiscoverableEndpoint(func.__name__, params, help_text, func)
#     return inner 


# Path: nappingcat/contrib/auth/handlers.py
from nappingcat.exceptions import NappingCatRejected
from nappingcat.response import Success 
from nappingcat.decorators import discoverable
import sys
import os

        settings = dict(request.settings.items('kittyconfig'))
        auth.add_key_to_user(username, key) 
        return Success({'message':"You added the key '%s...' to the user '%s'" % (key[0:30], username)})
    raise NappingCatRejected("You don't have permission to modify users.")

@discoverable({'username':'string', 'permission':('tuple', PERMISSION_SEP)}, """
add_permission <username> '<permission list>'

    add a permission to an existing user.
    permission tuples should be provided as a series of strings; e.g.,

        {EXECUTABLE} add_permission <username> kittygit read <reponame>
        {EXECUTABLE} add_permission <username> auth modifyuser

""".strip())
def add_permission(request, username, permission):
    auth = request.auth_backend
    permission_tuple = permission.split(PERMISSION_SEP)
    # if you've got global rights to modifying users,
    # OR if you've already got the existing permission
    # you can pay it forward.
    if auth.has_permission(request.user, ('auth', 'modifyuser')) or auth.has_permission(request.user, permission_tuple):
        auth.add_permission(username, permission_tuple)
        return Success({'message':"You granted '%s' the permission '%s'" % (username, permission)})
    raise NappingCatRejected("You really don't have the right to do that. Sorry.")


@discoverable({'username':'string', 'permission':('tuple', PERMISSION_SEP)}, """
remove_permission <username> '<permission list>'


    remove a permission from an existing user