Created
October 15, 2012 14:30
-
-
Save saga/3892762 to your computer and use it in GitHub Desktop.
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 flask import Flask | |
import platform | |
from flask import Request, Response | |
from werkzeug.routing import BaseConverter | |
import time | |
import sys | |
import json | |
import urllib2 | |
application = Flask(__name__) | |
@application.route("/") | |
def index(): | |
return 'Hello from Flask' | |
@application.route("/info") | |
def info(): | |
return platform.python_version() | |
class RegexConverter(BaseConverter): | |
def __init__(self, url_map, *items): | |
super(RegexConverter, self).__init__(url_map) | |
self.regex = items[0] | |
application.url_map.converters['regex'] = RegexConverter | |
@application.route('/atestaaafads/<regex("[abcABC0-9]{4,6}"):uid>-<slug>/') | |
def example1(uid, slug): | |
return "uid: %s, slug: %s" % (uid, slug) | |
@application.route('/m4v/<regex(".*"):filename>') | |
def FetchM4V(filename): | |
response1 = urllib2.urlopen(filename) | |
content = response1.read() | |
return Response(content, content_type="video/m4v") | |
@application.route('/mp4/<regex(".*"):filename>') | |
def FetchMP4(filename): | |
response1 = urllib2.urlopen(filename) | |
content = response1.read() | |
return Response(content, content_type="video/mp4") | |
@application.route('/mp3/<regex(".*"):filename>') | |
def FetchMP3(filename): | |
response1 = urllib2.urlopen(filename) | |
content = response1.read() | |
return Response(content, content_type="audio/mp3") | |
@application.route('/htm/<regex(".*"):filename>') | |
def FetchHTM(filename): | |
response1 = urllib2.urlopen(filename) | |
content = response1.read() | |
return Response(content, content_type="text/html") | |
@application.route('/jpg/<regex(".*"):filename>') | |
def FetchJPG(filename): | |
response1 = urllib2.urlopen(filename) | |
content = response1.read() | |
return Response(content, content_type="image/jpeg") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment