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
class rest_resource(object): | |
all_methods = frozenset([ | |
'head', 'get', 'post', 'put', 'patch', 'delete']) | |
def __init__(self, **kw): | |
self.kw = kw # view defaults | |
def __call__(self, wrapped): | |
# grab the supported methods from the class | |
methods = self.all_methods.intersection(set(vars(wrapped).keys())) |
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 pyramid.response import Response | |
from pyramid.view import view_config | |
class Test12: | |
def __init__(self, request): | |
self.request = request | |
@view_config(route_name='test1') | |
def test1(self): | |
return Response('I am from test 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
from pyramid.decorator import reify | |
from pyramid_traversalwrapper import LocationProxy | |
class traversable_attrs(object): | |
""" A decorator that adds a "wrap" attribute to the given class | |
in the form of a dict-like class that does item lookup based on | |
the attrs given. | |
""" |
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
# tutorial/__init__.py | |
from pyramid.config import Configurator | |
from tutorial.model.meta import init_model | |
from tutorial.request import TutorialRequest | |
def main(global_config, **settings): | |
init_model(settings) |
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
class DayZeroContainer(ModelContainer): | |
def __init__(self, request, cls): | |
self.cls = cls | |
self.request = request | |
@property | |
def __acl__(self): | |
return [ | |
(Allow, 'owner:{0}'.format(cls.ownerid), ('add', 'edit)), | |
# ... some other acls for this particular resource? |
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 commit_veto(environ, status, headers): | |
for good in ('1', '2', '3'): | |
if status.startswith(good): | |
break | |
else: | |
return True | |
for header_name, header_value in headers: | |
if header_name.lower() == 'x-tm-abort': | |
return True |
NewerOlder