[z3-checkins] r30823 - in z3/deliverance/branches/packaged: . deliverance deliverance/tests doc

ianb at codespeak.net ianb at codespeak.net
Mon Jul 31 21:14:28 CEST 2006


Author: ianb
Date: Mon Jul 31 21:14:20 2006
New Revision: 30823

Added:
   z3/deliverance/branches/packaged/deliverance/
   z3/deliverance/branches/packaged/deliverance/ThemedHTTPServer.py
      - copied unchanged from r30821, z3/deliverance/branches/packaged/ThemedHTTPServer.py
   z3/deliverance/branches/packaged/deliverance/__init__.py   (contents, props changed)
   z3/deliverance/branches/packaged/deliverance/main.py
      - copied unchanged from r30821, z3/deliverance/branches/packaged/deliverance.py
   z3/deliverance/branches/packaged/deliverance/mpfilter.py
      - copied unchanged from r30821, z3/deliverance/branches/packaged/mpfilter.py
   z3/deliverance/branches/packaged/deliverance/renderer.xsl
      - copied unchanged from r30821, z3/deliverance/branches/packaged/renderer.xsl
   z3/deliverance/branches/packaged/deliverance/tests/
   z3/deliverance/branches/packaged/deliverance/tests/__init__.py   (contents, props changed)
   z3/deliverance/branches/packaged/deliverance/themecompiler.xsl
      - copied unchanged from r30821, z3/deliverance/branches/packaged/themecompiler.xsl
   z3/deliverance/branches/packaged/doc/example-mpfilter.conf
      - copied, changed from r30821, z3/deliverance/branches/packaged/mpfilter.conf
   z3/deliverance/branches/packaged/doc/favicon.ico
      - copied unchanged from r30821, z3/deliverance/branches/packaged/favicon.ico
   z3/deliverance/branches/packaged/setup.py   (contents, props changed)
Removed:
   z3/deliverance/branches/packaged/ThemedHTTPServer.py
   z3/deliverance/branches/packaged/deliverance.py
   z3/deliverance/branches/packaged/favicon.ico
   z3/deliverance/branches/packaged/mpfilter.conf
   z3/deliverance/branches/packaged/mpfilter.py
   z3/deliverance/branches/packaged/renderer.xsl
   z3/deliverance/branches/packaged/themecompiler.xsl
Log:
Moving files around (just moving, not editing yet)

Deleted: /z3/deliverance/branches/packaged/ThemedHTTPServer.py
==============================================================================
--- /z3/deliverance/branches/packaged/ThemedHTTPServer.py	Mon Jul 31 21:14:20 2006
+++ (empty file)
@@ -1,92 +0,0 @@
-"""Simple HTTP Server.
-
-This module builds on BaseHTTPServer by implementing the standard GET
-and HEAD requests in a fairly straightforward manner.
-
-"""
-
-
-__version__ = "0.6"
-
-__all__ = ["ThemedHTTPRequestHandler"]
-
-import os
-import mimetypes
-import BaseHTTPServer
-import SimpleHTTPServer
-from StringIO import StringIO
-
-from deliverance import AppMap
-appmap = AppMap()
-
-
-class ThemedHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
-
-    def send_head(self):
-        """Common code for GET and HEAD commands.
-
-        This sends the response code and MIME headers.
-
-        Return value is either a file object (which has to be copied
-        to the outputfile by the caller unless the command was HEAD,
-        and must be closed by the caller under all circumstances), or
-        None, in which case the caller has nothing further to do.
-
-        """
-        path = self.translate_path(self.path)
-        f = None
-        if os.path.isdir(path):
-            for index in "index.html", "index.htm":
-                index = os.path.join(path, index)
-                if os.path.exists(index):
-                    path = index
-                    break
-            else:
-                return self.list_directory(path)
-        ctype = self.guess_type(path)
-        try:
-            # Always read in binary mode. Opening files in text mode may cause
-            # newline translations, making the actual size of the content
-            # transmitted *less* than the content-length!
-            
-            # This is where we apply theming
-            
-            # First check to see if there is a query string.  If so, presume that 
-            # to mean they want the source version.
-            qs = len(self.path.split("?"))
-            if ctype == "text/html" and qs == 99:
-                print "Applying theme to", path
-                xmlstring = open(path, "r").read()
-                response = appmap.publish(xmlstring)
-                f = StringIO(response)
-                responsesize = str(len(xmlstring))
-            else:
-                f = open(path, 'rb')
-                responsesize = str(os.fstat(f.fileno())[6])
-        except IOError:
-            self.send_error(404, "File not found")
-            return None
-        self.send_response(200)
-        self.send_header("Content-type", ctype)
-        self.send_header("Content-Length", responsesize)
-        self.end_headers()
-        return f
-
-    extensions_map = mimetypes.types_map.copy()
-    extensions_map.update({
-        '': 'application/octet-stream', # Default
-        '.py': 'text/plain',
-        '.c': 'text/plain',
-        '.h': 'text/plain',
-        '.ico': 'image/x-icon',
-        })
-
-    
-
-def test(HandlerClass = ThemedHTTPRequestHandler,
-         ServerClass = BaseHTTPServer.HTTPServer):
-    BaseHTTPServer.test(HandlerClass, ServerClass)
-
-
-if __name__ == '__main__':
-    test()

