<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>App Mecha</title>
	<atom:link href="http://appmecha.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://appmecha.wordpress.com</link>
	<description>A focus on Web applications, in particular Google App Engine</description>
	<lastBuildDate>Thu, 29 Oct 2009 16:14:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='appmecha.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>App Mecha</title>
		<link>http://appmecha.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://appmecha.wordpress.com/osd.xml" title="App Mecha" />
	<atom:link rel='hub' href='http://appmecha.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Bottle : Authentication</title>
		<link>http://appmecha.wordpress.com/2009/10/29/bottle-mw-auth/</link>
		<comments>http://appmecha.wordpress.com/2009/10/29/bottle-mw-auth/#comments</comments>
		<pubDate>Thu, 29 Oct 2009 16:08:48 +0000</pubDate>
		<dc:creator>delagoya</dc:creator>
				<category><![CDATA[cu3w0rx]]></category>
		<category><![CDATA[GAE]]></category>

		<guid isPermaLink="false">http://appmecha.wordpress.com/?p=299</guid>
		<description><![CDATA[Continuing on with our middleware series, we now cover authentication. There are a ton of authentication and authorization WSGI middleware, as well an basic authnetication example used in the WSGI documentation. Some are out of date, and a lot of others are tightly integrated with other parts of a particular frameworks request handling. It would [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=appmecha.wordpress.com&amp;blog=5089419&amp;post=299&amp;subd=appmecha&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Continuing on with our middleware series, we now cover authentication. There are a ton of authentication and authorization WSGI middleware, as well an basic authnetication example used in the WSGI documentation. Some are out of date, and a lot of others are tightly integrated with other parts of a particular frameworks request handling.  It would have been easy enough to RollYO basic authentication, but I really hate reinventing a wheel I don&#8217;t have to.</p>
<p>I decided to investigate AuthKit, part of Pylons, to service my authentication needs, and struggled through a lack of documentation and fairly large code base, all for your pleasure.</p>
<h3>Authentication with AuthKit</h3>
<p>AuthKit assumes a lot of the setup for your middleware follows Pylons conventions. It was a struggle for me to make heads or tails of the examples, not being familiar with Pylons application configuration and how requests were routed. The secret sauce to actually make AuthKit work with bottle is to realize that there are actually multiple levels of AuthKit middleware that you have to invoke to get the authorization chain to even start up. Here is how you go about it in Bottle:</p>
<pre class="brush: python;">
from authkit import authenticate, authorize
from authkit.permissions import RemoteUser

from bottle import *

# bottle exposed function
@default() # maps to root URL
def hello():
    return &quot;hello&quot;

# get the default bottle application
app = default_app()

# set up an authorization permission for
# basic authentication of a remote user
app = authorize.middleware(app, RemoteUser())

# A simple authentication function
def basic_auth(environ, username, password):
    return username ==  password

# now activate the authentication
auth_config = {
    'authkit.setup.method':'basic',
    'authkit.basic.realm':'Test Realm',
    'authkit.basic.authenticate.function':basic_auth,
    'authkit.setup.enable':'True'
}
app = authenticate.middleware(app,app_conf=auth_config)

# run the application
run(app=app)
</pre>
<p>To make this work for App Engine, you need to include the AuthKit sources and account for deploying Bottle applicatios on GAE, covered in the Bottle docs and other posts.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/appmecha.wordpress.com/299/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/appmecha.wordpress.com/299/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/appmecha.wordpress.com/299/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/appmecha.wordpress.com/299/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/appmecha.wordpress.com/299/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/appmecha.wordpress.com/299/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/appmecha.wordpress.com/299/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/appmecha.wordpress.com/299/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/appmecha.wordpress.com/299/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/appmecha.wordpress.com/299/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/appmecha.wordpress.com/299/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/appmecha.wordpress.com/299/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/appmecha.wordpress.com/299/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/appmecha.wordpress.com/299/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=appmecha.wordpress.com&amp;blog=5089419&amp;post=299&amp;subd=appmecha&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://appmecha.wordpress.com/2009/10/29/bottle-mw-auth/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">delagoya</media:title>
		</media:content>
	</item>
		<item>
		<title>Bottle : Request Method Overriding</title>
		<link>http://appmecha.wordpress.com/2009/10/29/bottle-mw-method-override/</link>
		<comments>http://appmecha.wordpress.com/2009/10/29/bottle-mw-method-override/#comments</comments>
		<pubDate>Thu, 29 Oct 2009 15:27:43 +0000</pubDate>
		<dc:creator>delagoya</dc:creator>
				<category><![CDATA[cu3w0rx]]></category>
		<category><![CDATA[GAE]]></category>

		<guid isPermaLink="false">http://appmecha.wordpress.com/?p=294</guid>
		<description><![CDATA[Bottle is a great little Web application framework, but in it&#8217;s quest for simplicity, it left out a couple of key components that are needed for cu3w0rx: HTTP method overriding and basic authentication. Luckily Python&#8217;s WSGI middleware can fulfill this role. WSGI Middleware WSGI middleware is a handy way to add functionality to an application [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=appmecha.wordpress.com&amp;blog=5089419&amp;post=294&amp;subd=appmecha&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Bottle is a great little Web application framework, but in it&#8217;s quest for simplicity, it left out a couple of key components that are needed for cu3w0rx: HTTP method overriding and basic authentication. Luckily Python&#8217;s WSGI middleware can fulfill this role.</p>
<h3>WSGI Middleware</h3>
<p>WSGI middleware is a handy way to add functionality to an application by adding layers to the request/response chain in between the client request and your application. Incidently, Ruby&#8217;s Rack project took inspiration from WSGI middleware.</p>
<h3>Method Overriding</h3>
<p>A while back I bemoaned the fact that CherryPy&#8217;s RoutedDispatcher could not handle PUT and DELETE requests from forms submitted by your typical web browser, which most often only does GET and POST requests. I submitted a patch to the CherryPy project, but I now believe that this is the wrong approach, and that middleware can handle altering the REQUEST_METHOD header in response to a submitted form with a hidden &#8220;_method&#8221; parameter, as is the accepted convention. Here is some middleware for the server side application which will resige on GAE:</p>
<pre class="brush: python;">
# method_overide.py
# WSGI middleware to set the HTTP REQUEST_METHOD header from a submitted form
# that contains a &quot;_method&quot; hidden variable.

class MethodOverride(object):
  def __init__(self, app):
    self.app = app

  def __call__(self, environ, start_response):
    method = webapp.Request(environ).get('_method')
    if method:
      environ['REQUEST_METHOD'] = method.upper()
    return self.app(environ, start_response)
</pre>
<p>And here is how you would insert it in between your bottle application:</p>
<pre class="brush: python;">
from bottle import *
from google.appengine.ext.webapp import util
from method_override import MethodOverride

@route(&quot;/test_put&quot;,method=&quot;PUT&quot;)
def testput():
  return &quot;PUT success&quot;

@route(&quot;/test_delete&quot;,method=&quot;DELETE&quot;)
def testdelete():
  return &quot;DELETE success&quot;

# run in GAE
def main():
  app= default_app()
  # insert the method override middleware
  app = MethodOverride(default_app())

  util.run_wsgi_app(app)

if __name__ == '__main__':
  main()
</pre>
<p>Now forms that define the REQUEST_METHOD as a hidden param &#8220;_method&#8221; will be routed to the correct function.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/appmecha.wordpress.com/294/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/appmecha.wordpress.com/294/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/appmecha.wordpress.com/294/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/appmecha.wordpress.com/294/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/appmecha.wordpress.com/294/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/appmecha.wordpress.com/294/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/appmecha.wordpress.com/294/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/appmecha.wordpress.com/294/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/appmecha.wordpress.com/294/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/appmecha.wordpress.com/294/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/appmecha.wordpress.com/294/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/appmecha.wordpress.com/294/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/appmecha.wordpress.com/294/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/appmecha.wordpress.com/294/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=appmecha.wordpress.com&amp;blog=5089419&amp;post=294&amp;subd=appmecha&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://appmecha.wordpress.com/2009/10/29/bottle-mw-method-override/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">delagoya</media:title>
		</media:content>
	</item>
		<item>
		<title>cu3w0rx : Bottle</title>
		<link>http://appmecha.wordpress.com/2009/10/28/cu3w0rx-bottle/</link>
		<comments>http://appmecha.wordpress.com/2009/10/28/cu3w0rx-bottle/#comments</comments>
		<pubDate>Wed, 28 Oct 2009 14:13:39 +0000</pubDate>
		<dc:creator>delagoya</dc:creator>
				<category><![CDATA[cu3w0rx]]></category>
		<category><![CDATA[GAE]]></category>

		<guid isPermaLink="false">http://appmecha.wordpress.com/?p=281</guid>
		<description><![CDATA[One of the great aspects of CloudCrowd is that the code base is so small and readable. A big part of that comes by virtue of using the Sinatra Web application framework for the master and slave daemon processes. Sinatra is much closer to the GAE webapp framework than CherryPy (by default), in that you [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=appmecha.wordpress.com&amp;blog=5089419&amp;post=281&amp;subd=appmecha&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>One of the great aspects of CloudCrowd is that the code base is so small and readable. A big part of that comes by virtue of using the <a href="http://www.sinatrarb.com">Sinatra Web application framework</a> for the master and slave daemon processes. Sinatra is much closer to the GAE webapp framework than CherryPy (by default), in that you define methods that correspond to the HTTP verbs (GET, PUT, POST, DELETE and HEAD).  Sinatra differs in that the method&#8217;s first argument is the route that the method services. The GAE webapp framework instead forces you to define a class that the defines the HTTP verbs, and later map those classes to some route. Let&#8217;s take a look at &#8220;Hello World!&#8221; to illustrate the difference. Here is the GAE webapp version</p>
<pre class="brush: python;">
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

class HelloWorld(webapp.RequestHandler):
	def get(self):
		self.response.out.write(&quot;Hello World!&quot;)

app = webapp.WSGIApplication([(&quot;/&quot;,HellowWorld)])

def main():
	run_wsgi_application(app)

if __name__ == &quot;main&quot;:
	main()
</pre>
<p>Now here is the version in Sinatra:</p>
<pre class="brush: ruby;">
require &quot;rubygems&quot; # RubyGems is optional, depending on your setup
require &quot;sinatra&quot;
get '/' do
  &quot;Hello World!&quot;
end
</pre>
<p>Much more readable and concise. Here is a version of HellWorld in CherryPy, using the default MethodDispatcher, for comparison:</p>
<pre class="brush: python;">
import cherrypy

class HelloWorld:
    exposed = True
    def GET(self):
        return &quot;Hello World!&quot;

app = HelloWorld()

d = cherrypy.dispatch.MethodDispatcher()
conf = {'/': {'request.dispatch': d}}
cherrypy.tree.mount(root, &quot;/&quot;, conf)
</pre>
<p>Better, but you are still separating the the mapping of the root URL &#8220;/&#8221; to the HelloWorld class outside of the class. I started digging around the interwebz for Python frameworks that would work closer to the lightweight Sinatra and found <a>Bottle</a>. Bottle is small, self-contained and uses python decorators to map a function to a route. Brilliant. Here is the example using Bottle:</p>
<pre class="brush: python;">
from bottle import route, run

@route(&quot;/&quot;) # assumes GET method
def hello():
	return &quot;Hello world!&quot;

run() # This starts the HTTP server
</pre>
<p>Now that&#8217;s what I&#8217;m talking about! Deploying a Bottle application to GAE is covered in their <a href="http://bottle.paws.de/page/docs#deployment">documentation</a>. We&#8217;ll be using Bottle for <strong>cu3w0rx</strong> to create the master and slave daemons in later posts.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/appmecha.wordpress.com/281/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/appmecha.wordpress.com/281/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/appmecha.wordpress.com/281/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/appmecha.wordpress.com/281/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/appmecha.wordpress.com/281/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/appmecha.wordpress.com/281/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/appmecha.wordpress.com/281/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/appmecha.wordpress.com/281/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/appmecha.wordpress.com/281/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/appmecha.wordpress.com/281/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/appmecha.wordpress.com/281/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/appmecha.wordpress.com/281/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/appmecha.wordpress.com/281/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/appmecha.wordpress.com/281/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=appmecha.wordpress.com&amp;blog=5089419&amp;post=281&amp;subd=appmecha&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://appmecha.wordpress.com/2009/10/28/cu3w0rx-bottle/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">delagoya</media:title>
		</media:content>
	</item>
		<item>
		<title>Designing cu3w0rx</title>
		<link>http://appmecha.wordpress.com/2009/10/27/cu3w0rx-design/</link>
		<comments>http://appmecha.wordpress.com/2009/10/27/cu3w0rx-design/#comments</comments>
		<pubDate>Tue, 27 Oct 2009 03:30:18 +0000</pubDate>
		<dc:creator>delagoya</dc:creator>
				<category><![CDATA[GAE]]></category>

		<guid isPermaLink="false">http://appmecha.wordpress.com/?p=269</guid>
		<description><![CDATA[cu3w0rx. Lovely name, eh? Moving on &#8230; In this series we will be looking to implement a simple Map-Reduce framework that closely models the design and implementation of the CloudCrowd, which is written in Ruby. CloudCrowd  has some nice design choices. Specifically its small size (~1,800 LOC), use of JSON for message transport, and emphasis on [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=appmecha.wordpress.com&amp;blog=5089419&amp;post=269&amp;subd=appmecha&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><code>cu3w0rx</code>. Lovely name, eh? Moving on &#8230;</p>
<p>In this series we will be looking to implement a simple Map-Reduce framework that closely models the design and implementation of the <a href="http://github.com/documentcloud/cloud-crowd">CloudCrowd</a>, which is written in Ruby. CloudCrowd  has some nice design choices. Specifically its small size (~1,800 LOC), use of JSON for message transport, and emphasis on HTTP as the protocol is quite nice. It is also pretty to look at, and the interface is entirely AJAX driven, so relies on the same service calls as the rest of the suite.  I think it is worth our while to set the stage for the project. Here are a list of things we will be taking directly from CloudCrowd:</p>
<ol>
<li>The App Engine application will serve as the central master resource.</li>
<li>It will serve as the master work queue. All jobs will be submitted to it for processing.</li>
<li>All communication will be via JSON messages. As in CC, the web site will make use of the JSON returned from AJAX requests to the resource handlers.</li>
<li>There will be a clear specification for the top-level properties of a Job message, but handlers will be responsible for vetting the provided options to handle the request.</li>
<li>Operations on inputs are assumed to happen on local disk. E.g. jobs will be staged onto the worker nodes&#8217; scratch space.</li>
<li>Jobs will have the option of a callback URL on success.</li>
<li>For simplicity&#8217;s sake, authentication to the master, and between master and slaves, will be the same basic HTTP authentication credentials.</li>
<li>A worker node will accept work item requests based on the machine&#8217;s load.</li>
</ol>
<p>There will be several points that will stray from CloudCrowds implementation as well:</p>
<ol>
<li>Nodes will publish their capabilities to the master. It will not be assumed that all nodes have all the same capabilities. In this respect <code>cu3w0rx</code> will more resemble the <a href="http://github.com/ezmobius/nanite">nanite project</a> (Ruby + ERLang).</li>
<li>Worker nodes will not share the same code base as the master. The major reason for this is that worker nodes will not run on GAE, hence it makes no sense to hamstring them with the restrains that GAE imposes on python.</li>
<li>Workers will maintain their own state in a local database. This will server to keep track of capabilities, number of jobs processed, monitoring statistics, and results from previous jobs.</li>
<li>Map and reduce are implemented as two separate jobs, as far as the worker nodes are concerned.</li>
<li>Since this is a demonstration project, we will not implement a scheme to save result files to non-volitile storage. Instead we will provide a way to give authenticated access to result files from worker nodes. Result files from Reduce phases will live only at the final destination host (e.g. the hosts that have checked back into the master as having succeeded a particular job.</li>
<li>The queue is not necessarily FIFO. I am actually not sure if this is also true about CloudCrowd, but its worth mentioning here.</li>
</ol>
<p>I would also like to implement a way to provision and configure cloud VMs using the excellent <a href="http://libcloud.org/">libcloud</a> library, but I think that is outside the scope of a demonstration project. If you see anything missing (or think some stuff can be left out) leave a comment!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/appmecha.wordpress.com/269/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/appmecha.wordpress.com/269/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/appmecha.wordpress.com/269/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/appmecha.wordpress.com/269/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/appmecha.wordpress.com/269/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/appmecha.wordpress.com/269/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/appmecha.wordpress.com/269/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/appmecha.wordpress.com/269/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/appmecha.wordpress.com/269/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/appmecha.wordpress.com/269/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/appmecha.wordpress.com/269/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/appmecha.wordpress.com/269/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/appmecha.wordpress.com/269/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/appmecha.wordpress.com/269/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=appmecha.wordpress.com&amp;blog=5089419&amp;post=269&amp;subd=appmecha&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://appmecha.wordpress.com/2009/10/27/cu3w0rx-design/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">delagoya</media:title>
		</media:content>
	</item>
		<item>
		<title>App ID struggle</title>
		<link>http://appmecha.wordpress.com/2009/10/24/app-id-struggle/</link>
		<comments>http://appmecha.wordpress.com/2009/10/24/app-id-struggle/#comments</comments>
		<pubDate>Sat, 24 Oct 2009 02:21:02 +0000</pubDate>
		<dc:creator>delagoya</dc:creator>
				<category><![CDATA[1]]></category>

		<guid isPermaLink="false">http://appmecha.wordpress.com/2009/10/24/app-id-struggle/</guid>
		<description><![CDATA[I just tried for 10 minutes to get an unused application identifier that would make sense for the new example app. Adding insult to injury, every single supposedly taken ID I tried to access via the &#60;appID&#62;.appspot.com URL was a 404. Perhaps there is a bit of squatting going on? Yeah you can map to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=appmecha.wordpress.com&amp;blog=5089419&amp;post=267&amp;subd=appmecha&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I just tried for 10 minutes to get an unused application identifier that would make sense for the new example app. Adding insult to injury, every single supposedly taken ID I tried to access via the &lt;appID&gt;.appspot.com URL was a 404.  Perhaps there is a bit of squatting going on?</p>
<p>Yeah you can map to domain name, but it makes writing tutorials that much more of a pain <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/appmecha.wordpress.com/267/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/appmecha.wordpress.com/267/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/appmecha.wordpress.com/267/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/appmecha.wordpress.com/267/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/appmecha.wordpress.com/267/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/appmecha.wordpress.com/267/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/appmecha.wordpress.com/267/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/appmecha.wordpress.com/267/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/appmecha.wordpress.com/267/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/appmecha.wordpress.com/267/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/appmecha.wordpress.com/267/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/appmecha.wordpress.com/267/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/appmecha.wordpress.com/267/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/appmecha.wordpress.com/267/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=appmecha.wordpress.com&amp;blog=5089419&amp;post=267&amp;subd=appmecha&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://appmecha.wordpress.com/2009/10/24/app-id-struggle/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">delagoya</media:title>
		</media:content>
	</item>
		<item>
		<title>JRuby on GAE</title>
		<link>http://appmecha.wordpress.com/2009/10/14/jruby-on-gae/</link>
		<comments>http://appmecha.wordpress.com/2009/10/14/jruby-on-gae/#comments</comments>
		<pubDate>Wed, 14 Oct 2009 16:06:24 +0000</pubDate>
		<dc:creator>delagoya</dc:creator>
				<category><![CDATA[1]]></category>

		<guid isPermaLink="false">http://appmecha.wordpress.com/?p=264</guid>
		<description><![CDATA[After a long hiatus, I am trying to pick up the series of GAE posts. One small problem is that by day I am a Ruby programmer and switching context to Python for posts is a bit of extra work. That and a friendly prod from Ilya Grigorik for Ruby programmers to start writing about [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=appmecha.wordpress.com&amp;blog=5089419&amp;post=264&amp;subd=appmecha&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>After a long hiatus, I am trying to pick up the series of GAE posts. One small problem is that by day I am a Ruby programmer and switching context to Python for posts is a bit of extra work. That and a friendly prod from <a href="http://www.igvita.com/about/">Ilya Grigorik</a> for Ruby programmers to start writing about <a href="http://www.igvita.com/2009/09/23/deploying-jruby-on-google-app-engine/">JRuby on Google App Engine</a> has me thinking that I should play to my strengths more.</p>
<p>Having said that, I plan on doing one more series for Pythonistas, in order to implement a simple Map-Reduce work queue system using GAE as the master node. This comes from a direct need for us to support MapReduce type workflows on both Windows and Linux machines and an existing Ruby project that I would have loved to use (<a href="http://github.com/documentcloud/cloud-crowd">CloudCrowd</a>) does not work on windows. In general any Ruby project that assumes fork() is available on the system tends to have problems in a Windows environment. The project is small enough that it will not be too much work to port over the concepts to Python.</p>
<p>&#8220;But Angel, doesn&#8217;t <a href="http://discoproject.org/">disco</a> already fit the MapReduce void for Python?&#8221;</p>
<p>Technically, yes it does, but it relies on Erlang for communication between master and nodes, which is obviously a no-go for GAE.</p>
<p>&#8220;But Angel, if you are a Ruby guy, why don&#8217;t you just fork CloudCrowd and make it run on JRuby + GAE?&#8221;</p>
<p>Maybe one day I will, but Windows worker node compatibility is a must-have for us and as I researched CloudCrowd, the code base kept getting more and more Unix-centric. I did make a branch of the codebase that uses Ruby threads to overcome the use of fork() but the solution is non-optimal and broke when I tried to merge it back into the master branch which added even more into Unix dependencies for node CPU and memory statistics. Then other priorities took over and I have not looked back on that project.</p>
<p>Plus it will be an interesting project to cover on AppMecha!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/appmecha.wordpress.com/264/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/appmecha.wordpress.com/264/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/appmecha.wordpress.com/264/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/appmecha.wordpress.com/264/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/appmecha.wordpress.com/264/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/appmecha.wordpress.com/264/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/appmecha.wordpress.com/264/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/appmecha.wordpress.com/264/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/appmecha.wordpress.com/264/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/appmecha.wordpress.com/264/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/appmecha.wordpress.com/264/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/appmecha.wordpress.com/264/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/appmecha.wordpress.com/264/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/appmecha.wordpress.com/264/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=appmecha.wordpress.com&amp;blog=5089419&amp;post=264&amp;subd=appmecha&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://appmecha.wordpress.com/2009/10/14/jruby-on-gae/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">delagoya</media:title>
		</media:content>
	</item>
		<item>
		<title>Google App Engine Backup and Restore</title>
		<link>http://appmecha.wordpress.com/2008/12/22/gaebar/</link>
		<comments>http://appmecha.wordpress.com/2008/12/22/gaebar/#comments</comments>
		<pubDate>Mon, 22 Dec 2008 19:27:11 +0000</pubDate>
		<dc:creator>delagoya</dc:creator>
				<category><![CDATA[GAE]]></category>
		<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[App Engine]]></category>
		<category><![CDATA[AppEngine]]></category>

		<guid isPermaLink="false">http://appmecha.wordpress.com/?p=245</guid>
		<description><![CDATA[A quick note to point folks to thow follwoing project, that may be of interest to GAE developers: Google App Engine Backup and Restore http://github.com/aral/gaebar/tree/master Check it out! Also GitHub.com is probably the most useful site I have ever used.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=appmecha.wordpress.com&amp;blog=5089419&amp;post=245&amp;subd=appmecha&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A quick note to point folks to thow follwoing project, that may be of interest to GAE developers:</p>
<p><a href="http://github.com/aral/gaebar/tree/master">Google App Engine Backup and Restore</a></p>
<p>http://github.com/aral/gaebar/tree/master</p>
<p>Check it out! Also GitHub.com is probably the most useful site I have ever used.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/appmecha.wordpress.com/245/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/appmecha.wordpress.com/245/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/appmecha.wordpress.com/245/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/appmecha.wordpress.com/245/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/appmecha.wordpress.com/245/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/appmecha.wordpress.com/245/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/appmecha.wordpress.com/245/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/appmecha.wordpress.com/245/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/appmecha.wordpress.com/245/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/appmecha.wordpress.com/245/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/appmecha.wordpress.com/245/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/appmecha.wordpress.com/245/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/appmecha.wordpress.com/245/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/appmecha.wordpress.com/245/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=appmecha.wordpress.com&amp;blog=5089419&amp;post=245&amp;subd=appmecha&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://appmecha.wordpress.com/2008/12/22/gaebar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">delagoya</media:title>
		</media:content>
	</item>
		<item>
		<title>Breaking the Chain</title>
		<link>http://appmecha.wordpress.com/2008/11/15/breaking-the-chain/</link>
		<comments>http://appmecha.wordpress.com/2008/11/15/breaking-the-chain/#comments</comments>
		<pubDate>Sat, 15 Nov 2008 15:36:28 +0000</pubDate>
		<dc:creator>delagoya</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>

		<guid isPermaLink="false">http://appmecha.wordpress.com/?p=236</guid>
		<description><![CDATA[Well folks, I can see a light at the end of the tunnel for  tutorials and background material on GAE. Thus far I have been using the Seinfeld Calendar method (via dontbreakthechain.com) to keep my posts coming, but recently I&#8217;ve had to burn a few hours at home finishing up day-job matters, as you can [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=appmecha.wordpress.com&amp;blog=5089419&amp;post=236&amp;subd=appmecha&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Well folks, I can see a light at the end of the tunnel for  tutorials and background material on GAE. Thus far I have been using the <a href="http://lifehacker.com/software/motivation/jerry-seinfelds-productivity-secret-281626.php">Seinfeld Calendar</a> method (via <a href="http://dontbreakthechain.com/">dontbreakthechain.com</a>) to keep my posts coming, but recently I&#8217;ve had to burn a few hours at home finishing up day-job matters, as you can see:</p>
<div id="attachment_232" class="wp-caption alignnone" style="width: 258px"><a href="http://appmecha.files.wordpress.com/2008/11/picture-1.png"><img class="size-full wp-image-232" title="calendar" src="http://appmecha.files.wordpress.com/2008/11/picture-1.png?w=248&#038;h=189" alt="Don't Break the Chain" width="248" height="189" /></a><p class="wp-caption-text">Don</p></div>
<p>Those white spaces are really pretty annoying, but there is not much I can do about it now, unless my name is Hiro, and its not. As bad as it is, though, it is only going to get worse, as there are a lot of projects that need to get out the door by end-of-year. Admittedly this is a self-imposed deadline, but a deadline none the less.</p>
<p>I think what really bugs me is that the white spaces don&#8217;t have an obvious pattern. I think I would not mind it as much if it was more checker-board type, or stripes:</p>
<p><a href="http://appmecha.files.wordpress.com/2008/11/picture-2.png"><img class="alignnone size-full wp-image-233" title="checkers" src="http://appmecha.files.wordpress.com/2008/11/picture-2.png?w=255&#038;h=202" alt="checkers" width="255" height="202" /></a></p>
<p>Much better. The message is a little annoying, but I can deal with that.  Which is to say that I am trying to balance the day-jobs work-load with family and hobbies, so the posts will keep coming, but at a slower pace.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/appmecha.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/appmecha.wordpress.com/236/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/appmecha.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/appmecha.wordpress.com/236/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/appmecha.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/appmecha.wordpress.com/236/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/appmecha.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/appmecha.wordpress.com/236/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/appmecha.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/appmecha.wordpress.com/236/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/appmecha.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/appmecha.wordpress.com/236/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/appmecha.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/appmecha.wordpress.com/236/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=appmecha.wordpress.com&amp;blog=5089419&amp;post=236&amp;subd=appmecha&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://appmecha.wordpress.com/2008/11/15/breaking-the-chain/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">delagoya</media:title>
		</media:content>

		<media:content url="http://appmecha.files.wordpress.com/2008/11/picture-1.png" medium="image">
			<media:title type="html">calendar</media:title>
		</media:content>

		<media:content url="http://appmecha.files.wordpress.com/2008/11/picture-2.png" medium="image">
			<media:title type="html">checkers</media:title>
		</media:content>
	</item>
		<item>
		<title>Platform Poll Results</title>
		<link>http://appmecha.wordpress.com/2008/11/14/platform-poll-results/</link>
		<comments>http://appmecha.wordpress.com/2008/11/14/platform-poll-results/#comments</comments>
		<pubDate>Fri, 14 Nov 2008 01:56:18 +0000</pubDate>
		<dc:creator>delagoya</dc:creator>
				<category><![CDATA[GAE]]></category>
		<category><![CDATA[Miscellaneous]]></category>

		<guid isPermaLink="false">http://appmecha.wordpress.com/?p=227</guid>
		<description><![CDATA[So we got a whopping total of 9 votes (and one &#8220;other&#8221; that gave no alternate answer). Predictably the top answer was Java (60%) with Ruby running second (30%) . On the surface this makes sense, since there is a well-established developer community and Google itself uses Java for a lot of their projects. Personally [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=appmecha.wordpress.com&amp;blog=5089419&amp;post=227&amp;subd=appmecha&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>So we got a whopping total of 9 votes (and one &#8220;other&#8221; that gave no alternate answer). Predictably the top answer was Java (60%) with Ruby running second (30%) . On the surface this makes sense, since there is a well-established developer community and Google itself uses Java for a lot of their projects.</p>
<p>Personally I don&#8217;t think it will be Java for a few reasons. First and foremost because even though GWT is a Java based framework, the output is Java script, not compiled code. Second, the whole reason Python is so ill-disposed to C extensions is to restrict access to the file system. I would assume that arbitrary compiled Java packages carry the same problem. Possibly you can get around this by stringent sandboxing of the JVM or providing a custom compiler for GAE deployments. I don&#8217;t know enough about it to make any intelligent sort of comment (may have already proven that) but both of these solutions seem like heavy investment into an immature product. Especially when there are viable alternatives, like PHP and Ruby, that share the same sort of constraints as the current Python implementation.</p>
<p>If I had a vote, it would be Ruby, since I work in that every day. I am biased,  yes, but it&#8217;s my blog, so I am entitled <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  I would not be surprised if it was PHP, though. After all, it pretty much still runs the Web.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/appmecha.wordpress.com/227/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/appmecha.wordpress.com/227/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/appmecha.wordpress.com/227/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/appmecha.wordpress.com/227/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/appmecha.wordpress.com/227/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/appmecha.wordpress.com/227/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/appmecha.wordpress.com/227/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/appmecha.wordpress.com/227/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/appmecha.wordpress.com/227/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/appmecha.wordpress.com/227/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/appmecha.wordpress.com/227/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/appmecha.wordpress.com/227/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/appmecha.wordpress.com/227/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/appmecha.wordpress.com/227/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=appmecha.wordpress.com&amp;blog=5089419&amp;post=227&amp;subd=appmecha&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://appmecha.wordpress.com/2008/11/14/platform-poll-results/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">delagoya</media:title>
		</media:content>
	</item>
		<item>
		<title>Mako Introduction</title>
		<link>http://appmecha.wordpress.com/2008/11/13/mako-introduction/</link>
		<comments>http://appmecha.wordpress.com/2008/11/13/mako-introduction/#comments</comments>
		<pubDate>Thu, 13 Nov 2008 02:54:23 +0000</pubDate>
		<dc:creator>delagoya</dc:creator>
				<category><![CDATA[GAE]]></category>
		<category><![CDATA[MainStory]]></category>
		<category><![CDATA[App Engine]]></category>
		<category><![CDATA[AppEngine]]></category>
		<category><![CDATA[Mako]]></category>

		<guid isPermaLink="false">http://appmecha.wordpress.com/?p=200</guid>
		<description><![CDATA[Thus far we have spent a lot of time covering CherryPy. I think it is high time to cover our choice of view template engine, Mako. As a reminder, view system components serve to present data that is being fed to it from the controllers. Ideally view templates should be given all of the data [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=appmecha.wordpress.com&amp;blog=5089419&amp;post=200&amp;subd=appmecha&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Thus far we have spent a lot of time covering CherryPy. I think it is high time to cover our choice of view template engine, <a href="http://www.makotemplates.org/">Mako</a>. As a reminder, view system components serve to present data that is being fed to it from the controllers. Ideally view templates should be given all of the data they need to render appropriately, and not have to request more information from the data models directly. The view template then cherry picks (no pun intended) from the data it is given and formats it into an appropriate view of the data given the task at hand, for instance an summary of a posts versus the full entries.</p>
<p>Mako is a template library written in Python. HTML markup is intermixed with Python varaibles, control structures and statements. As such it uses similar approaches to JSP, ASP and PHP, but given the origins in MVC style Web applications, it is closer to ERB templates in Ruby land. Strictly speaking, Mako can produce any text format, not just HTML, but that is it&#8217;s main purpose.</p>
<p><em>Sidebar:</em> Mako templates are compiled to Python modules at runtime for maximum performance. This has implications on memory and CPU usage quotas for GAE, but only if you have a tremendous amount of templates. In any case, you can configure Mako to only hold a certain amount of pre-compiled templates in memory, and the engine will retire the oldest (base on last access time) templates to make room for the new.</p>
<p>Let&#8217;s take a look at a basic example:</p>
<div class="highlight">
<pre><span class="cp">&lt;%!</span>
  <span class="k">import</span> <span class="nn">re</span>
  <span class="k">def</span> <span class="nf">censor</span><span class="p">(</span><span class="n">text</span><span class="p">):</span>
    <span class="k">return</span> <span class="n">re</span><span class="o">.</span><span class="n">sub</span><span class="p">(</span><span class="s">r'ass'</span><span class="p">,</span> <span class="s">'butt'</span><span class="p">,</span> <span class="n">text</span><span class="p">)</span>
<span class="cp">%&gt;</span>
<span class="cp">&lt;%</span>
  <span class="n">msg</span> <span class="o">=</span> <span class="s">"&lt;b&gt;Hello World!&lt;/b&gt;"</span>
<span class="cp">%&gt;</span>
<span class="nt">&lt;html&gt;</span>
<span class="nt">&lt;body&gt;</span>
  <span class="nt">&lt;p&gt;</span>Hello World!<span class="nt">&lt;/p&gt;</span>
  <span class="nt">&lt;p&gt;</span><span class="cp">${</span> <span class="n">msg</span> <span class="cp">}</span><span class="nt">&lt;/p&gt;</span>
  <span class="nt">&lt;p&gt;</span><span class="cp">${</span> <span class="n">msg</span> <span class="o">|</span> <span class="n">h</span> <span class="cp">}</span><span class="nt">&lt;/p&gt;</span>
  <span class="nt">&lt;p&gt;</span>
    "Classic mistake" == <span class="cp">${</span> <span class="n">censor</span><span class="p">(</span><span class="s">"Classic mistake"</span><span class="p">)</span> <span class="cp">}</span>
  <span class="nt">&lt;/p&gt;</span>
<span class="nt">&lt;/body&gt;</span>
<span class="nt">&lt;/html&gt;</span></pre>
</div>
<p>OK, that&#8217;s a lot to take in, so let&#8217;s review each piece in turn. First and foremost are the directives for arbitrary Python blocks, denoted by <span class="cp">&lt;%</span> <span class="o">&#8230;</span> <span class="cp">%&gt;</span> and module level blocks, denoted by <span class="cp">&lt;%!</span> <span class="o">&#8230;</span> <span class="cp">%&gt;</span>. The difference between the two is that module level blocks are only evaluated on loading the template on the first time into memory, which may only be once per application. Ideally these module level blocks should be used for imports and some method definitions. The blocks follow all of the syntax rules for Python, including proper indentation.</p>
<p>Next is a simple expression substitution, denoted by <span class="cp">${</span> <span class="o">&#8230;</span> <span class="cp">}</span>. The contents within the ${} tag are evaluated by Python directly and evaluated directly into a string before handing the result back to the template.  You can also call any  imported function or functions defined within the scope of the template, such as the <code>censor()</code> function defined in the module block.</p>
<p>If the content for the expression is user-supplied (e.g. user generated content from the data store or forms) you often want to further process that result before presenting it to the client for security reasons (e.g. preventing malicious Javascript). This is done by using filters to escape the expression&#8217;s output string to something that is non-threatening to a browser.  These escapes can be added to an expression substituion using the | operator:</p>
<div class="highlight">
<pre>  <span class="cp">${</span> <span class="s">"&lt;script&gt; alert(</span><span class="se">\"</span><span class="s">danger will robinson</span><span class="se">\"</span><span class="s">) ; &lt;/script&gt; "</span> <span class="o">|</span> <span class="n">h</span> <span class="cp">}</span></pre>
</div>
<p>The above expression produces</p>
<div class="highlight">
<pre>  &amp;lt;script&amp;gt; alert("danger will robinson"); &amp;lt;/script&amp;gt;</pre>
</div>
<p>instead of the possibly malicious javascript within the content of the expression. Mako includes a number of built-in escaping mechanisms, including HTML, URI and XML escaping, as well as a &#8220;trim&#8221; function.</p>
<h3>Control Structures</h3>
<p>Mako templates provides the basic set of control structures &#8211; conditionals (i.e. if/elif/else), loops ( while and for), and exception handling ( try/except). These are denoted by a plain &#8220;%&#8221; sign as the first non-whitespace character on a line. Since Python indentation does not apply to them, must be explicitly ended by the corresponding end tag. Here are two examples copied from the Mako docs:</p>
<div class="highlight">
<pre><span class="cp">%</span> <span class="k">if</span> <span class="n">x</span><span class="o">==</span><span class="mf">5</span><span class="p">:</span>
    this is some output
<span class="cp">%</span><span class="k"> endif</span>

<span class="cp">%</span> <span class="k">for</span> <span class="n">a</span> <span class="ow">in</span> <span class="p">[</span><span class="s">'one'</span><span class="p">,</span> <span class="s">'two'</span><span class="p">,</span> <span class="s">'three'</span><span class="p">,</span> <span class="s">'four'</span><span class="p">,</span> <span class="s">'five'</span><span class="p">]:</span>
    <span class="cp">%</span> <span class="k">if</span> <span class="n">a</span><span class="p">[</span><span class="mf">0</span><span class="p">]</span> <span class="o">==</span> <span class="s">'t'</span><span class="p">:</span>
     its two or three
    <span class="cp">%</span> <span class="k">elif</span> <span class="n">a</span><span class="p">[</span><span class="mf">0</span><span class="p">]</span> <span class="o">==</span> <span class="s">'f'</span><span class="p">:</span>
    four/five
    <span class="cp">%</span> <span class="k">else</span><span class="p">:</span>
    one
    <span class="cp">%</span><span class="k">endif</span>
<span class="cp">%</span><span class="k"> endfor</span></pre>
</div>
<p>As you can see, the conditions and iterators from Python work just fine.</p>
<h3>Tags</h3>
<p>In addition to these Python-embedding structures, Mako provide a few XML tags for adding functionality specific to the Mako templates. The tag names all begin with &#8220;%&#8221; but are not like the Python block demarkations since the tag end does not have a corresponding &#8220;%&#8221;. Confusing, I know, but here is the basic syntax format:</p>
<div class="highlight">
<pre><span class="cp">&lt;%</span><span class="nb">include</span> <span class="na">file=</span><span class="s">"foo.txt"</span><span class="cp">/&gt;</span>

<span class="cp">&lt;%</span><span class="nb">def</span> <span class="na">name=</span><span class="s">"foo"</span> <span class="na">buffered=</span><span class="s">"True"</span><span class="cp">&gt;</span>
    this is a def
<span class="cp">&lt;/%</span><span class="nb">def</span><span class="cp">&gt;</span></pre>
</div>
<p>Notice how the closing &#8220;&gt;&#8221; is not prefixed with &#8220;%&#8221; as the Python blocks are. Also notice that when the tag has content, the closing tag follows XML syntax. The following table lists the available tags and attributes:</p>
<table border="1">
<tbody>
<tr>
<th><strong> Tag</strong></th>
<th>Description</th>
</tr>
<tr>
<td><strong>%page</strong></td>
<td>defines general characteristics of the template</td>
</tr>
<tr>
<td><strong>%include</strong></td>
<td>include another template, optionally passing arguments to it</td>
</tr>
<tr>
<td><strong>%def</strong></td>
<td>defines a Python function which contains a set of content and can be called at some other point in the template</td>
</tr>
<tr>
<td><strong>%namespace &nbsp;&nbsp;</strong></td>
<td>Like Python import statement, allows access to rendering functions and metadata of other template files, Python modules, etc.</td>
</tr>
<tr>
<td><strong>%inherit</strong></td>
<td>allows templates to arrange themselves in inheritance chains</td>
</tr>
<tr>
<td><strong>%call</strong></td>
<td>used to call &lt;%defs&gt; with additional embedded content</td>
</tr>
<tr>
<td><strong>%doc</strong></td>
<td>multiline comments</td>
</tr>
<tr>
<td><strong>%text</strong></td>
<td>suspends parsing and returns the content as plain text</td>
</tr>
</tbody>
</table>
<p>All of the tags are very well documented in the <a href="http://www.makotemplates.org/docs/"> Mako documentation</a>, but it is worth discussing at the  tag, which defines functions like the Python def, but the content of the tag follows the syntax rules of Mako. These are compiled into Python bytecode and can be evaluated in expression statements like so:</p>
<div class="highlight">
<pre><span class="cp">&lt;%</span><span class="nb">def</span> <span class="na">name=</span><span class="s">"int_square(x)"</span><span class="cp">&gt;</span>
  Integer square of <span class="cp">${</span><span class="n">x</span><span class="cp">}</span> is <span class="cp">${</span> <span class="nb">int</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">*</span> <span class="nb">int</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="cp">}</span>
<span class="cp">&lt;/%</span><span class="nb">def</span><span class="cp">&gt;</span>

<span class="cp">${</span> <span class="n">int_square</span><span class="p">(</span><span class="mf">33</span><span class="p">)</span> <span class="cp">}</span></pre>
</div>
<p>Next post, we&#8217;ll cover how templates can call and include each other using the inherit tag.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/appmecha.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/appmecha.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/appmecha.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/appmecha.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/appmecha.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/appmecha.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/appmecha.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/appmecha.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/appmecha.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/appmecha.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/appmecha.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/appmecha.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/appmecha.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/appmecha.wordpress.com/200/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=appmecha.wordpress.com&amp;blog=5089419&amp;post=200&amp;subd=appmecha&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://appmecha.wordpress.com/2008/11/13/mako-introduction/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">delagoya</media:title>
		</media:content>
	</item>
	</channel>
</rss>
