return mnml.HttpResponse(layout(esc(name), Wiki.format(wiki.get_page(name), lambda n: "/view/%s" % quote(n)) + '<p><a href="/edit/%s">Edit</a></p>' % quote(name))) class Edit(mnml.RequestHandler): def GET(self, name): name = unquote(name) return mnml.HttpResponse(layout("Edit " + esc(name), """ <form method="post" action="/edit/%s"> <textarea name="text" cols="60" rows="15">%s</textarea><br/> <input type="submit" value="Save"/> or <a href="/view/%s">Cancel</a> </form>""" % ( quote(name), esc(wiki.get_page(name)), quote(name)))) def POST(self, name): name = unquote(name) wiki.set_page(name, self.request.POST.getfirst('text')) return mnml.HttpResponseRedirect("/view/%s" % quote(name)) application = mnml.TokenBasedApplication(( ('/index', Index), ('/view/:name', View), ('/edit/:name', Edit), )) if __name__ == '__main__': mnml.development_server(application)
You'll probably want to overload that in some cases to get even more control over procedings """ return self.error(404) # MNML supports two different routing mechanisms. One using regular # expressions and another using tokens. This is done predominantly to # highlight the pluggable nature of MNML, but also because the two # authors both prefer different approaches. Use whichever suites you best. routes = ( (r'^/$', Foo), (r'^/form$', Form), (r'^/foo/([0-9]+)/([0-9]+)', Foo), (r'^/bar$', Bar), ('/.*', NotFoundPageHandler), ) application = RegexBasedApplication(routes) """ routes = ( ('/', Foo), ('/myview/:stuff/', Bar) ) application = TokenBasedApplication(routes) """ if __name__ == '__main__': # run the MNML development server development_server(application)
try: subprocess.check_call( 'gmetric -n %s -v %s -t float -u Seconds' % (name, value), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) return HttpResponse("Success") except subprocess.CalledProcessError: return self.error(500) class Heartbeat(RequestHandler): def GET(self): """ A simple endpoint that will return a 200 response code We use this to verify that the service is alive """ return HttpResponse("Alive") class NotFoundPageHandler(RequestHandler): def GET(self): return self.error(404) routes = ( (r'/heartbeat', Heartbeat), (r'^/([A-Za-z0-9_]+)/([0-9]+)/$', Gmetric), ('/.*', NotFoundPageHandler), ) application = RegexBasedApplication(routes) if __name__ == '__main__': development_server(application, port=8079)