Deleted: /z3/deliverance/branches/packaged/deliverance.py
==============================================================================
--- /z3/deliverance/branches/packaged/deliverance.py	Mon Jul 31 21:14:20 2006
+++ (empty file)
@@ -1,144 +0,0 @@
-
-import os
-from lxml import etree
-from time import time
-from lxml.etree import Namespace, ElementBase
-
-
-nsmap = {
-    "dv": "http://www.plone.org/deliverance",
-    "html": "http://www.w3.org/1999/xhtml",
-    "xsl": "http://www.w3.org/1999/XSL/Transform",
-    "at": "http://plone.org/archetypes",
-    }
-
-class AppMap:
-
-    def __init__(self):
-        
-        # Open the appmap file, make a tree, and process XIncludes
-        self.module_dir = os.path.dirname(os.path.abspath(__file__))
-        layoutsfn = os.path.join(self.module_dir, "etc/appmap.xml")
-        self.tree = etree.ElementTree(file=layoutsfn)
-        self.tree.xinclude()
-
-        # Make a themeprocessor to style all outgoing pages.  Note that the 
-        # .processor attribute comes from an lxml namespace binding, meaning it is 
-        # defined via a custom Python class defined below (class LayoutElement)
-        root = self.tree.getroot()
-        layout = root.xpath("dv:layouts/dv:layout", nsmap)[0]
-        self.themeprocessor = layout.processor
-
-
-    def publish(self, xmlstring):
-        """Given a string of XML, theme it"""
-        
-        resource = etree.XML(xmlstring)
-        response = str(self.themeprocessor(resource))
-
-        return response
-
-# The following are extensions based on lxml namespace extensions.  It 
-# adds Python behavior to XML nodes.
-
-class DVRuleBase(ElementBase):
-
-    def getThemeNode(self):
-        """Get a node in the theme doc"""
-
-        # Current node is a rule, get xpath from the @theme attr
-        themedoc = self.xpath("../../dv:theme", nsmap)[0][0]
-        xpath = self.get("theme")
-        try:
-            themenode = themedoc.xpath(xpath, nsmap)[0]
-        except IndexError:
-            msg = "Themedoc has no node at: %s" % xpath
-            print msg
-            themenode = None
-
-        return themenode
-
-
-class LayoutElement(ElementBase):
-
-    def processor(self):
-        """Make XSLT processor by changing theme based on rules"""
-
-        # Apply all the rules
-        for rule in self.xpath("./dv:rules/*", nsmap):
-            rule.apply()
-
-        # Merge applied rules into compilerdoc
-        compilerroot = self.xpath("../dv:compiler/xsl:stylesheet", nsmap)[0]
-        themeroot = self.xpath("dv:theme/html:html", nsmap)[0]
-        target = compilerroot.xpath("xsl:template[@match='/']", nsmap)[0]
-        target.append(themeroot)
-        
-        #print etree.tostring(compilerroot)
-
-        return etree.XSLT(compilerroot)
-    
-    processor = property(processor)
-        
-
-class RuleReplaceElement(DVRuleBase):
-
-    def apply(self):
-        # TODO: Someething here
-        themenode = self.getThemeNode()
-        if themenode is None:
-            return
-        del(themenode[:])
-        themenode.text = None
-        xslvalueof = etree.SubElement(themenode,
-                                      "{%s}value-of" % nsmap["xsl"])
-        xslvalueof.set("select", self.get("content"))
-
-
-class RuleCopyElement(DVRuleBase):
-
-    def apply(self):
-        themenode = self.getThemeNode()
-        if themenode is None:
-            return
-        del(themenode[:])
-        themenode.text = None
-        xslvalueof = etree.SubElement(themenode,
-                                      "{%s}apply-templates" % nsmap["xsl"])
-        xslvalueof.set("select", self.get("content"))
-
-
-class RuleAppendElement(DVRuleBase):
-
-    def apply(self):
-        themenode = self.getThemeNode()
-        if themenode is None:
-            return
-        xslvalueof = etree.SubElement(themenode,
-                                      "{%s}apply-templates" % nsmap["xsl"])
-        xslvalueof.set("select", self.get("content"))
-
-
-# Bind Python classes for lxml namespace support
-namespace = Namespace(nsmap['dv'])
-namespace['layout'] = LayoutElement
-namespace['replace'] = RuleReplaceElement
-namespace['copy'] = RuleCopyElement
-namespace['append'] = RuleAppendElement
-    
-
-def timeit(xmlstring):
-    appmap = AppMap()
-    start = time()
-    iters = 50
-    for i in range(iters):
-        result = appmap.publish(xmlstring)
-    print "*** Average time:", (time() - start) / iters, " ***\n"
-    print result[0:2000]
-    
-def main():
-    xmlstring = open("content/index.html").read()
-    timeit(xmlstring)
-    
-if __name__ == "__main__":
-    main()

