from gistio.utils import get_setting logger = logging.getLogger(__name__) FORMAT_RST = 'rst' FORMAT_MD = 'md' RENDERABLE = { u'Text': FORMAT_MD, u'Markdown': FORMAT_MD, u'Literate CoffeeScript': FORMAT_MD, u'reStructuredText': FORMAT_RST, None: FORMAT_MD, } GITHUB_AUTH_PARAMS = get_setting('GITHUB_AUTH_PARAMS') GIST_PUBLIC_CACHE_SECONDS = get_setting('GIST_PUBLIC_CACHE_SECONDS') class GistFetchError(Exception): pass @rethinkdb_connect def gist(request, id): now = tz_now() gist = rdb.table('gists').get(unicode(id)).run(request.rdbconn) if gist is None: # it's a new gist for us user, gist = fetch_and_render_gist(request, id)
from functools import wraps import rethinkdb # from rethinkdb.errors import RqlDriverError from gistio.utils import get_setting RETHINK_CONNARGS = get_setting('RETHINK_CONNARGS') def get_connection(): conn = rethinkdb.connect(**RETHINK_CONNARGS) return conn def rethinkdb_connect(view): @wraps(view) def wrapper(request, *args, **kwargs): request.rdbconn = get_connection() retval = view(request, *args, **kwargs) try: request.rdbconn.close() except AttributeError: close finally: return retval return wrapper
__FILENAME__ = rethink from functools import wraps import rethinkdb # from rethinkdb.errors import RqlDriverError from gistio.utils import get_setting RETHINK_CONNARGS = get_setting('RETHINK_CONNARGS') def get_connection(): conn = rethinkdb.connect(**RETHINK_CONNARGS) return conn def rethinkdb_connect(view): @wraps(view) def wrapper(request, *args, **kwargs): request.rdbconn = get_connection() retval = view(request, *args, **kwargs) try: request.rdbconn.close() except AttributeError: close finally: return retval return wrapper ########NEW FILE######## __FILENAME__ = base import os import urlparse
from gistio.utils import get_setting logger = logging.getLogger(__name__) FORMAT_RST = 'rst' FORMAT_MD = 'md' RENDERABLE = { u'Text': FORMAT_MD, u'Markdown': FORMAT_MD, u'Literate CoffeeScript': FORMAT_MD, u'reStructuredText': FORMAT_RST, None: FORMAT_MD, } GITHUB_AUTH_PARAMS = get_setting('GITHUB_AUTH_PARAMS') GIST_PUBLIC_CACHE_SECONDS = get_setting('GIST_PUBLIC_CACHE_SECONDS') class GistFetchError(Exception): pass @rethinkdb_connect def gist(request, id): now = tz_now() gist = rdb.table('gists').get(unicode(id)).run(request.rdbconn) if gist is None: # it's a new gist for us user, gist = fetch_and_render_gist(request, id) else: # we already have the gist, check to see if it's still cached delta = now - gist['fetched_at']