[Repoze-checkins] r1201 - in repoze.debug/trunk/repoze/debug: . static

Paul Everitt paul at agendaless.com
Mon Jun 30 12:20:56 EDT 2008


Author: Paul Everitt <paul at agendaless.com>
Date: Mon Jun 30 12:20:56 2008
New Revision: 1201

Log:
Generate the atom:content part of each entry. This serializes the request and response into a stable format that the browser can pick data out of.  Where possible, pick apart the response body.

Modified:
   repoze.debug/trunk/repoze/debug/static/debugui-html.css
   repoze.debug/trunk/repoze/debug/static/debugui-html.xsl
   repoze.debug/trunk/repoze/debug/static/debugui-xul.xsl
   repoze.debug/trunk/repoze/debug/static/samplefeed.xml
   repoze.debug/trunk/repoze/debug/ui.py

Modified: repoze.debug/trunk/repoze/debug/static/debugui-html.css
==============================================================================
--- repoze.debug/trunk/repoze/debug/static/debugui-html.css	(original)
+++ repoze.debug/trunk/repoze/debug/static/debugui-html.css	Mon Jun 30 12:20:56 2008
@@ -6,7 +6,7 @@
     position: absolute;
     top: 0;
     left: 0;
-    width: 230px;
+    width: 280px;
     height: 100%;
     background-color: silver;
     color: black;
@@ -15,10 +15,11 @@
 #logtree {
     margin: 0.4em;
     height: 90%;
-    padding: 0.2em
+    padding: 0.2em;
+    font-size: smaller;
 }
 #selected-entry {
