<?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>In Nomine - The Lotus Land &#187; werkzeug</title>
	<atom:link href="http://www.in-nomine.org/tag/werkzeug/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.in-nomine.org</link>
	<description>The focused mind can pierce through stone...</description>
	<lastBuildDate>Sat, 14 May 2011 20:22:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>JSONP with Werkzeug</title>
		<link>http://www.in-nomine.org/2009/04/03/jsonp-with-werkzeug/</link>
		<comments>http://www.in-nomine.org/2009/04/03/jsonp-with-werkzeug/#comments</comments>
		<pubDate>Fri, 03 Apr 2009 13:07:15 +0000</pubDate>
		<dc:creator>asmodai</dc:creator>
				<category><![CDATA[Browsers]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[jsonp]]></category>
		<category><![CDATA[werkzeug]]></category>

		<guid isPermaLink="false">http://www.in-nomine.org/?p=269</guid>
		<description><![CDATA[So I had implemented a simple JSON data server with Werkzeug for a classroom experiment. Unfortunately in my haste to get everything up and running I totally forgot about the fact that, since we cannot allow uploads to this server &#8230; <a href="http://www.in-nomine.org/2009/04/03/jsonp-with-werkzeug/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>So I had implemented a simple <a title="JSON data format website" href="http://www.json.org/">JSON</a> data server with Werkzeug for a classroom experiment. Unfortunately in my haste to get everything up and running I totally forgot about the fact that, since we cannot allow uploads to this server of various custom made webpages, using <a title="Ajax/jQuery.ajax() documentation" href="http://docs.jquery.com/Ajax/jQuery.ajax">jQuery&#8217;s <code>$.ajax()</code></a> everything just fails since it will then be a cross-site scripting request.</p>
<p>So, normally you would do something like the following in order to return JSON data:</p>
<pre lang="python">return json.dumps(data)</pre>
<p>Which would be used with the $.ajax() call in a way like the following:</p>
<pre lang="javascript">$.ajax({
  type: "POST",
  url: "http://example.com/json/something",
  data: "parameter=value",
  dataType: "json",
  error: function(XMLHttpRequest, textStatus, errorThrown){},
  success: function(data, msg){}
});</pre>
<p>Which is perfectly fine for scripts getting and using the data on the same host/domain. But, as said before, this will fail with warnings similar to: <code>"Access to restricted URI denied" code: "1012" nsresult: "0xdeadc0de (NS_ERROR_DOM_BAD_URI)"</code>.</p>
<p>One way out of this is using <a title="Remote JSON - JSONP" href="http://bob.pythonmac.org/archives/2005/12/05/remote-json-jsonp/">JSONP</a>. jQuery has a <a title="Ajax/jQuery.getJSON() documentation" href="http://docs.jquery.com/Ajax/jQuery.getJSON"><code>$.getJSON()</code> function</a>, which loads JSON data using a HTTP GET request. Now, the simplistic way to convert your code would be to change it as such:</p>
<pre lang="javascript">$.getJSON("http://example.com/json/something",
  function(data){}
);</pre>
<p>But this causes another issue. Since <code>$.getJSON()</code> GETs the JSON data, but doesn&#8217;t use eval() on it, but instead pulls the result into <code>script</code> tags, it somehow causes,on Firefox at least, an invalid label error. In order to fix this you need to set up the JSON data server to properly support a callback argument, to use <code>$.getJSON()</code> how it is meant to be used:</p>
<pre lang="javascript">$.getJSON("http://example.com/json/something?jsoncallback=?",
  function(data){}
);</pre>
<p>In the code above the additional parameter <code>jsoncallback</code> will, thanks to jQuery, get the question mark replaced by an alphanumeric string (typically in the form of <code>jsonp</code> followed by a timestamp). This value should be used to wrap the resulting JSON data with. This means you would have to change the initial Python code to something like this:</p>
<pre lang="python">return request.args.get('jsoncallback') + '(' + json.dumps(data) + ')'</pre>
<p>Of course this causes problems when you want to reuse the code for both AJAX use on the same host/domain and use it from outside. So in order to make both work you can test on whether or not the callback parameter is available and return the appropriate data. I came up with this little snippet for that:</p>
<pre lang="python">def jsonwrapper(self, request, data):
    callback = request.args.get('jsoncallback')

    if callback:
        return callback + '(' + json.dumps(data) + ')'
    else:
        return json.dumps(data)</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.in-nomine.org/2009/04/03/jsonp-with-werkzeug/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>2008 will be a stellar year for Python</title>
		<link>http://www.in-nomine.org/2008/02/06/2008-will-be-a-stellar-year-for-python/</link>
		<comments>http://www.in-nomine.org/2008/02/06/2008-will-be-a-stellar-year-for-python/#comments</comments>
		<pubDate>Wed, 06 Feb 2008 20:56:24 +0000</pubDate>
		<dc:creator>asmodai</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[babel]]></category>
		<category><![CDATA[bitten]]></category>
		<category><![CDATA[genshi]]></category>
		<category><![CDATA[trac]]></category>
		<category><![CDATA[webob]]></category>
		<category><![CDATA[werkzeug]]></category>

		<guid isPermaLink="false">http://www.in-nomine.org/2008/02/06/2008-will-be-a-stellar-year-for-python/</guid>
		<description><![CDATA[For the past few months there&#8217;s been a certain vibe building up. This vibe is coming from parts of the Python community. As it stands 2008 seems to become a very stellar year for Python. Just after New Year TIOBE &#8230; <a href="http://www.in-nomine.org/2008/02/06/2008-will-be-a-stellar-year-for-python/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>For the past few months there&#8217;s been a certain vibe building up. This vibe is coming from parts of the Python community. As it stands 2008 seems to become a very stellar year for Python.</p>
<p>Just after New Year <a title="TIOBE Programming Community Index" href="http://www.tiobe.com/index.htm?tiobe_index">TIOBE</a> reported this:</p>
<blockquote><p>Python has been declared as programming language of 2007. It was a close finish, but in the end Python appeared to have the largest increase in ratings in one year time (2.04%). There is no clear reason why Python made this huge jump in 2007. Last month Python surpassed Perl for the first time in history, which is an indication that Python has become the &#8220;de facto&#8221; glue language at system level. It is especially beloved by system administrators and build managers. Chances are high that Python&#8217;s star will rise further in 2008, thanks to the upcoming release of Python 3.</p></blockquote>
<p>There are a lot of really interesting developments going on.  Some interesting developments in my opinion are (in no particular order): <a title="Babel" href="http://babel.edgewall.org/">Babel</a>, <a title="http://bitten.edgewall.org/" href="http://www.in-nomine.org/wp-admin/Bitten">Bitten</a>, <a title="Genshi" href="http://genshi.edgewall.org/">Genshi</a>, <a title="Trac" href="http://trac.edgewall.org/">Trac</a>, <a title="http://werkzeug.pocoo.org/" href="http://www.in-nomine.org/wp-admin/Werkzeug">Werkzeug</a>, <a title="http://pythonpaste.org/webob/" href="http://www.in-nomine.org/wp-admin/WebOb">WebOb</a>.</p>
<p>An exciting year indeed.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.in-nomine.org/2008/02/06/2008-will-be-a-stellar-year-for-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Werkzeug 0.1 released &#8211; WSGI toolbox</title>
		<link>http://www.in-nomine.org/2007/12/21/werkzeug-01-released-wsgi-toolbox/</link>
		<comments>http://www.in-nomine.org/2007/12/21/werkzeug-01-released-wsgi-toolbox/#comments</comments>
		<pubDate>Fri, 21 Dec 2007 11:48:26 +0000</pubDate>
		<dc:creator>asmodai</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[cherrypy]]></category>
		<category><![CDATA[werkzeug]]></category>
		<category><![CDATA[wsgi]]></category>

		<guid isPermaLink="false">http://www.in-nomine.org/2007/12/21/werkzeug-01-released-wsgi-toolbox/</guid>
		<description><![CDATA[Armin Ronacher has released Werkzeug 0.1 a little while ago. As the website for Werkzeug says: &#8220;Werkzeug is a collection of various utilities for WSGI applications. It features request and response objects as well as a powerful url dispatcher and &#8230; <a href="http://www.in-nomine.org/2007/12/21/werkzeug-01-released-wsgi-toolbox/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Armin Ronacher has released <a title="Werkzeug 0.1 Released" href="http://lucumr.pocoo.org/cogitations/2007/12/09/werkzeug-01-released/">Werkzeug 0.1 a little while ago</a>. As the <a title="Werkzeug" href="http://werkzeug.pocoo.org/">website for Werkzeug</a> says: &#8220;Werkzeug is a collection of various utilities for WSGI applications. It     features request and response objects as well as a powerful url dispatcher     and a debugging system.&#8221;</p>
<p>I have it on my todo list to convert my current CherryPy environment to Werkzeug as a proof of concept and see which one of the two I prefer and will ultimately use for <a title="The Kouyou Project" href="http://www.rangaku.org/">my Japanese-Dutch dictionary project</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.in-nomine.org/2007/12/21/werkzeug-01-released-wsgi-toolbox/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

