Skip to content

Instantly share code, notes, and snippets.

View mcdonc's full-sized avatar

Chris McDonough mcdonc

View GitHub Profile
# myapp/subscribers.py
from myapp import helpers as h
from pyramid.events import subscriber
from pyramid.events import BeforeRender
def add_globals(event):
event['h'] = h
# myapp/__init__.py
def commit_veto(environ, status, headers):
for good in ('10', '20', '30', '40'):
if not status.startswith(good):
return True
for header_name, header_value in headers:
if header_name.lower() == 'x-tm-abort':
return True
import inspect
import xmlrpclib
from zope.interface import implements
from zope.interface import providedBy
from pyramid.interfaces import IViewClassifier
from pyramid.interfaces import IView
from pyramid.interfaces import IViewMapperFactory
@mcdonc
mcdonc / bench.py
Created January 20, 2011 22:10 — forked from defnull/bench.py
# with pyramid tweak (and 80-column wrapping)
import time
import sys
import StringIO
class Bench(object):
def __init__(self, flags=None):
''' Flags:
* cgi: Build a new app every time.
# [chrism@thinko ~]$ curl -i -X POST http://127.0.0.1:8080/login
# HTTP/1.0 200 OK
# Server: PasteWSGIServer/0.5 Python/2.6.5
# Date: Wed, 26 Jan 2011 18:18:22 GMT
# Content-Length: 4
# Content-Type: text/plain; charset=UTF-8
# POST[chrism@thinko curl -i http://127.0.0.1:8080/login
# HTTP/1.0 200 OK
# Server: PasteWSGIServer/0.5 Python/2.6.5
from paste.httpserver import serve
from pyramid.view import view_config
from pyramid.response import Response
@view_config(route_name='login', request_method='GET')
@view_config(context='pyramid.exceptions.Forbidden')
def login(request):
return Response('Log In', status=401)
@mcdonc
mcdonc / models.py
Created February 12, 2011 19:47
nonglobal sessions, no dbsession attached to request
import transaction
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.exc import IntegrityError
from sqlalchemy.orm.session import object_session
from sqlalchemy import Integer
from sqlalchemy import Unicode
from sqlalchemy import Column
[chrism@thinko shootout]$ env26/bin/python setup.py test -q
running test
running egg_info
writing requirements to shootout.egg-info/requires.txt
writing shootout.egg-info/PKG-INFO
writing top-level names to shootout.egg-info/top_level.txt
writing dependency_links to shootout.egg-info/dependency_links.txt
writing entry points to shootout.egg-info/entry_points.txt
writing paster_plugins to shootout.egg-info/paster_plugins.txt
reading manifest file 'shootout.egg-info/SOURCES.txt'
[chrism@thinko JayD3e]$ git diff
diff --git a/jayd3e/tests/test_handlers.py b/jayd3e/tests/test_handlers.py
index d540562..0ab58e2 100644
--- a/jayd3e/tests/test_handlers.py
+++ b/jayd3e/tests/test_handlers.py
@@ -5,10 +5,10 @@ from jayd3e.handlers.auth import AuthHandler
class TestHandlers(unittest.TestCase):
def setUp(self):
+ self.config = testing.setUp()
@mcdonc
mcdonc / gist:1270482
Created October 7, 2011 15:11
apidoc messing around
# framework
from pyramid.view import view_config
from pyramid.interfaces import IRoutesMapper
class api(view_config):
def __init__(self, **kw):
view_config.__init__(self, **kw)
def __call__(self, func):