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 datetime import datetime | |
import time | |
import math | |
def pretty_date(t): | |
""" | |
Take a datetime object or epoch time int, return a string representing | |
how long ago the date was. | |
Inspired by: http://ejohn.org/files/pretty.js |
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 DumbObject(object): | |
def __init__(self, len=1): | |
self.len = len | |
def __call__(self, *args, **kw): | |
return self | |
def __getattr__(self, name): | |
return self |
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
"""SQLAlchemy Metadata and Session object""" | |
from sqlalchemy import MetaData | |
from sqlalchemy.orm import scoped_session, sessionmaker | |
from sqlalchemy.orm.session import Session as SessionBase | |
from sqlalchemy.interfaces import ConnectionProxy | |
from datetime import datetime | |
import time | |
__all__ = ['Session', 'metadata', 'BaseModel'] |
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 AccountController(BaseController): | |
class login(BaseAction): | |
def __call__(self): | |
if 'username' in request.params: | |
return self.do_login | |
# Otherwise... | |
return self.draw_login | |
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 | |
""" | |
Really silly schema migration framework, built for SQLAlchemy. | |
Example: | |
./grate.py "mysql://foo:bar@localhost/baz" "sqlite:///:memory:" \ | |
--metadata model.meta:metadata --verbose | |
""" | |
import sqlalchemy | |
import sys |
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 django.utils import simplejson | |
from google.appengine.ext.webapp import RequestHandler | |
import logging | |
log = logging.getLogger(__name__) | |
class APIException(Exception): | |
def __init__(self, msg, code=400): | |
self.msg = msg |
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
def get_many(d, required=[], optional=[], one_of=[]): | |
""" | |
Returns a predictable number of elements out of `d` in a list for auto-expanding. | |
Keys in `required` will raise KeyError if not found in `d`. | |
Keys in `optional` will return None if not found in `d`. | |
Keys in `one_of` will raise KeyError if none exist, otherwise return the first in `d`. | |
Example usage: |
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
# Helper methods for an SQLAlchemy declarative base class. | |
def _is_loaded(self, key): | |
return key in self.__dict__ | |
def _is_loaded_all(self, path): | |
""" | |
Check if the given path of properties are eager-loaded. | |
`path` is similar to sqlalchemy.orm.eagerload_all, checking happens | |
by inspecting obj.__data__. |
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
API_METHOD_MAP = {} | |
def expose_api(name): | |
def decorator(fn): | |
API_METHOD_MAP[name] = fn | |
return fn | |
return decorator | |
class ApiController(BaseController): |
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 logging | |
log = logging.getLogger(__name__) | |
def warn_deprecated(environ, result): | |
log.warn("Deprecated route used: %s" % environ['PATH_INFO']) | |
return True | |
def make_map(config): |
OlderNewer