-    margin-left: 260px;
+    margin-left: 310px;
 }
 .tree-group, .tree-item-entry {
     margin-bottom: 0.6em;

Modified: repoze.debug/trunk/repoze/debug/static/debugui-html.xsl
==============================================================================
--- repoze.debug/trunk/repoze/debug/static/debugui-html.xsl	(original)
+++ repoze.debug/trunk/repoze/debug/static/debugui-html.xsl	Mon Jun 30 12:20:56 2008
@@ -2,7 +2,7 @@
 <xsl:stylesheet xmlns="http://www.w3.org/1999/xhtml" xmlns:atom="http://www.w3.org/2005/Atom"
     xmlns:rz="http://repoze.org/namespace" exclude-result-prefixes="atom rz"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
-    <xsl:key name="getsubentry" match="atom:entry" use="atom:content/rz:entry/rz:request/@tid"/>
+    <xsl:key name="getsubentry" match="atom:entry" use="atom:content/rz:logentry/rz:request/@tid"/>
     <xsl:output method="html" indent="yes"/>
     <xsl:param name="items-style">flat</xsl:param>
     <xsl:template match="/">
@@ -37,7 +37,7 @@
     -->
     <xsl:template match="/atom:feed" mode="tree">
         <div>
-            <xsl:apply-templates select="atom:entry[atom:content/rz:entry/rz:response/@tid]"
+            <xsl:apply-templates select="atom:entry[atom:content/rz:logentry/rz:response/@tid]"
                 mode="tree-group"/>
         </div>
     </xsl:template>
@@ -45,7 +45,7 @@
         <!-- The parent request is the one with a @tid on the response -->
         <div class="tree-group">
             <xsl:apply-templates select="." mode="item"/>
-            <xsl:variable name="thistid" select="atom:content/rz:entry/rz:response/@tid"/>
+            <xsl:variable name="thistid" select="atom:content/rz:logentry/rz:response/@tid"/>
             <div class="tree-item">
                 <xsl:apply-templates select="key('getsubentry', $thistid)" mode="item"/>
             </div>

Modified: repoze.debug/trunk/repoze/debug/static/debugui-xul.xsl
==============================================================================
--- repoze.debug/trunk/repoze/debug/static/debugui-xul.xsl	(original)
+++ repoze.debug/trunk/repoze/debug/static/debugui-xul.xsl	Mon Jun 30 12:20:56 2008
@@ -4,27 +4,27 @@
 <xsl:stylesheet xmlns:atom="http://www.w3.org/2005/Atom" xmlns:rz="http://repoze.org/namespace"
     exclude-result-prefixes="atom rz" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
     <xsl:output indent="yes"/>
-    <xsl:key name="getsubentry" match="atom:entry" use="atom:content/rz:entry/rz:request/@tid"/>
+    <xsl:key name="getsubentry" match="atom:entry" use="atom:content/rz:logentry/rz:request/@tid"/>
     <xsl:template match="/">
                 <xsl:apply-templates select="atom:feed" mode="tree"/>
     </xsl:template>
     <xsl:template match="atom:feed" mode="tree">
         <!-- Recurse into the feed and make data to load into the tree -->
         <log>
-            <xsl:apply-templates select="atom:entry[atom:content/rz:entry/rz:response/@tid]"
+            <xsl:apply-templates select="atom:entry[atom:content/rz:logentry/rz:response/@tid]"
                 mode="entry"/>
         </log>
     </xsl:template>
     <xsl:template match="atom:entry" mode="entry">
         <!-- The parent request is the one with a @tid on the response -->
-        <entry entryid="{atom:id}" name="{atom:title}" elapsed="{atom:content/rz:entry/@elapsed}">
-            <xsl:variable name="thistid" select="atom:content/rz:entry/rz:response/@tid"/>
+        <entry entryid="{atom:id}" name="{atom:title}" elapsed="{atom:content/rz:logentry/@elapsed}">
+            <xsl:variable name="thistid" select="atom:content/rz:logentry/rz:response/@tid"/>
             <xsl:apply-templates select="key('getsubentry', $thistid)" mode="item"/>
             <!-- <xsl:apply-templates
-                select="/atom:feed/atom:entry[atom:content/rz:entry/rz:request/@tid=$thistid]" mode="item"/>-->
+                select="/atom:feed/atom:entry[atom:content/rz:logentry/rz:request/@tid=$thistid]" mode="item"/>-->
         </entry>
     </xsl:template>
     <xsl:template match="atom:entry" mode="item">
-        <item entryid="{atom:id}" name="{atom:title}" elapsed="{atom:content/rz:entry/@elapsed}"/>
+        <item entryid="{atom:id}" name="{atom:title}" elapsed="{atom:content/rz:logentry/@elapsed}"/>
     </xsl:template>
 </xsl:stylesheet>

Modified: repoze.debug/trunk/repoze/debug/static/samplefeed.xml
==============================================================================
--- repoze.debug/trunk/repoze/debug/static/samplefeed.xml	(original)
+++ repoze.debug/trunk/repoze/debug/static/samplefeed.xml	Mon Jun 30 12:20:56 2008
@@ -1,40 +1,87 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<feed xmlns="http://www.w3.org/2005/Atom" xmlns:rz="http://repoze.org/namespace">
-    <title>Example Feed</title>
-    <link href="http://example.org/"/>
-    <updated>2003-12-13T18:30:02Z</updated>
-    <author>
-        <name>John Doe</name>
-    </author>
-    <id>urn:uuid:60a76c80-d399-11d9-b93C-0003a39e9bf6</id>
-    <updated>2003-12-13T18:30:02Z</updated>
+<atom:feed xmlns:atom="http://www.w3.org/2005/Atom" xmlns:rz="http://repoze.org/namespace">
+    <atom:title>Example Feed</atom:title>
+    <atom:link href="http://example.org/"/>
+    <atom:updated>2003-12-13T18:30:02Z</atom:updated>
+    <atom:author>
+        <atom:name>John Doe</atom:name>
+    </atom:author>
+    <atom:id>urn:uuid:60a76c80-d399-11d9-b93C-0003a39e9bf6</atom:id>
+    <atom:updated>2003-12-13T18:30:02Z</atom:updated>
 
-    <entry>
-        <id>urn:uuid:20323</id>
-        <title>/profile/paul/edit.html</title>
-        <link href="http://www.google.com/"/>
-        <updated>2003-12-13T18:31:01Z</updated>
-        <content>
-            <rz:entry elapsed="32.0">
-                <rz:request/>
-                <rz:response tid="1744480">
-                    <rz:body>
-                        <response>
-                            <view id="profile-edit">
-                                <formcontroller type="Profile" mode="edit"/>
-                            </view>
-                        </response>
-                    </rz:body>
-                </rz:response>
-            </rz:entry>
-        </content>
-    </entry>
-    <entry>
-        <id>urn:uuid:a1</id>
-        <title>/typedefs.xml</title>
-        <updated>2003-12-13T18:31:02Z</updated>
-        <content>
-            <rz:entry elapsed="0.9">
+    <atom:entry>
+        <atom:id>urn:uuid:20323</atom:id>
+        <atom:title>/profile/paul/edit.html</atom:title>
+        <atom:link href="http://www.google.com/"/>
+        <atom:updated>2003-12-13T18:31:01Z</atom:updated>
+        <atom:content>
+            <rz:logentry id="1214835124.656971">
+                <rz:request>
+                    <rz:begin>1214835124.656971</rz:begin>
+                    <rz:cgi_variable name="CONTENT_LENGTH">0</rz:cgi_variable>
+                    <rz:cgi_variable name="HTTP_ACCEPT"
+                        >text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8</rz:cgi_variable>
+                    <rz:cgi_variable name="HTTP_ACCEPT_CHARSET">ISO-8859-1,utf-8;q=0.7,*;q=0.7</rz:cgi_variable>
+                    <rz:cgi_variable name="HTTP_ACCEPT_ENCODING">gzip,deflate</rz:cgi_variable>
+                    <rz:cgi_variable name="HTTP_ACCEPT_LANGUAGE">en-us,en;q=0.5</rz:cgi_variable>
+                    <rz:cgi_variable name="HTTP_CACHE_CONTROL">max-age=0</rz:cgi_variable>
+                    <rz:cgi_variable name="HTTP_CONNECTION">keep-alive</rz:cgi_variable>
+                    <rz:cgi_variable name="HTTP_HOST">localhost:8090</rz:cgi_variable>
+                    <rz:cgi_variable name="HTTP_KEEP_ALIVE">300</rz:cgi_variable>
+                    <rz:cgi_variable name="HTTP_USER_AGENT">Mozilla/5.0 (Macintosh; U; Intel Mac OS
+                        X 10.5; en-US; rv:1.9) Gecko/2008061004 Firefox/3.0</rz:cgi_variable>
+                    <rz:cgi_variable name="PATH_INFO">/foo4</rz:cgi_variable>
+                    <rz:cgi_variable name="REMOTE_ADDR">127.0.0.1</rz:cgi_variable>
+                    <rz:cgi_variable name="REQUEST_METHOD">GET</rz:cgi_variable>
+                    <rz:cgi_variable name="SERVER_NAME">127.0.0.1</rz:cgi_variable>
+                    <rz:cgi_variable name="SERVER_PORT">8090</rz:cgi_variable>
+                    <rz:cgi_variable name="SERVER_PROTOCOL">HTTP/1.1</rz:cgi_variable>
+                    <rz:method>GET</rz:method>
+                    <rz:url>http://localhost:8090/foo4</rz:url>
+                    <rz:wsgi_variable name="application">&lt;myapp.MyApp object at
+                        0x7821b0&gt;</rz:wsgi_variable>
+                    <rz:wsgi_variable name="paste.httpserver.thread_pool"
+                        >&lt;paste.httpserver.ThreadPool object at 0x77fff0&gt;</rz:wsgi_variable>
+                    <rz:wsgi_variable name="wsgi process">Multithreaded</rz:wsgi_variable>
+                    <rz:wsgi_variable name="response"/>
+                </rz:request>
+                <rz:response>
+                    <rz:begin>1214835124.6575179</rz:begin>
+                    <rz:end>1214835124.6586039</rz:end>
+                    <rz:content-length>20</rz:content-length>
+                    <rz:header name="content-type">text/html; charset=UTF-8</rz:header>
+                    <rz:header name="Content-Length">20</rz:header>
+                    <rz:status>200 OK</rz:status>
+                    <rz:body>
+                        <h1>Test Mode 2</h1>
+                    </rz:body>
+                </rz:response>
+            </rz:logentry>
+        </atom:content>
+        <atom:summary>{'id': 1214835124.656971, 'request': {'begin': 1214835124.656971,
+            'cgi_variables': [('CONTENT_LENGTH', '0'), ('HTTP_ACCEPT',
+            'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'),
+            ('HTTP_ACCEPT_CHARSET', 'ISO-8859-1,utf-8;q=0.7,*;q=0.7'), ('HTTP_ACCEPT_ENCODING',
+            'gzip,deflate'), ('HTTP_ACCEPT_LANGUAGE', 'en-us,en;q=0.5'), ('HTTP_CACHE_CONTROL',
+            'max-age=0'), ('HTTP_CONNECTION', 'keep-alive'), ('HTTP_HOST', 'localhost:8090'),
+            ('HTTP_KEEP_ALIVE', '300'), ('HTTP_USER_AGENT', 'Mozilla/5.0 (Macintosh; U; Intel Mac OS
+            X 10.5; en-US; rv:1.9) Gecko/2008061004 Firefox/3.0'), ('PATH_INFO', '/foo4'),
+            ('REMOTE_ADDR', '127.0.0.1'), ('REQUEST_METHOD', 'GET'), ('SERVER_NAME', '127.0.0.1'),
+            ('SERVER_PORT', '8090'), ('SERVER_PROTOCOL', 'HTTP/1.1')], 'method': 'GET', 'url':
+            'http://localhost:8090/foo4', 'wsgi_variables': [('application', &lt;myapp.MyApp
+            object at 0x7821b0&gt;), ('paste.httpserver.thread_pool',
+            &lt;paste.httpserver.ThreadPool object at 0x77fff0&gt;), ('wsgi process',
+            'Multithreaded')]}, 'response': {'begin': 1214835124.6575179, 'body':
+            '&lt;h1&gt;Test Mode 2&lt;/h1&gt;', 'content-length': 20, 'end':
+            1214835124.6586039, 'headers': [('content-type', 'text/html; charset=UTF-8'),
+            ('Content-Length', '20')], 'status': '200 OK'}}</atom:summary>
+    </atom:entry>
+    <atom:entry>
+        <atom:id>urn:uuid:a1</atom:id>
+        <atom:title>/typedefs.xml</atom:title>
+        <atom:updated>2003-12-13T18:31:02Z</atom:updated>
+        <atom:content>
+            <rz:logentry>
                 <rz:request tid="1744480"/>
                 <rz:response>
                     <rz:body>
@@ -43,15 +90,15 @@
                         </typedefs>
                     </rz:body>
                 </rz:response>
-            </rz:entry>
-        </content>
-    </entry>
-    <entry>
-        <id>urn:uuid:a2</id>
-        <title>/user.xml</title>
-        <updated>2003-12-13T18:31:03Z</updated>
-        <content>
-            <rz:entry elapsed="12.7">
+            </rz:logentry>
+        </atom:content>
+    </atom:entry>
+    <atom:entry>
+        <atom:id>urn:uuid:a2</atom:id>
+        <atom:title>/user.xml</atom:title>
+        <atom:updated>2003-12-13T18:31:03Z</atom:updated>
+        <atom:content>
+            <rz:logentry>
                 <rz:request tid="1744480"/>
                 <rz:response>
                     <rz:body>
@@ -60,19 +107,19 @@
                         </user>
                     </rz:body>
                 </rz:response>
-            </rz:entry>
-        </content>
-    </entry>
+            </rz:logentry>
+        </atom:content>
+    </atom:entry>
 
 
 
 
-    <entry>
-        <id>urn:uuid:734661</id>
-        <title>/communities</title>
-        <updated>2003-12-13T18:31:04Z</updated>
-        <content>
-            <rz:entry elapsed="23.1">
+    <atom:entry>
+        <atom:id>urn:uuid:734661</atom:id>
+        <atom:title>/communities</atom:title>
+        <atom:updated>2003-12-13T18:31:04Z</atom:updated>
+        <atom:content>
+            <rz:logentry>
                 <rz:response tid="92394480">
                     <rz:body>
                         <user>
@@ -80,15 +127,15 @@
                         </user>
                     </rz:body>
                 </rz:response>
-            </rz:entry>
-        </content>
-    </entry>
-    <entry>
-        <id>urn:uuid:b2</id>
-        <title>/user.xml</title>
-        <updated>2003-12-13T18:31:05Z</updated>
-        <content>
-            <rz:entry elapsed="14.9">
+            </rz:logentry>
+        </atom:content>
+    </atom:entry>
+    <atom:entry>
+        <atom:id>urn:uuid:b2</atom:id>
+        <atom:title>/user.xml</atom:title>
+        <atom:updated>2003-12-13T18:31:05Z</atom:updated>
+        <atom:content>
+            <rz:logentry>
                 <rz:request tid="92394480"/>
                 <rz:response>
                     <rz:body>
@@ -97,15 +144,15 @@
                         </user>
                     </rz:body>
                 </rz:response>
-            </rz:entry>
-        </content>
-    </entry>
-    <entry>
-        <id>urn:uuid:b3</id>
-        <title>siteconfig.xml</title>
-        <updated>2003-12-13T18:31:06Z</updated>
-        <content>
-            <rz:entry elapsed="4.8">
+            </rz:logentry>
+        </atom:content>
+    </atom:entry>
+    <atom:entry>
+        <atom:id>urn:uuid:b3</atom:id>
+        <atom:title>siteconfig.xml</atom:title>
+        <atom:updated>2003-12-13T18:31:06Z</atom:updated>
+        <atom:content>
+            <rz:logentry>
                 <rz:request tid="92394480"/>
                 <rz:response>
                     <rz:body>
@@ -114,7 +161,7 @@
                         </siteconfig>
                     </rz:body>
                 </rz:response>
-            </rz:entry>
-        </content>
-    </entry>
-</feed>
+            </rz:logentry>
+        </atom:content>
+    </atom:entry>
+</atom:feed>

Modified: repoze.debug/trunk/repoze/debug/ui.py
==============================================================================
--- repoze.debug/trunk/repoze/debug/ui.py	(original)
+++ repoze.debug/trunk/repoze/debug/ui.py	Mon Jun 30 12:20:56 2008
@@ -78,14 +78,80 @@
 
         for entry in self.middleware.entries:
             request = entry['request']
+            response = entry.get('response')
             begin = time.localtime(request['begin'])
             entry_id = self._generateEntryTagURI(entry)
             entry_title = '%s %s ' % (request['method'], request['url'])
+
+            # Make the <rz:cgi_variable> nodes into a string
+            cgivars = ""
+            for k,v in request['cgi_variables']:
+                newv = cgi.escape(str(v))
+                s = cgi_variable_fmt % (k, newv)
+                cgivars = cgivars + s
+
+            # Make the <rz:cgi_variable> nodes into a string
+            wsgivars = ""
+            for k,v in request['wsgi_variables']:
+                newv = cgi.escape(str(v))
+                s = wsgi_variable_fmt % (k, newv)
+                wsgivars = wsgivars + s
+
+            # Make the <rz:request> node
+            rzrequest = rzrequest_fmt % {
+                'begin': request['begin'],
+                'cgi_variables': cgivars,
+                'wsgi_variables': wsgivars,
+                'method': request['method'],
+                'url': request['url'],
+                }
+
+            if response is not None:
+                # Make the <rz:request> node
+                headers = ''
+                for k,v in response['headers']:
+                    newv = cgi.escape(str(v))
+                    s = header_fmt % (k, newv)
+                    headers = headers + s
+
+                # If the response is text/xml, then include. If 
+                # text/html, cgi.escape and include. Otherwise, skip.
+                rh = dict(response['headers'])
+                ct = rh.get('content-type')
+                if ct is None:
+                    # 40x errors don't generate a content type
+                    body = ''
+                elif ct.startswith("text/xml"):
+                    body = response['body']
+                elif ct.startswith("text/html"):
+                    body = cgi.escape(response['body'])
+                else:
+                    body = ''
+                rzresponse = rzresponse_fmt % {
+                    'begin': response['begin'],
+                    'end': response['end'],
+                    'content-length': response['content-length'],
+                    'headers': headers,
+                    'status': response['status'],
+                    'body': body,
+                    }
+            else:
+                rzresponse = ''
+
+
+            # Make the atom:entry/atom:content node
+            content = contentfmt % {
+                'logentry_id': entry_id,
+                'rzrequest': rzrequest,
+                'rzresponse': rzresponse,
+                }
+
             entry_xml = entryfmt % {
                 'entry_id':entry_id,
                 'entry_title':cgi.escape(entry_title),
                 'updated':time.strftime('%Y-%m-%dT%H:%M:%SZ', begin),
                 'summary':cgi.escape(pprint.pformat(entry)),
+                'content':content,
                 }
             entries_xml.append(entry_xml)
 
@@ -103,26 +169,63 @@
 
 feedfmt = """\
 <?xml version="1.0" encoding="utf-8"?>
-<feed xmlns="http://www.w3.org/2005/Atom">
+<atom:feed xmlns:atom="http://www.w3.org/2005/Atom">
 
-  <title>%(title)s</title>
-  <link href="http://example.org/"/>
-  <updated>%(updated)s</updated>
-  <author>
-    <name></name>
-  </author>
-  <id>%(feed_id)s</id>
+  <atom:title>%(title)s</atom:title>
+  <atom:link href="http://example.org/"/>
+  <atom:updated>%(updated)s</atom:updated>
+  <atom:author>
+    <atom:name></atom:name>
+  </atom:author>
+  <atom:id>%(feed_id)s</atom:id>
   %(entries)s
-</feed>
+</atom:feed>
 """
 
 entryfmt = """\
-  <entry>
-    <id>%(entry_id)s</id>
-    <title>%(entry_title)s</title>
-    <link href="http://example.org/2003/12/13/atom03"/>
-    <updated>%(updated)s</updated>
-    <summary>%(summary)s</summary>
-  </entry>
+  <atom:entry>
+    <atom:id>%(entry_id)s</atom:id>
+    <atom:title>%(entry_title)s</atom:title>
+    <atom:link href="http://example.org/2003/12/13/atom03"/>
+    <atom:updated>%(updated)s</atom:updated>
+    <atom:summary>%(summary)s</atom:summary>
+    <atom:content>%(content)s</atom:content>
+  </atom:entry>
+"""
+
+contentfmt = """\
+<rz:logentry id="%(logentry_id)s" xmlns:rz="http://repoze.org/namespace">
+  %(rzrequest)s
+  %(rzresponse)s
+</rz:logentry>
+"""
+
+cgi_variable_fmt = """<rz:cgi_variable name="%s">%s</rz:cgi_variable>
+"""
+
+wsgi_variable_fmt = """<rz:wsgi_variable name="%s">%s</rz:wsgi_variable>
+"""
+
+rzrequest_fmt = """<rz:request>
+  <rz:begin>%(begin)s</rz:begin>
+  %(cgi_variables)s
+  <rz:method>%(method)s</rz:method>
+  <rz:url>%(url)s</rz:url>
+  %(wsgi_variables)s  
+</rz:request>
+"""
+
+header_fmt = """<rz:header name="%s">%s</rz:header>
 """
 
+rzresponse_fmt = """<rz:response>
+  <rz:begin>%(begin)s</rz:begin>
+  <rz:end>%(end)s</rz:end>
+  <rz:content-length>%(content-length)s</rz:content-length>
+  %(headers)s
+  <rz:status>%(status)s</rz:status>
+  <rz:body>
+%(body)s
+  </rz:body>
+</rz:response>
+"""


More information about the Repoze-checkins mailing list