# Path: ddserver/utils/deps.py
# 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
# @property
# @require(session = 'ddserver.interface.session:SessionManager')
# def authorized(self, session):
#   if session.username:
#     return self[session.username]


import bottle
import formencode
from ddserver.web import route
from ddserver.utils.deps import extend, require
from ddserver.interface.user import authorized
from ddserver.interface import validation
from ddserver.interface.validation import validate
from passlib.apps import custom_app_context as pwd
          `host`.`id` AS `id`,
          `host`.`hostname` AS `hostname`,
          `suffix`.`name` AS `suffix`,
          `host`.`address` AS `address`,
          `host`.`updated` AS `updated`,
          `host`.`description` AS `description`
        FROM `hosts` AS `host`
        LEFT JOIN `suffixes` AS `suffix`
          ON ( `suffix`.`id` = `host`.`suffix_id` )
        WHERE `host`.`id` = %(id)s
          AND `host`. `user_id` = %(user_id)s
    ''', {'id': host_id,
          'user_id': user.id})
    host = cur.fetchone()

  if host is None:
    messages.error('Hostname not found or no access!')
    bottle.redirect('/user/hosts/list')

  return templates['host.html'](host = host,
                                current_ip = bottle.request.remote_addr)



@route('/user/host/updateAddress', method = 'POST')
@authorized()
@validate('/user/hosts/list',
          host_id = formencode.validators.Int(),
          address = validation.IPAddress(),
          description = validation.String(max = 255))

# Path: ddserver/utils/deps.py
# 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
# @property
# @require(session = 'ddserver.interface.session:SessionManager')
# def authorized(self, session):
#   if session.username:
#     return self[session.username]


# Path: ddserver/interface/pages/user/host.py
import bottle
import formencode
from ddserver.web import route
from ddserver.utils.deps import extend, require
from ddserver.interface.user import authorized
from ddserver.interface import validation
from ddserver.interface.validation import validate
from passlib.apps import custom_app_context as pwd

          `host`.`id` AS `id`,
          `host`.`hostname` AS `hostname`,
          `suffix`.`name` AS `suffix`,
          `host`.`address` AS `address`,
          `host`.`updated` AS `updated`,
          `host`.`description` AS `description`
        FROM `hosts` AS `host`
        LEFT JOIN `suffixes` AS `suffix`
          ON ( `suffix`.`id` = `host`.`suffix_id` )
        WHERE `host`.`id` = %(id)s
          AND `host`. `user_id` = %(user_id)s
    ''', {'id': host_id,
          'user_id': user.id})
    host = cur.fetchone()

  if host is None:
    messages.error('Hostname not found or no access!')
    bottle.redirect('/user/hosts/list')

  return templates['host.html'](host = host,
                                current_ip = bottle.request.remote_addr)



@route('/user/host/updateAddress', method = 'POST')
@authorized()
@validate('/user/hosts/list',
          host_id = formencode.validators.Int(),
          address = validation.IPAddress(),
          description = validation.String(max = 255))

@require(db = 'ddserver.db:Database',