<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>chris moos&#039;s blog &#187; middleware</title>
	<atom:link href="http://chrismoos.com/tag/middleware/feed/" rel="self" type="application/rss+xml" />
	<link>http://chrismoos.com</link>
	<description>coding my way through life</description>
	<lastBuildDate>Sun, 18 Sep 2011 19:48:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Pylons (X)HTML Validator&#160;Middleware</title>
		<link>http://chrismoos.com/2008/01/29/pylons-xhtml-validator-middleware/</link>
		<comments>http://chrismoos.com/2008/01/29/pylons-xhtml-validator-middleware/#comments</comments>
		<pubDate>Tue, 29 Jan 2008 20:29:20 +0000</pubDate>
		<dc:creator>Chris Moos</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[middleware]]></category>
		<category><![CDATA[pylons]]></category>
		<category><![CDATA[validator]]></category>
		<category><![CDATA[w3]]></category>
		<category><![CDATA[xhtml]]></category>

		<guid isPermaLink="false">http://chrismoos.com/2008/01/29/pylons-xhtml-validator-middleware/</guid>
		<description><![CDATA[This middleware will use the W3 Validator Service to check if your page is valid HTML. It will only check each URI once so that it doesn&#8217;t slow down your site by validating every page load. It does this by placing the result of each URI into a memory cache(using Beaker). You can then call [...]]]></description>
			<content:encoded><![CDATA[<p>This middleware will use the W3 Validator Service to check if your page is valid HTML. It will only check each URI once so that it doesn&#8217;t slow down your site by validating every page load. It does this by placing the result of each URI into a memory cache(using Beaker). You can then call <strong>cache_is_valid_xhtml()</strong> in your template to determine if the current page is valid.</p>
<p><em>Note</em>: The first time your page loads it will not display if the page is valid or not(It is validated AFTER the first response).</p>
<p>Download Link: <a href="http://www.tech9computers.com/W3ValidatorMiddleware-0.1-py2.5.egg">http://www.tech9computers.com/W3ValidatorMiddleware-0.1-py2.5.egg</a></p>
<p>Source Download(gzipped): <a href="http://www.tech9computers.com/w3validator.tar.gz">http://www.tech9computers.com/w3validator.tar.gz</a></p>
<p><strong>Install</strong></p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>www.tech9computers.com<span style="color: #000000; font-weight: bold;">/</span>W3ValidatorMiddleware-<span style="color: #000000;">0.1</span>-py2.5.egg<br />
<span style="color: #c20cb9; font-weight: bold;">sudo</span> easy_install W3ValidatorMiddleware-<span style="color: #000000;">0.1</span>-py2.5.egg</div></td></tr></tbody></table></div>
<p><strong>Configuration</strong></p>
<p><em>config/middleware.py</em></p>
<p>At the top of your middleware.py import the following</p>
<div class="codecolorer-container python blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">from</span> w3validator <span style="color: #ff7700;font-weight:bold;">import</span> ValidatorMiddleware</div></td></tr></tbody></table></div>
<p>Then right below <strong>CUSTOM MIDDLEWARE HERE<br />
</strong></p>
<div class="codecolorer-container python blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares)</span><br />
&nbsp; &nbsp; app <span style="color: #66cc66;">=</span> ValidatorMiddleware<span style="color: black;">&#40;</span>app<span style="color: black;">&#41;</span></div></td></tr></tbody></table></div>
<p><em>lib/helpers.py</em></p>
<p>At the top you need to import cache_is_valid_xhtml()</p>
<div class="codecolorer-container python blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">from</span> w3validator <span style="color: #ff7700;font-weight:bold;">import</span> cache_is_valid_xhtml</div></td></tr></tbody></table></div>
<p>I then created the following method that I call from my templates to return a string saying if the page is valid or not.</p>
<div class="codecolorer-container python blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">def</span> xhtml_str<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; valid <span style="color: #66cc66;">=</span> cache_is_valid_xhtml<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> valid <span style="color: #66cc66;">==</span> <span style="color: #008000;">True</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">'&lt;em&gt;Valid&lt;/em&gt; XHTML 1.0'</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">elif</span> valid <span style="color: #66cc66;">==</span> <span style="color: #008000;">False</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">'&lt;em&gt;NOT&lt;/em&gt; Valid XHTML 1.0'</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">else</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># hasn't been validated yet</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">'XHTML 1.0'</span></div></td></tr></tbody></table></div>
<p><strong>Template Configuration</strong></p>
<p>If you have a base template, you might want to the footer of every page to display if it is valid (X)HTML or not.</p>
<p><em>Mako</em></p>
<div class="codecolorer-container xml blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;html<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h1<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>My XHTML Site<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/h1<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;footer&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ${h.xhtml_str()}<br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/html<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></td></tr></tbody></table></div>
<p>That&#8217;s all you need to do to add validation support to your site. You can check the middleware out in action on my site at <a href="http://blackberrytracker.com">http://blackberrytracker.com</a>. Scroll to the bottom of the page to see where I have the validation result.</p>
]]></content:encoded>
			<wfw:commentRss>http://chrismoos.com/2008/01/29/pylons-xhtml-validator-middleware/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

