Logo Search packages:      
Sourcecode: hellanzb version File versions  Download package

def Hellanzb::Daemon::initHellaHella (   configFile,
  verbose = False 
)

Initialize hellahella, the web UI 

Definition at line 113 of file Daemon.py.

00113                                                :
    """ Initialize hellahella, the web UI """
    Hellanzb.HELLAHELLA_PORT = 8750
    try:
        import cgi
        from paste.deploy import loadapp
        from twisted.web2.server import Request
        def _parseURL(self):
            if self.uri[0] == '/':
                # Can't use urlparse for request_uri because urlparse
                # wants to be given an absolute or relative URI, not just
                # an abs_path, and thus gets '//foo' wrong.
                self.scheme = self.host = self.path = self.params = self.querystring = ''
                if '?' in self.uri:
                    self.path, self.querystring = self.uri.split('?', 1)
                else:
                    self.path = self.uri
                if ';' in self.path:
                    self.path, self.params = self.path.split(';', 1)
            else:
                # It is an absolute uri, use standard urlparse
                (self.scheme, self.host, self.path,
                 self.params, self.querystring, fragment) = urlparse.urlparse(self.uri)

            if self.querystring:
                self.args = cgi.parse_qs(self.querystring, True)
            else:
                self.args = {}

            ####path = map(unquote, self.path[1:].split('/'))
            path = self.path[1:].split('/')
            if self._initialprepath:
                # We were given an initial prepath -- this is for supporting
                # CGI-ish applications where part of the path has already
                # been processed
                ####prepath = map(unquote, self._initialprepath[1:].split('/'))
                prepath = self._initialprepath[1:].split('/')

                if path[:len(prepath)] == prepath:
                    self.prepath = prepath
                    self.postpath = path[len(prepath):]
                else:
                    self.prepath = []
                    self.postpath = path
            else:
                self.prepath = []
                self.postpath = path

        Request._parseURL = _parseURL

        twistedWeb01 = False
        from twisted.application.service import Application
        try:
            # twistedWeb 0.1
            from twisted.web2.http import HTTPFactory
            twistedWeb01 = True
        except ImportError:
            # twistedWeb 0.2
            from twisted.web2.channel import HTTPFactory
        from twisted.web2.log import LogWrapperResource, DefaultCommonAccessLoggingObserver
        from twisted.web2.server import Site
        from twisted.web2.wsgi import FileWrapper, InputStream, ErrorStream, WSGIHandler, \
            WSGIResource

        # Munge the SCRIPT_NAME to '' when web2 makes it '/'
        from twisted.web2.twcgi import createCGIEnvironment
        if twistedWeb01:
            def setupEnvironment(self, ctx, request):
                # Called in IO thread
                env = createCGIEnvironment(ctx, request)
                if re.compile('\/+').search(env['SCRIPT_NAME']):
                    env['SCRIPT_NAME'] = ''
                env['wsgi.version']      = (1, 0)
                env['wsgi.url_scheme']   = env['REQUEST_SCHEME']
                env['wsgi.input']        = InputStream(request.stream)
                env['wsgi.errors']       = ErrorStream()
                env['wsgi.multithread']  = True
                env['wsgi.multiprocess'] = False
                env['wsgi.run_once']     = False
                env['wsgi.file_wrapper'] = FileWrapper
                self.environment = env
        else:
            def setupEnvironment(self, request):
                # Called in IO thread
                env = createCGIEnvironment(request)
                if re.compile('\/+').search(env['SCRIPT_NAME']):
                    env['SCRIPT_NAME'] = ''
                env['wsgi.version']      = (1, 0)
                env['wsgi.url_scheme']   = env['REQUEST_SCHEME']
                env['wsgi.input']        = InputStream(request.stream)
                env['wsgi.errors']       = ErrorStream()
                env['wsgi.multithread']  = True
                env['wsgi.multiprocess'] = False
                env['wsgi.run_once']     = False
                env['wsgi.file_wrapper'] = FileWrapper
                self.environment = env

        WSGIHandler.setupEnvironment = setupEnvironment

        # incase pylons raises deprecation warnings during loadapp, redirect them to the
        # debug log
        oldStderr = sys.stderr
        sys.stderr = LogOutputStream(debug)

        # Load the wsgi app via paste
        wsgiApp = loadapp('config:' + configFile)

        sys.stderr = oldStderr

        if verbose:
            lwr = LogWrapperResource(WSGIResource(wsgiApp))
            DefaultCommonAccessLoggingObserver().start()
            Hellanzb.hhHTTPFactory = HTTPFactory(Site(lwr))
        else:
            Hellanzb.hhHTTPFactory = HTTPFactory(Site(WSGIResource(wsgiApp)))

        reactor.listenTCP(Hellanzb.HELLAHELLA_PORT, Hellanzb.hhHTTPFactory)
    except Exception, e:
        error('Unable to load hellahella', e)

def resumePostProcessors():


Generated by  Doxygen 1.6.0   Back to index