Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
class CRest(grok.REST):
grok.layer(LayerC)
grok.context(MyApp)
def some_method_thats_not_in_HTTP(self):
pass
class DRest(grok.REST):
grok.context(MyContent)
def GET(self):
return "GET2"
class SecurityRest(grok.REST):
grok.context(MyContent)
grok.layer(LayerSecurity)
@grok.require(grok.Public)
def GET(self):
return "GET3"
@grok.require('zope.ManageContent')
def POST(self):
return "POST3"
@grok.require('zope.ManageContent')
def PUT(self):
return "PUT3"
@grok.require('zope.ManageContent')
def DELETE(self):
return "DELETE3"
class GoldBone(grok.Viewlet):
grok.context(Interface)
grok.viewletmanager(Pot)
grok.require(Gold)
def render(self):
return 'Gold Bone'
class IBoneLayer(IDefaultBrowserLayer):
grok.skin('boneskin')
class LayeredBone(grok.Viewlet):
grok.context(Interface)
grok.viewletmanager(Pot)
grok.layer(IBoneLayer)
def render(self):
return 'Layered Bone'
class ManBone(grok.Viewlet):
grok.viewletmanager(Pot)
grok.context(CaveMan)
def render(self):
return "Man Bone"
class LadyViewlet(grok.Viewlet):
grok.context(Interface)
grok.viewletmanager(Pot)
grok.view(FireView)
@grok.require('zope.ManageContent')
def POST(self):
return "POST3"
@grok.require('zope.ManageContent')
def PUT(self):
return "PUT3"
@grok.require('zope.ManageContent')
def DELETE(self):
return "DELETE3"
class BodyTest(grok.REST):
grok.context(MyContent)
grok.layer(LayerContent)
def POST(self):
return self.body
def PUT(self):
return self.body
class MyInterfaceContent(grok.Model):
grok.implements(IFoo)
class MyNoInterfaceContent(grok.Model):
grok.implements(IFoo)
class InterfaceRest(grok.REST):
grok.context(IFoo)
grok.layer(LayerInterface)
>>> browser.open("http://localhost/++skin++Rotterdam/manfred/@@moredrawings")
>>> print browser.contents
Pretty
>>> browser.open("http://localhost/++skin++skinfromclass/manfred/@@evenmoredrawings")
>>> print browser.contents
Awesome
"""
import grok
from zope.app.basicskin import IBasicSkin
from zope.app.rotterdam import rotterdam
grok.layer(IBasicSkin)
class MySkinLayer(grok.IBrowserRequest):
pass
class SkinFromClass(grok.Skin):
grok.layer(MySkinLayer)
class Mammoth(grok.Model):
pass
class CaveDrawings(grok.View):
pass
cavedrawings = grok.PageTemplate("""\
"""
import grok
class Mammoth(grok.Model):
def __init__(self, name):
self.name = name
class MammothRestLayer(grok.IRESTLayer):
grok.restskin('mammoth')
class TouchMammoth(grok.Permission):
grok.name('mammoth.Touch')
class MammothRest(grok.REST):
grok.layer(MammothRestLayer)
@grok.require(TouchMammoth)
def GET(self):
return self.context.name
>>> browser.open("http://localhost/++skin++skinfromclass/manfred/@@evenmoredrawings")
>>> print browser.contents
Awesome
"""
import grok
from zope.app.basicskin import IBasicSkin
from zope.app.rotterdam import rotterdam
grok.layer(IBasicSkin)
class MySkinLayer(grok.IBrowserRequest):
pass
class SkinFromClass(grok.Skin):
grok.layer(MySkinLayer)
class Mammoth(grok.Model):
pass
class CaveDrawings(grok.View):
pass
cavedrawings = grok.PageTemplate("""\
<h1>Hello, world!</h1>
""")
class MoreDrawings(grok.View):
def DELETE(self):
return "DELETE"
class BRest(grok.REST):
grok.layer(LayerB)
grok.context(MyApp)
def GET(self):
return "GET"
def PUT(self):
return "PUT"
class CRest(grok.REST):
grok.layer(LayerC)
grok.context(MyApp)
def some_method_thats_not_in_HTTP(self):
pass
class DRest(grok.REST):
grok.context(MyContent)
def GET(self):
return "GET2"
class SecurityRest(grok.REST):
grok.context(MyContent)
grok.layer(LayerSecurity)
@grok.require(grok.Public)
import grok
from zope import interface
grok.definelayer('my')
grok.definelayer('admin')
grok.layer('my')
grok.defineskin('my', ['my']) # this is the default
grok.defineskin('my') # does the same as the line above
grok.defineskin('admin', ['admin', 'my'])
class Painting(grok.View):
pass
fireplace = grok.PageTemplate("""\
""")
class AdminPainting(grok.View):
class Messages(grok.View):
@property
def messages(self):
receiver = component.getUtility(IMessageReceiver)
return receiver.receive()
class WikiLayer(grok.IRESTLayer):
# This skin will be visible as http://localhost:8080/++rest++wiki/...
grok.restskin('wiki')
class PageRest(grok.REST):
grok.layer(WikiLayer)
def GET(self):
return "Hello world"
raise TraversalError("++rest++%s" % name)
applySkin(self.request, skin)
return self.context
class NotAllowedREST(grok.REST):
"""Default REST view, whose methods all raise Not Allowed errors.
By binding itself to ``Interface``, this becomes the most general
available REST view, and will be called into service for objects
that have not had more specific REST views registered. This means
that such objects can at least return attractive refusals when
clients attempt to assail them with unwanted HTTP methods.
"""
grok.layer(grok.IRESTRequest)
grok.context(Interface)
is_not_allowed = True
def GET(self):
raise GrokMethodNotAllowed(self.context, self.request)
def POST(self):
raise GrokMethodNotAllowed(self.context, self.request)
def PUT(self):
raise GrokMethodNotAllowed(self.context, self.request)
def DELETE(self):
raise GrokMethodNotAllowed(self.context, self.request)