Skip to content

Instantly share code, notes, and snippets.

View cjgiridhar's full-sized avatar

Chetan Giridhar cjgiridhar

View GitHub Profile
@cjgiridhar
cjgiridhar / custom.html
Created August 2, 2012 13:22
Tornado - Template - Extends
{%extends "templateinheritance.html" %}
{% block header %}
<table border="1">
<tr>
<td>Article2</td>
<td>Author2</td>
</tr>
{% end %}
@cjgiridhar
cjgiridhar / errorhandler.py
Created August 3, 2012 17:57
Tornado - Error Handler
import tornado.ioloop
import tornado.web
import time
class ItWorks(tornado.web.RequestHandler):
def get(self):
self.write("It Works!!")
class Article(tornado.web.RequestHandler):
def get(self,id):
@cjgiridhar
cjgiridhar / tornadorequesthandler.py
Created August 6, 2012 14:11
Tornado - POST Request Handler
import tornado.ioloop
import tornado.web
class Hello(tornado.web.RequestHandler):
def get(self):
self.write("Hello, world")
class User(tornado.web.RequestHandler):
def get(self):
@cjgiridhar
cjgiridhar / tornadocookie.py
Created August 7, 2012 03:49
Tornado - Cookie
import tornado.ioloop
import tornado.web
import time
class Hello(tornado.web.RequestHandler):
def get(self):
self.write("Hello there")
class User(tornado.web.RequestHandler):
@cjgiridhar
cjgiridhar / request.py
Created August 7, 2012 17:07
Tornado - Secure Cookies
import httplib2
h = httplib2.Http()
response, content = h.request("http://127.0.0.1:8888/user/", "GET")
print"HTTP GET request"
print "Reponse:", response, "\nContent:", content, "\nCookie:", response['set-cookie']
## Resending the request with cookie with headers
headers = {"Cookie":response['set-cookie']}
response_2, content_2 = h.request("http://127.0.0.1:8888/user/", "GET", headers = headers)
print "\nResending the request with cookie in headers"
@cjgiridhar
cjgiridhar / template.html
Created August 10, 2012 04:47
Tornado - Template - Template() and Loader()
<html>{{ name }}</html>
@cjgiridhar
cjgiridhar / tornadoauth.py
Created August 13, 2012 16:38
Tornado - Authentication
import tornado.ioloop
import tornado.web
class Main(tornado.web.RequestHandler):
def get_current_user(self):
return self.get_secure_cookie("user")
def get(self):
if not self.current_user:
self.redirect("/login")
@cjgiridhar
cjgiridhar / tornadoauth_1.py
Created August 13, 2012 17:46
Tornado - Authentication - tornado.web.authenticated
import tornado.ioloop
import tornado.web
class Main(tornado.web.RequestHandler):
def get_current_user(self):
return self.get_secure_cookie("user")
@tornado.web.authenticated
def get(self):
## This work is achieved by decorator @tornado.web.authenticated
@cjgiridhar
cjgiridhar / tornadowebsocket.py
Created August 18, 2012 17:14
Tornado - WebSockets
import tornado.ioloop
import tornado.web
import tornado.websocket
class Socket(tornado.websocket.WebSocketHandler):
def open(self):
print "Socket opened"
def on_message(self, message):
self.write_message("Msg is " + message)
@cjgiridhar
cjgiridhar / tornadoasync.py
Created August 19, 2012 09:47
Tornado - Asynchronous
import tornado.ioloop
import tornado.web
import httplib2
httplib2.debuglevel=1
http = httplib2.Http()
class AsyncHandler(tornado.web.RequestHandler):
@tornado.web.asynchronous
def get(self):