def getHandle():
    #open database
    _db.open(misc.getCallableByName(settings['store']['interface']))
    #create in-memory session manager
    SessionManager.open(inMemorySessionManager.SessionManager, 1200)
    oSystemUser = _db.getItem('system')
    context = HttpContext()
    context.session = SessionManager.create(oSystemUser)
    
    currentThread().context = context
    currentThread().trans = None
    return _db
    def handle_request(self, rh, raw_request=None):
        if raw_request == None:
            raw_request = loads(rh.input_buffer)
        response = HttpResponse()
        request = HttpRequest(raw_request)
                
        item = None
        registration = None
        
        try:
            try:
                self.context = HttpContext(request, response)
                sPath = request.serverVariables['PATH_INFO']
                item = _db.get_item(sPath)
                if item != None and not item._isDeleted:
                    self.context._fetch_session()
                    self.dispatch_method(item)
                else:
                    # dir request
                    lstPath = sPath.split('/')
                    dirName = lstPath[1]
                    # remove blank entry & app name to get the requested path
                    sDirPath = '/'.join(lstPath[2:])
                    webApp = pubdirs.dirs.get(dirName, None)
                    if webApp:
                        registration = webApp.getRegistration(
                            sDirPath,
                            request.serverVariables['REQUEST_METHOD'],
                            request.serverVariables['HTTP_USER_AGENT'],
                            request.getLang())
                    if not registration:
                        raise exceptions.NotFound, \
                            'The resource "%s" does not exist' % sPath
                    
                    rtype = registration.type
                    if rtype == 1: # in case of psp fetch session
                        self.context._fetch_session()

                    # apply pre-processing filters
                    [filter[0].apply(self.context, item, registration, **filter[1])
                     for filter in registration.filters
                     if filter[0].type == 'pre']

                    if rtype == 1: # psp page
                        ServerPage.execute(self.context, registration.context)
                    elif rtype == 0: # static file
                        f_name = registration.context
                        if_none_match = request.HTTP_IF_NONE_MATCH
                        if if_none_match != None and if_none_match == \
                                '"%s"' % misc.generate_file_etag(f_name):
                            response._code = 304
                        else: 
                            response.loadFromFile(f_name)
                            response.setHeader('ETag', '"%s"' %
                                               misc.generate_file_etag(f_name))
                            if registration.encoding:
                                response.charset = registration.encoding
            
            except exceptions.ResponseEnd, e:
                pass
            
            if registration != None and response._code == 200:
                # do we have caching directive?
                if registration.max_age:
                    response.setExpiration(registration.max_age)
                # apply post-processing filters
                [filter[0].apply(self.context, item, registration, **filter[1])
                 for filter in registration.filters
                 if filter[0].type == 'post']