# Path: nappingcat/auth.py
# class AuthBackend(object):
#     def __init__(self, settings):
#         self.users = {}
#         self.settings = settings
#         self.require_update = False
# 
#     def has_permission(self, user, permission):
#         full_query = (user,) + tuple(permission)
#         result = self.users
#         for i in full_query:
#             result = result.get(i, {})
#         return bool(result)
# 
#     def add_permission(self, user, permission):
#         self.require_update = True
#         full_query = (user,) + tuple(permission)
#         result = self.users
#         for i in full_query[:-1]:
#             level = result.get(i, None)
#             if level is None:
#                 result[i] = {}
#             result = result[i]
#         result[full_query[-1]] = True
# 
#     def remove_permission(self, user, permission):
#         self.require_update = True
#         full_query = (user,) + tuple(permission)
#         result = self.users
#         for i in full_query[:-1]:
#             level = result.get(i, None)
#             if level is None:
#                 result[i] = {}
#             result = result[i]
#         del result[full_query[-1]]
# 
#     def add_user(self, username):
#         self.require_update = True
#         self.users[username] = {'keys':[]}
# 
#     def add_key_to_user(self, user, key):
#         self.require_update = True
#         self.users[user]['keys'].append(key)
# 
#     def get_keys(self, username):
#         return self.users[username]['keys']
# 
#     def finish(self, pubkey_handler):
#         if self.require_update:
#             pubkey_handler.flush_keys(self)
# 
#     def get_users(self):
#         return self.users.keys()
# 
# Path: nappingcat/contrib/auth/handlers.py
# PERMISSION_SEP = '::'
# def add_user(request, username):
# def add_key_to_user(request, username):
# def add_permission(request, username, permission):
# def remove_permission(request, username, permission):
# 
# Path: nappingcat/request.py
# class Request(object):
#     def __init__(self, user, command, settings, streams, root_patterns):
# 
# Path: nappingcat/exceptions.py
# class NappingCatRejected(NappingCatException):
#     pass


from unittest import TestCase
from nappingcat.auth import AuthBackend
from nappingcat.contrib.auth import handlers
from nappingcat import request
from nappingcat.exceptions import NappingCatRejected
import ConfigParser
import StringIO
import random
import os

class SimpleAuth(AuthBackend):
    user_dict = {}
    def has_permission(self, username, permission):
        return bool(SimpleAuth.user_dict.get(username, {}).get(handlers.PERMISSION_SEP.join(permission), False)) 


# Path: nappingcat/auth.py
# class AuthBackend(object):
#     def __init__(self, settings):
#         self.users = {}
#         self.settings = settings
#         self.require_update = False
# 
#     def has_permission(self, user, permission):
#         full_query = (user,) + tuple(permission)
#         result = self.users
#         for i in full_query:
#             result = result.get(i, {})
#         return bool(result)
# 
#     def add_permission(self, user, permission):
#         self.require_update = True
#         full_query = (user,) + tuple(permission)
#         result = self.users
#         for i in full_query[:-1]:
#             level = result.get(i, None)
#             if level is None:
#                 result[i] = {}
#             result = result[i]
#         result[full_query[-1]] = True
# 
#     def remove_permission(self, user, permission):
#         self.require_update = True
#         full_query = (user,) + tuple(permission)
#         result = self.users
#         for i in full_query[:-1]:
#             level = result.get(i, None)
#             if level is None:
#                 result[i] = {}
#             result = result[i]
#         del result[full_query[-1]]
# 
#     def add_user(self, username):
#         self.require_update = True
#         self.users[username] = {'keys':[]}
# 
#     def add_key_to_user(self, user, key):
#         self.require_update = True
#         self.users[user]['keys'].append(key)
# 
#     def get_keys(self, username):
#         return self.users[username]['keys']
# 
#     def finish(self, pubkey_handler):
#         if self.require_update:
#             pubkey_handler.flush_keys(self)
# 
#     def get_users(self):
#         return self.users.keys()
# 
# Path: nappingcat/contrib/auth/handlers.py
# PERMISSION_SEP = '::'
# def add_user(request, username):
# def add_key_to_user(request, username):
# def add_permission(request, username, permission):
# def remove_permission(request, username, permission):
# 
# Path: nappingcat/request.py
# class Request(object):
#     def __init__(self, user, command, settings, streams, root_patterns):
# 
# Path: nappingcat/exceptions.py
# class NappingCatRejected(NappingCatException):
#     pass


# Path: tests/contribauth.py
from unittest import TestCase
from nappingcat.auth import AuthBackend
from nappingcat.contrib.auth import handlers
from nappingcat import request
from nappingcat.exceptions import NappingCatRejected
import ConfigParser
import StringIO
import random
import os


class SimpleAuth(AuthBackend):
    user_dict = {}
    def has_permission(self, username, permission):
        return bool(SimpleAuth.user_dict.get(username, {}).get(handlers.PERMISSION_SEP.join(permission), False)) 


    def add_permission(self, username, permission):