Пример #1
0
def blosxom_handler(request):
    """
    This is the default blosxom handler.
    """
    import cgi

    config = request.getConfiguration()
    data = request.getData()

    # go through the renderer callback to see if anyone else
    # wants to render.  this renderer gets stored in the data dict 
    # for downstream processing.
    r = tools.run_callback('renderer', 
                           {'request': request},
                           donefunc = lambda x: x != None, 
                           defaultfunc = lambda x: None)

    if not r:
        # get the renderer we want to use
        r = config.get("renderer", "blosxom")

        # import the renderer
        r = tools.importName("renderers", r)

        # get the renderer object
        r = r.Renderer(request, config.get("stdoutput", sys.stdout))

    data['renderer'] = r

    #why in the world isn't this done in pyblosxom.cgi?
    request.addHttp( {"form": cgi.FieldStorage() } )
    # process the path info to determine what kind of blog entry(ies) 
    # this is
    tools.run_callback("pathinfo",
                           {"request": request},
                           donefunc=lambda x:x != None,
                           defaultfunc=blosxom_process_path_info)

    # call the filelist callback to generate a list of entries
    data["entry_list"] = tools.run_callback("filelist",
                               {"request": request},
                               donefunc=lambda x:x != None,
                               defaultfunc=blosxom_file_list_handler)

    # we pass the request with the entry_list through the prepare callback
    # giving everyone a chance to transform the data.  the request is
    # modified in place.
    tools.run_callback("prepare", {"request": request})

    # now we pass the entry_list through the renderer
    entry_list = data["entry_list"]
    renderer = data['renderer']

    if renderer and not renderer.rendered:
        if entry_list:
            renderer.setContent(entry_list)
            # Log it as success
            tools.run_callback("logrequest", 
                    {'filename':config.get('logfile',''), 
                     'return_code': '200', 
                     'request': request})
        else:
            renderer.addHeader('Status', '404 Not Found')
            renderer.setContent(
                {'title': 'The page you are looking for is not available',
                 'body': 'Somehow I cannot find the page you want. ' + 
                 'Go Back to <a href="%s">%s</a>?' 
                 % (config["base_url"], config["blog_title"])})
            # Log it as failure
            tools.run_callback("logrequest", 
                    {'filename':config.get('logfile',''), 
                     'return_code': '404', 
                     'request': request})
        renderer.render()

    elif not renderer:
        output = config.get('stdoutput', sys.stdout)
        output.write("Content-Type: text/plain\n\nThere is something wrong with your setup.\n  Check your config files and verify that your configuration is correct.\n")
Пример #2
0
def blosxom_handler(request):
    """
    This is the default blosxom handler.
    """
    import cgi

    config = request.getConfiguration()
    data = request.getData()

    # go through the renderer callback to see if anyone else
    # wants to render.  this renderer gets stored in the data dict
    # for downstream processing.
    r = tools.run_callback('renderer', {'request': request},
                           donefunc=lambda x: x != None,
                           defaultfunc=lambda x: None)

    if not r:
        # get the renderer we want to use
        r = config.get("renderer", "blosxom")

        # import the renderer
        r = tools.importName("renderers", r)

        # get the renderer object
        r = r.Renderer(request, config.get("stdoutput", sys.stdout))

    data['renderer'] = r

    #why in the world isn't this done in pyblosxom.cgi?
    request.addHttp({"form": cgi.FieldStorage()})
    # process the path info to determine what kind of blog entry(ies)
    # this is
    tools.run_callback("pathinfo", {"request": request},
                       donefunc=lambda x: x != None,
                       defaultfunc=blosxom_process_path_info)

    # call the filelist callback to generate a list of entries
    data["entry_list"] = tools.run_callback(
        "filelist", {"request": request},
        donefunc=lambda x: x != None,
        defaultfunc=blosxom_file_list_handler)

    # we pass the request with the entry_list through the prepare callback
    # giving everyone a chance to transform the data.  the request is
    # modified in place.
    tools.run_callback("prepare", {"request": request})

    # now we pass the entry_list through the renderer
    entry_list = data["entry_list"]
    renderer = data['renderer']

    if renderer and not renderer.rendered:
        if entry_list:
            renderer.setContent(entry_list)
            # Log it as success
            tools.run_callback(
                "logrequest", {
                    'filename': config.get('logfile', ''),
                    'return_code': '200',
                    'request': request
                })
        else:
            renderer.addHeader('Status', '404 Not Found')
            renderer.setContent({
                'title':
                'The page you are looking for is not available',
                'body':
                'Somehow I cannot find the page you want. ' +
                'Go Back to <a href="%s">%s</a>?' %
                (config["base_url"], config["blog_title"])
            })
            # Log it as failure
            tools.run_callback(
                "logrequest", {
                    'filename': config.get('logfile', ''),
                    'return_code': '404',
                    'request': request
                })
        renderer.render()

    elif not renderer:
        output = config.get('stdoutput', sys.stdout)
        output.write(
            "Content-Type: text/plain\n\nThere is something wrong with your setup.\n  Check your config files and verify that your configuration is correct.\n"
        )
