# Path: ldapcherry/exceptions.py
# class UserDoesntExist(Exception):
#     def __init__(self, user, backend):
#         self.user = user
#         self.bakend = backend
#         self.log = \
#             "user '" + user + "'" \
#             " does not exist" \
#             " in backend '" + backend + "'"
# 
# class GroupDoesntExist(Exception):
#     def __init__(self, group, backend):
#         self.group = group
#         self.bakend = backend
#         self.log = \
#             "group '" + group + "'" \
#             " does not exist" \
#             " in backend '" + backend + "'"
# 
# class MissingParameter(Exception):
#     def __init__(self, section, key):
#         self.section = section
#         self.key = key
#         self.log = \
#             "missing parameter '%(key)s' in section '%(section)s'" % \
#             {'key': key, 'section': section}
# 
# class UserAlreadyExists(Exception):
#     def __init__(self, user, backend):
#         self.user = user
#         self.bakend = backend
#         self.log = \
#             "user '" + user + "'" \
#             " already exists" \
#             " in backend '" + backend + "'"


import sys
import ldapcherry.backend
import re
from ldapcherry.exceptions import UserDoesntExist, \
    GroupDoesntExist, MissingParameter, \
    UserAlreadyExists
    from sets import Set as set
        """ Search backend for users

        :param searchstring: the search string
        :type searchstring: string
        :rtype: dict of dict ( {<user attr key>: {<attr>: <value>}} )
        """
        ret = {}
        for user in self.users:
            match = False
            for attr in self.search_attrs:
                if attr not in self.users[user]:
                    pass
                elif re.search(searchstring + '.*', self.users[user][attr]):
                    match = True
            if match:
                ret[user] = self.users[user]
        return ret

    def get_user(self, username):
        """ Get a user's attributes

        :param username: 'key' attribute of the user
        :type username: string
        :rtype: dict ( {<attr>: <value>} )

        .. warning:: raise UserDoesntExist if user doesn't exist
        """
        try:
            return self.users[username]
        except Exception as e:

# Path: ldapcherry/exceptions.py
# class UserDoesntExist(Exception):
#     def __init__(self, user, backend):
#         self.user = user
#         self.bakend = backend
#         self.log = \
#             "user '" + user + "'" \
#             " does not exist" \
#             " in backend '" + backend + "'"
# 
# class GroupDoesntExist(Exception):
#     def __init__(self, group, backend):
#         self.group = group
#         self.bakend = backend
#         self.log = \
#             "group '" + group + "'" \
#             " does not exist" \
#             " in backend '" + backend + "'"
# 
# class MissingParameter(Exception):
#     def __init__(self, section, key):
#         self.section = section
#         self.key = key
#         self.log = \
#             "missing parameter '%(key)s' in section '%(section)s'" % \
#             {'key': key, 'section': section}
# 
# class UserAlreadyExists(Exception):
#     def __init__(self, user, backend):
#         self.user = user
#         self.bakend = backend
#         self.log = \
#             "user '" + user + "'" \
#             " already exists" \
#             " in backend '" + backend + "'"


# Path: ldapcherry/backend/backendDemo.py
import sys
import ldapcherry.backend
import re
from ldapcherry.exceptions import UserDoesntExist, \
    GroupDoesntExist, MissingParameter, \
    UserAlreadyExists
    from sets import Set as set

        """ Search backend for users

        :param searchstring: the search string
        :type searchstring: string
        :rtype: dict of dict ( {<user attr key>: {<attr>: <value>}} )
        """
        ret = {}
        for user in self.users:
            match = False
            for attr in self.search_attrs:
                if attr not in self.users[user]:
                    pass
                elif re.search(searchstring + '.*', self.users[user][attr]):
                    match = True
            if match:
                ret[user] = self.users[user]
        return ret

    def get_user(self, username):
        """ Get a user's attributes

        :param username: 'key' attribute of the user
        :type username: string
        :rtype: dict ( {<attr>: <value>} )

        .. warning:: raise UserDoesntExist if user doesn't exist
        """
        try:
            return self.users[username]
        except Exception as e:

            raise UserDoesntExist(username, self.backend_name)