Post processing

"Adam DePrince, CSA" <[email protected]>
Newsgroups gmane.comp.web.skunkweb
Message-ID <[email protected]>
There is currently no clean way of catching the output of templating and
applying some sort of post processing filter.  I'd added PostProcess
hook to templating.Handler that allows you to modify the outgoing data. 

My motivation was my own itch.  I needed created a way of removing \n's
from the html generated by skunkweb.  Instead of using spool I figured
that in one effort I would:

1. Document and provide a "how to" example on writing a service 
2. To do #1 I wanted to provide something useful, but simple to write,
like an outgoing filtering module.

I'm hoping that skunkweb-3.5b5.template-postprocess-hook.patch would be
accepted into the skunk sources.  

killnewlines.py is a sample/test use of the hook and is not intended for
distribution in skunk.  The killnewlines.py attachment does NOT satisfy
the goals above, albeit specifically useful for me.


-- 
Adam DePrince, CSA <[email protected]>
skunkweb-3.5b5.template-postprocess-hook.patch (text/x-patch, 892 B)
Only in skunkweb-3.4b5-mod/SkunkWeb/Services: killnewlines.py
diff -ur --minimal skunkweb-3.4b5/SkunkWeb/Services/templating/Handler.py skunkweb-3.4b5-mod/SkunkWeb/Services/templating/Handler.py
--- skunkweb-3.4b5/SkunkWeb/Services/templating/Handler.py	2003-08-11 20:48:27.000000000 -0400
+++ skunkweb-3.4b5-mod/SkunkWeb/Services/templating/Handler.py	2003-12-17 10:48:17.000000000 -0500
@@ -23,6 +23,9 @@
 from SkunkWeb.ServiceRegistry import TEMPLATING
 import vfs
 import Date
+from SkunkWeb.Hooks import KeyedHook
+
+PostProcess = KeyedHook()
 
 Configuration.mergeDefaults(
     indexDocuments = ['index.html'],
@@ -136,6 +139,7 @@
         respText = AE.Component.callComponent(
             connObj.uri, {'CONNECTION': connObj},
             srcModTime = modTime)
+        respText = PostProcess( Configuration.job, respText,connObj )
     except Redirect:
         pass
     except:
killnewlines.py (text/x-python, 1.3 KB)
########################################################################
#
#  Copyright (C) 2003 Adam DePrince <[email protected]>
#
#  Derived work of:
#  Copyright (C) 2002, 2003 Andrew T. Csillag <[email protected]>,
#                           Jacob Smullyan <[email protected]>
#
#  
#      You may distribute under the terms of either the GNU General
#      Public License or the SkunkWeb License, as specified in the
#      README file.
#
# graciously contributed by Spruce Weber <[email protected]>
#   
########################################################################



from SkunkWeb import ServiceRegistry, Configuration, constants
ServiceRegistry.registerService('killnewlines')
from SkunkWeb.LogObj import DEBUG, logException
from SkunkWeb.ServiceRegistry import KILLNEWLINES
import re
import sys
from requestHandler.protocol import PreemptiveResponse
from skunklib import normpath

# Configuration.mergeDefaults(killnewlinesAggresive=1)
        
def _rewrite( responseData, connection ):
    return responseData.replace( '\n', '' )
    
def __initHooks():
    import web.protocol as wp
    import SkunkWeb.constants as sc
    import requestHandler.requestHandler as rh
    import templating.Handler as th
    # if Configuration.killnewlinesAggressive:
    th.PostProcess["*"] =  _rewrite


__initHooks()
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.