'Hook this tool into cherrypy.request.
The standard CherryPy request object will automatically call this
method when the tool is "turned on" in config.'

def _setup(self):

    hooks = cherrypy.serving.request.hooks
    conf = self._merged_args()
    p = conf.pop('priority', None)
    if (p is None):
        p = getattr(self.callable, 'priority', self._priority)
    hooks.attach(self._point, self.callable, priority=p, **conf)
    locking = conf.pop('locking', 'implicit')
    if (locking == 'implicit'):
        hooks.attach('before_handler', self._lock_session)
    elif (locking == 'early'):
        hooks.attach('before_request_body', self._lock_session, priority=60)
    else:
        pass
    hooks.attach('before_finalize', _sessions.save)
    hooks.attach('on_end_request', _sessions.close)