Added: z3/deliverance/branches/packaged/deliverance/__init__.py
==============================================================================
--- (empty file)
+++ z3/deliverance/branches/packaged/deliverance/__init__.py	Mon Jul 31 21:14:20 2006
@@ -0,0 +1 @@
+#

Added: z3/deliverance/branches/packaged/deliverance/tests/__init__.py
==============================================================================
--- (empty file)
+++ z3/deliverance/branches/packaged/deliverance/tests/__init__.py	Mon Jul 31 21:14:20 2006
@@ -0,0 +1 @@
+#

Copied: z3/deliverance/branches/packaged/doc/example-mpfilter.conf (from r30821, z3/deliverance/branches/packaged/mpfilter.conf)
==============================================================================
--- z3/deliverance/branches/packaged/mpfilter.conf	(original)
+++ z3/deliverance/branches/packaged/doc/example-mpfilter.conf	Mon Jul 31 21:14:20 2006
@@ -5,7 +5,7 @@
 LoadModule python_module modules/mod_python.so
 
 <Directory /Users/paul/sandboxes/z3/deliverance/branches/namespaced>
-  PythonOutputFilter mpfilter DELIVERANCE
+  PythonOutputFilter deliverance.mpfilter DELIVERANCE
   AddOutputFilter DELIVERANCE .html
   PythonDebug On
 </Directory>

Deleted: /z3/deliverance/branches/packaged/favicon.ico
==============================================================================
Binary file. No diff available.

Deleted: /z3/deliverance/branches/packaged/mpfilter.conf
==============================================================================
--- /z3/deliverance/branches/packaged/mpfilter.conf	Mon Jul 31 21:14:20 2006
+++ (empty file)
@@ -1,11 +0,0 @@
-# This module can be pointed to from your main Apache 
-# configuration file to apply a theme to certain parts of your
-# URL space.
-
-LoadModule python_module modules/mod_python.so
-
-<Directory /Users/paul/sandboxes/z3/deliverance/branches/namespaced>
-  PythonOutputFilter mpfilter DELIVERANCE
-  AddOutputFilter DELIVERANCE .html
-  PythonDebug On
-</Directory>

Deleted: /z3/deliverance/branches/packaged/mpfilter.py
==============================================================================
--- /z3/deliverance/branches/packaged/mpfilter.py	Mon Jul 31 21:14:20 2006
+++ (empty file)
@@ -1,70 +0,0 @@
-"""
-Deliverance theming for mod_python filters
-
-Deliverance applies a theme to content.  This mod_python module acts as an 
-Apache "filter", transforming content as it passes through Apache.
-
-This module gets imported by mod_python during its startup.  Thus, the 
-appmap instance becomes a global, computed only once.  If you need to 
-recompute the theme, for example, restart the Apache.
-"""
-import time
-from cStringIO import StringIO
-
-from mod_python import apache
-from deliverance import AppMap
-appmap = AppMap() # Theme is generated once at module import time
-
-def outputfilter(filter):
-    if not hasattr(filter.req, 'notheme'):
-        # Check for a flag to not apply theme
-        args = filter.req.args
-        if args and args.find("notheme") > -1:
-            filter.req.notheme = True
-        else:
-            filter.req.notheme = False
-            
-    try:
-        streambuffer = filter.req.streambuffer
-    except AttributeError:
-        if filter.req.notheme:
-            # pass on if no theme
-            filter.pass_on()
-            return
-        elif not filter.req.headers_out.has_key("content-type"):
-            # pass on if no content type specified
-            filter.pass_on()
-            return
-        elif not filter.req.headers_out["content-type"].startswith("text/html"):
-            # pass on if not HTML
-            filter.pass_on()
-            return
-
-        filter.req.streambuffer = StringIO()
-        streambuffer = filter.req.streambuffer
-
-    streamlet = filter.readline()
-    while streamlet:
-        streambuffer.write(streamlet)
-        streamlet = filter.readline()
-
-    if streamlet is None:
-        output = appmap.publish(streambuffer.getvalue())
-        filter.req.headers_out["Content-Length"] = str(len(output))
-        filter.write(output)
-        filter.close()
-
-
-def handler(req):
-    """Basic filter applying to all mime types it is registered for"""
-
-    # Get the path, strip off leading slash, and convert to a 
-    # dotted notation for xml:id compatibility
-    path_info = req.path_info[1:]
-    dotted_path = path_info.replace("/", ".")
-
-    response = appmap.publish(dotted_path)
-    req.content_type = "text/html"
-    req.write(response)
-
-    return apache.OK