Пример #3
0
    def run(self):
        """
        Main loop for pyblosxom.
        """
        config = self._request.getConfiguration()
        data = self._request.getData()

        # import and initialize plugins
        import plugin_utils
        plugin_utils.initialize_plugins(config)

        # inject our own startup into the callback thing
        plugin_utils.callbacks.setdefault("startup", []).append(self.startup)

        # get the renderer we want to use
        r = config.get("renderer", "blosxom")

        # import the renderer
        r = tools.importName("Pyblosxom.renderers", r)

        # get the renderer object
        r = r.Renderer(self._request, config.get("stdoutput", sys.stdout))

        # go through the renderer callback to see if anyone else
        # wants to render.  the default is the renderer object we
        # figured out from above.  this renderer gets stored in
        # the data dict for downstream processing.
        data['renderer'] = tools.run_callback('renderer', 
                                 {'request': self._request},
                                 donefunc = lambda x: x != None, 
                                 defaultfunc = lambda x: r)
        
        # do start callback
        tools.run_callback("start", {'request': self._request})

        # entryparser callback is runned first here to allow other plugins
        # register what file extensions can be used
        data['extensions'] = tools.run_callback("entryparser",
                                        {'txt': self.defaultEntryParser},
                                        mappingfunc=lambda x,y:y,
                                        defaultfunc=lambda x:x)

        # process the path info to determine what kind of blog entry(ies) 
        # this is
        tools.run_callback("pathinfo",
                           {"request": self._request},
                           donefunc=lambda x:x != None,
                           defaultfunc=self.processPathInfo)

        # call the filelist callback to generate a list of entries
        data["entry_list"] = tools.run_callback("filelist",
                                   {"request": self._request},
                                   donefunc=lambda x:x != None,
                                   defaultfunc=self.defaultFileListHandler)
        
        # we pass the request with the entry_list through the prepare callback
        # giving everyone a chance to transform the data.  the request is
        # modified in place.
        tools.run_callback("prepare", {"request": self._request})

        # now we pass the entry_list through the renderer
        entry_list = data["entry_list"]
        renderer = data['renderer']

        if renderer and not renderer.rendered:
            if entry_list:
                renderer.setContent(entry_list)
                # Log it as success
                tools.run_callback("logrequest", 
                        {'filename':config.get('logfile',''), 
                         'return_code': '200', 
                         'request': self._request})
            else:
                renderer.addHeader('Status', '404 Not Found')
                renderer.setContent(
                    {'title': 'The page you are looking for is not available',
                     'body': 'Somehow I cannot find the page you want. ' + 
                     'Go Back to <a href="%s">%s</a>?' 
                     % (config["base_url"], config["blog_title"])})
                # Log it as failure
                tools.run_callback("logrequest", 
                        {'filename':config.get('logfile',''), 
                         'return_code': '404', 
                         'request': self._request})
            renderer.render()

            # do end callback
            tools.run_callback("end", {'request':self._request})

        elif not renderer:
            output = config.get('stdoutput', sys.stdout)
            output.write("Content-Type: text/plain\n\nThere is something wrong with your setup.\n  Check your config files and verify that your configuration is correct.\n")