This file contains 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
#!flask/bin/python | |
from flask import Flask, jsonify, abort, request, make_response, url_for | |
from flask_httpauth import HTTPBasicAuth | |
app = Flask(__name__, static_url_path = "") | |
auth = HTTPBasicAuth() | |
@auth.get_password | |
def get_password(username): | |
if username == 'miguel': |
This file contains 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
"""''.format_map() in Python 2.x""" | |
try: | |
''.format_map({}) | |
except AttributeError: # Python < 3.2 | |
import string | |
def format_map(format_string, mapping, _format=string.Formatter().vformat): | |
return _format(format_string, None, mapping) | |
del string |
This file contains 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
from tornado import ioloop | |
from tornado import iostream | |
import socket | |
class Envelope(object): | |
def __init__(self, sender, rcpt, body, callback): | |
self.sender = sender | |
self.rcpt = rcpt[:] | |
self.body = body | |
self.callback = callback |
This file contains 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
# A decorator that lets you require HTTP basic authentication from visitors. | |
# Kevin Kelley <[email protected]> 2011 | |
# Use however makes you happy, but if it breaks, you get to keep both pieces. | |
# Post with explanation, commentary, etc.: | |
# http://kelleyk.com/post/7362319243/easy-basic-http-authentication-with-tornado | |
# Usage example: | |
#@require_basic_auth | |
#class MainHandler(tornado.web.RequestHandler): |