This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import httplib2 | |
from urllib import urlencode | |
import tornado.escape | |
import tornado.httpclient | |
http = httplib2.Http() | |
print "\nView welcome blog - GET" | |
headers, content = http.request("http://localhost:7777/blog/1", "GET") | |
print "Response:", tornado.escape.json_decode(content) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tornado.ioloop | |
import tornado.web | |
from datetime import datetime | |
import urlparse | |
from bson.json_util import dumps | |
import pymongo | |
from pymongo import Connection | |
class Home(tornado.web.RequestHandler): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pymongo | |
from datetime import datetime | |
from pymongo import Connection | |
conn = Connection() | |
db = conn['myDB'] | |
collection = db['language'] | |
#Creating a collection | |
db.language.insert({"id": "1", "name": "C", "grade":"Boring", "timestamp":datetime.now()}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import suds | |
## Invoke add method of MathService | |
url = 'http://localhost:8080/MathService?wsdl' | |
client = suds.client.Client(url,cache=None) | |
print client.service.add(2,3) | |
print "Request sent" | |
print client.last_sent() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tornado.httpserver | |
import tornado.ioloop | |
from tornadows import soaphandler | |
from tornadows import webservices | |
from tornadows import xmltypes | |
from tornadows.soaphandler import webservice | |
class MathService(soaphandler.SoapHandler): | |
@webservice(_params=[int,int],_returns=int) | |
def add(self, a, b): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tornado.auth | |
import tornado.escape | |
import tornado.httpserver | |
import tornado.ioloop | |
import tornado.web | |
class BaseHandler(tornado.web.RequestHandler): | |
def get_current_user(self): | |
user_json = self.get_secure_cookie("user") | |
return tornado.escape.json_decode(user_json) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<title> | |
Redis Example | |
</title> | |
<body> | |
<form action="/login" method="post"> | |
Username: <input type="text" name="username"> | |
Password: <input type="text" name="password"> | |
<input type="submit" value="Submit"> | |
</form> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tornado.ioloop | |
import tornado.web | |
class Page(tornado.web.RequestHandler): | |
def get(self): | |
self.render('xsrfform.html') | |
def post(self): | |
name = self.get_argument("name") | |
self.write('Helo ' + name) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WARNING:root:403 POST /page (127.0.0.1): '_xsrf' argument missing from POST | |
WARNING:root:403 POST /page (127.0.0.1) 1.49ms |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import httplib2 | |
from urllib import urlencode | |
h = httplib2.Http() | |
## Add articles | |
data = {'id':'1', 'author':'B', 'genre':'comedy'} | |
body = urlencode(data) | |
h.request("http://127.0.0.1:8888/articles", "POST", body=body) | |
data = {'id':'2', 'author':'A', 'genre':'tragedy'} |