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
stevek@thor ~ | |
$ virtualenv flaskdropbox_env | |
New python executable in flaskdropbox_env/bin/python | |
Installing setuptools............done. | |
stevek@thor ~ | |
$ cd flaskdropbox_env/ | |
stevek@thor ~/flaskdropbox_env | |
$ bin/pip install Flask-Dropbox |
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 mock import patch #http://pypi.python.org/pypi/mock | |
import flask | |
import myapp | |
@patch('flask.templating._render', return_value='') | |
def test_mocked_render(mocked): | |
t = myapp.app.test_client() | |
print "mocked", repr(t.get("/").data) | |
print "was _render called?", mocked.called |
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
#http://news.ycombinator.com/item?id=4439352 | |
''' | |
before = (decoration) -> | |
(base) -> | |
-> | |
decoration.apply(this, arguments) | |
base.apply(this, arguments) | |
after = (decoration) -> |
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
#http://news.ycombinator.com/item?id=4439352 | |
def has_permission_to(user, verb, subj): | |
if user == "steve" and verb == "write": | |
return True | |
elif user == "alice" and verb == "read": | |
return True | |
return False | |
def current_user(): |
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
#!/usr/bin/env python | |
'''\ | |
Usage: cookbookdiff COOKBOOK_NAME COOKBOOK_VER LOCAL_PATH [--nocolor] | |
Diff your LOCAL_PATH against what is on the chef server for a | |
given cookbook and version. | |
--nocolor: don't pipe output through 'colordiff' (in case you want to pipe to something else) | |
Examples: | |
cookbookdiff percona_toolkit 0.0.4 ~/chef-repo/cookbooks/percona_toolkit |
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
import unittest | |
from app import app | |
from cStringIO import StringIO | |
class UploadTest(unittest.TestCase): | |
def setUp(self): | |
self.app = app | |
self.app.config['TESTING'] = True | |
self.client = self.app.test_client() |
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, render_template_string, request | |
class CustomFlask(Flask): | |
jinja_options = Flask.jinja_options.copy() | |
jinja_options.update(dict( | |
block_start_string='<%', | |
block_end_string='%>', | |
variable_start_string='%%', | |
variable_end_string='%%', | |
comment_start_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 flask import Flask, render_template_string, request | |
app = Flask(__name__) | |
app.config['DEBUG'] = True | |
@app.route("/") | |
def index(): | |
#of course you would put these into files | |
jinja_template = """ | |
{# this is a jinja2 comment #} |
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, Blueprint, request | |
## blueprint ################################################################## | |
bp = Blueprint('category_functionality', __name__) | |
@bp.route('/') | |
def index(category): | |
return "this is the index page for %r" % category |
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
class ListView(object): | |
def get_items(self): | |
return [] | |
class CategoryView(ListView): | |
def get_items(self): | |
return [ | |
{'id': 1, 'title': 'First post', 'body': 'Hello world.', 'tags': ['red', 'blue'], 'category': 'something'}, | |
{'id': 2, 'title': 'Second post', 'body': 'Jello world.', 'tags': ['blue', 'green'], 'category': 'cool'}, | |
{'id': 3, 'title': 'Third post', 'body': 'Yellow world.', 'tags': ['yellow'], 'category': 'cool'}, |