This file contains hidden or 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
pyramid_retry +--------> if exc not retryable, render response | |
if exc retryable, ignore exc and try again | |
+ | |
| | |
| | |
v | |
pyramid_debugtoolbar | |
+ |
This file contains hidden or 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
release: ./entrypoint.sh run alembic -c site.ini upgrade head | |
web: ./entrypoint.sh run pserve site.ini |
This file contains hidden or 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 jinja2 | |
from pyramid.renderers import render | |
from pyramid.threadlocal import get_current_request | |
from translationstring import TranslationString | |
import uuid | |
from myapp.utils.i18n import DEFAULT_DOMAIN | |
log = __import__('logging').getLogger(__name__) |
This file contains hidden or 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 threading | |
import time | |
import transaction | |
from .models import get_tm_session | |
def worker(dbsession_factory, registry): | |
while True: | |
tm = transaction.TransactionManager(explicit=True) | |
with tm: |
This file contains hidden or 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 alembic.config import Config | |
from alembic.command import stamp | |
from alembic.command import upgrade | |
from alembic.migration import MigrationContext | |
from myapp.model.meta import metadata | |
from myapp.model.meta import get_engine | |
log = __import__('logging').getLogger(__name__) |
This file contains hidden or 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 add_localized_route(config, name, pattern, factory=None, pregenerator=None, **kw): | |
orig_factory = factory | |
def wrapper_factory(request): | |
lang = request.matchdict['lang'] | |
# determine if this is a supported lang and convert it to a locale, | |
# likely defaulting to your default language if the requested one is | |
# not supported by your app | |
request._LOCALE_ = lang | |
if orig_factory: | |
return orig_factory(request) |
This file contains hidden or 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 inspect | |
import sys | |
def caller_module(depth=1): | |
frm = inspect.stack()[depth + 1] | |
caller = inspect.getmodule(frm[0]) | |
return caller | |
def caller_package(depth=1): | |
module = caller_module(depth + 1) |
This file contains hidden or 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
""" | |
Let's pretend Pyramid doesn't have an enterprise-grade auth system | |
that can support several workflows. Make our own with decorators! | |
""" | |
import base64 | |
from pyramid.httpexceptions import HTTPUnauthorized | |
def check_auth(username, password): | |
"""This function is called to check if a username / | |
password combination is valid. |
This file contains hidden or 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
UNITY_GZIP_FILES = frozenset([ | |
'js', | |
'mem', | |
'data', | |
'unity3d', | |
]) | |
def can_gzip_request(request): | |
if ( | |
request.method in ('GET', 'HEAD') and |
This file contains hidden or 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
_static_regex = re.compile( | |
r''' | |
(?P<root>/static/[a-zA-Z0-9._/-]+) | |
- | |
(?P<buster>[a-fA-F0-9]+) | |
(?P<ext>\.[a-zA-Z0-9]+) | |
$''', | |
re.VERBOSE, | |
) |