# Path: ddserver/utils/deps.py
# def export(**requirements):
#   ''' Decorator to export a factory.
# 
#       Requirements for the factory can be specified. These requirements are
#       passed to the wrapped function as specified by the `require` decorator.
#   '''
# 
#   def wrapper(func):
#     return Export(factory = require(**requirements)(func))
# 
#   return wrapper
# 
# def extend(self, extend):
#   ''' Extends this export.
# 
#       The instance created by the wrapped factory is extended by passing the
#       created instance to the given extend function after creation.
# 
#       The extend function must accept the instance as its only argument. If
#       the function returns a value which is not None, the instance is replaced
#       with the returned value.
#   '''
# 
#   assert self.__instance is None
# 
#   self.__extends.append(extend)
# 
# def require(**requirements):
#   ''' Decorator to inject requirements into a function.
# 
#       The decorated function is called with a named argument for each
#       specified requirement containing the exported instances.
#   '''
# 
#   exports = {name : Export.load(requirement)
#              for name, requirement
#              in requirements.iteritems()}
# 
#   def wrapper(func):
#     def wrapped(*args, **kwargs):
#       # Update the keyword arguments with the required instances
#       kwargs.update({name : export.instance
#                      for name, export
#                      in exports.iteritems()
#                      if name not in kwargs})
# 
#       return func(*args,
#                   **kwargs)
# 
#     wrapped.__name__ = func.__name__
# 
#     return wrapped
#   return wrapper


import uuid
import bottle
import functools
import collections
from passlib.apps import custom_app_context as pwd
from ddserver.utils.deps import export, extend, require


@export()
class UserManager(object):
  User = collections.namedtuple('User', ['id',
                                         'username',
                                         'password',
                                         'email',
                                         'admin',
                                         'active',
                                         'created',
                                         'authcode',
                                         'maxhosts'])


  @require(db = 'ddserver.db:Database')
  def __getitem__(self,
                  key,
                  db):
    ''' Returns the user record for the given username.

        @param key: the username

        @return: the user record or None if no such user exists
    '''

    with db.cursor() as cur:
      cur.execute('''
          SELECT *
          FROM users

# Path: ddserver/utils/deps.py
# def export(**requirements):
#   ''' Decorator to export a factory.
# 
#       Requirements for the factory can be specified. These requirements are
#       passed to the wrapped function as specified by the `require` decorator.
#   '''
# 
#   def wrapper(func):
#     return Export(factory = require(**requirements)(func))
# 
#   return wrapper
# 
# def extend(self, extend):
#   ''' Extends this export.
# 
#       The instance created by the wrapped factory is extended by passing the
#       created instance to the given extend function after creation.
# 
#       The extend function must accept the instance as its only argument. If
#       the function returns a value which is not None, the instance is replaced
#       with the returned value.
#   '''
# 
#   assert self.__instance is None
# 
#   self.__extends.append(extend)
# 
# def require(**requirements):
#   ''' Decorator to inject requirements into a function.
# 
#       The decorated function is called with a named argument for each
#       specified requirement containing the exported instances.
#   '''
# 
#   exports = {name : Export.load(requirement)
#              for name, requirement
#              in requirements.iteritems()}
# 
#   def wrapper(func):
#     def wrapped(*args, **kwargs):
#       # Update the keyword arguments with the required instances
#       kwargs.update({name : export.instance
#                      for name, export
#                      in exports.iteritems()
#                      if name not in kwargs})
# 
#       return func(*args,
#                   **kwargs)
# 
#     wrapped.__name__ = func.__name__
# 
#     return wrapped
#   return wrapper


# Path: ddserver/interface/user.py
import uuid
import bottle
import functools
import collections
from passlib.apps import custom_app_context as pwd
from ddserver.utils.deps import export, extend, require



@export()
class UserManager(object):
  User = collections.namedtuple('User', ['id',
                                         'username',
                                         'password',
                                         'email',
                                         'admin',
                                         'active',
                                         'created',
                                         'authcode',
                                         'maxhosts'])


  @require(db = 'ddserver.db:Database')
  def __getitem__(self,
                  key,
                  db):
    ''' Returns the user record for the given username.

        @param key: the username

        @return: the user record or None if no such user exists
    '''

    with db.cursor() as cur:
      cur.execute('''
          SELECT *
          FROM users

          WHERE username = %(username)s