Deleted: /z3/deliverance/branches/packaged/renderer.xsl
==============================================================================
--- /z3/deliverance/branches/packaged/renderer.xsl	Mon Jul 31 21:14:20 2006
+++ (empty file)
@@ -1,67 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
-    xmlns:trois="http://www.plone.org/trois" xmlns="http://www.w3.org/1999/xhtml"
-    xmlns:html="http://www.w3.org/1999/xhtml"
-    xmlns:at="http://plone.org/archetypes" exclude-result-prefixes="trois at html" version="1.0">
-    <xsl:output indent="yes"/>
-    <xsl:param name="pathinfo">localhello</xsl:param>
-    <xsl:param name="siteurl">/sandboxes/trois/trunk/deliverance/examples/plonenet.py</xsl:param>
-    <xsl:variable name="contentnode" select="id($pathinfo)"/>
-    <xsl:template match="/">
-        <html xmlns="http://www.w3.org/1999/xhtml">
-            <head>
-                <title>
-                    <xsl:value-of select="$contentnode/@title"/>
-                </title>
-            </head>
-            <body>
-                <div id="navtree">
-                    <xsl:apply-templates select="id('root')" mode="navtree"/>
-                </div>
-                <div id="pagecontent">
-                    <xsl:apply-templates select="$contentnode"/>
-
-                </div>
-
-            </body>
-        </html>
-    </xsl:template>
-    <xsl:template match="at:collection" mode="navtree">
-        <div
-            style="float:left; width: 10em; background-color: yellow; height: 10em; margin-right: 5em">
-            <h2 style="text-align: center">sitenav</h2>
-            <ul>
-                <xsl:for-each select=".//*[@name]">
-                    <li>
-                        <a href="{$siteurl}/{@name}">
-                            <xsl:value-of select="@title"/>
-                        </a>
-                    </li>
-                </xsl:for-each>
-            </ul>
-
-        </div>
-    </xsl:template>
-
-    <xsl:template match="at:providers">
-        <ul>
-            <li>Item one</li>
-            <xsl:for-each select="at:provider">
-                <li>
-                    <xsl:value-of select="@title"/>
-                </li>
-            </xsl:for-each>
-        </ul>
-    </xsl:template>
-    
-    <xsl:template match="at:provider">
-        <p>
-            <xsl:value-of select="@title"/>
-        </p>
-    </xsl:template>
-
-    <xsl:template match="at:localfile">
-        <xsl:copy-of select="html:html/html:body/*"/>
-    </xsl:template>
-    
-</xsl:stylesheet>

Added: z3/deliverance/branches/packaged/setup.py
==============================================================================
--- (empty file)
+++ z3/deliverance/branches/packaged/setup.py	Mon Jul 31 21:14:20 2006
@@ -0,0 +1,27 @@
+__version__ = '0.1'
+
+from setuptools import setup, find_packages
+
+setup(name="Deliverance",
+      version=__version__,
+      description="",
+      long_description="""\
+""",
+      classifiers=[
+        # dev status, license, HTTP categories
+        ],
+      keywords='',
+      author="Paul Everitt",
+      author_email="",
+      url="",
+      license="",
+      packages=find_packages(exclude=[]),
+      zip_safe=False,
+      install_requires=[
+        'lxml',
+      ],
+      entry_points="""
+      """,
+      )
+
+

Deleted: /z3/deliverance/branches/packaged/themecompiler.xsl
==============================================================================
--- /z3/deliverance/branches/packaged/themecompiler.xsl	Mon Jul 31 21:14:20 2006
+++ (empty file)
@@ -1,16 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
-    xmlns="http://www.w3.org/1999/xhtml" xmlns:html="http://www.w3.org/1999/xhtml"
-    exclude-result-prefixes="html" version="1.0">
-    <!-- Theme compiler.  Applied to the rule file to generate 
-        an XSLT that gets applied to content. -->
-    <xsl:output indent="yes" method="xml"/>
-    <xsl:template match="/">
-        <!-- The compiled theme gets shoved in here -->
-    </xsl:template>
-    <xsl:template match="node()|@*">
-        <xsl:copy>
-            <xsl:apply-templates select="node()|@*"/>
-        </xsl:copy>
-    </xsl:template>
-</xsl:stylesheet>


More information about the z3-checkins mailing list