# Path: ddserver/utils/deps.py
# 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 functools
import bottle
import formencode
from passlib.apps import custom_app_context as pwd
from ddserver.utils.deps import require
from ddserver.web import route
resp_nohost = functools.partial(Response, 'nohost', None)
resp_badauth = functools.partial(Response, 'badauth', None)
resp_badagent = functools.partial(Response, 'badagent', None)
resp_not_donator = functools.partial(Response, '!donator', None)
resp_abuse = functools.partial(Response, 'abuse', None)
resp_911 = functools.partial(Response, '911', None)



@require(logger='ddserver.utils.logger:Logger',
         db='ddserver.db:Database')
def update(logger, db, username, password, hostnames, address):
  """ Update the records.

      The very first step is to check username and password. If they are not
      provided or the username does not exist, a bad credentials answer is
      returned.

      If the credentials are checked, for each given hostname, the address is
      stored in the database.
  """

  # Check if we get some credentials
  if not username or not password:
    logger.warning('updater: Update attempt with missing credentials')
    return resp_badauth()

  # Try to get user ID from database
  with db.cursor() as cur:
    cur.execute('''

# Path: ddserver/utils/deps.py
# 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/updater/nic.py
import functools
import bottle
import formencode
from passlib.apps import custom_app_context as pwd
from ddserver.utils.deps import require
from ddserver.web import route

resp_nohost = functools.partial(Response, 'nohost', None)
resp_badauth = functools.partial(Response, 'badauth', None)
resp_badagent = functools.partial(Response, 'badagent', None)
resp_not_donator = functools.partial(Response, '!donator', None)
resp_abuse = functools.partial(Response, 'abuse', None)
resp_911 = functools.partial(Response, '911', None)



@require(logger='ddserver.utils.logger:Logger',
         db='ddserver.db:Database')
def update(logger, db, username, password, hostnames, address):
  """ Update the records.

      The very first step is to check username and password. If they are not
      provided or the username does not exist, a bad credentials answer is
      returned.

      If the credentials are checked, for each given hostname, the address is
      stored in the database.
  """

  # Check if we get some credentials
  if not username or not password:
    logger.warning('updater: Update attempt with missing credentials')
    return resp_badauth()

  # Try to get user ID from database
  with db.cursor() as cur:
    cur.execute('''

      SELECT `id`, `password`