Skip to content

Instantly share code, notes, and snippets.

@saga
Created October 15, 2012 14:30
Show Gist options
  • Save saga/3892762 to your computer and use it in GitHub Desktop.
Save saga/3892762 to your computer and use it in GitHub Desktop.
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