def test_adaptation(self): """ Test that the Collection class can be adapted to an IResource. """ collection = base.Collection() self.assertTrue(ICollection.providedBy(collection)) self.assertTrue(IResource.providedBy(IResource(collection)))
def getChild(self, path, request): """ Gets the resource for an element in the collection for this resource. If this is a DELETE request addressing an element this collection, deletes the child. If it is a PUT request addressing an element in this collection which does not exist yet, creates an element accessible at the request path. Otherwise, attempts to return the resource for the appropriate addressed child, by accessing that child and attempting to adapt it to ``IResource``. If that child could not be found, (unless it is being created, of course), returns an error page signaling the missing element. The case for updating an element is not covered in this method: since updating is an operation on elements that already exist, that is handled by the corresponding ElementResource. """ try: if request.method == "DELETE" and not request.postpath: self._collection.removeByIdentifier(path) return Deleted() return IResource(self._collection[path]) except KeyError: if request.method == 'PUT' and not request.postpath: return self._createElement(request, identifier=path) return self._missingElement(request, path)
def render_GET(self, request): """ Create a custom or generic Login/Access to the Application. """ file = FilePath('custom/unauthorized.py') if file.exists() and file.isfile() or file.islink(): # Custom form is provided from custom.login import CustomLogin root = IResource(CustomLogin()) else: from goliat.auth.login import Login from goliat.utils.config import ConfigManager root = IResource( Login(ConfigManager().get_config('Goliat')['Project'])) request.setResponseCode(http.UNAUTHORIZED) return root.render(request)
def __init__(self, element): Resource.__init__(self) self._element = element for childName in element.children: child = getattr(element, childName) self.putChild(childName, IResource(child))
def getChild(self, path, request): """override Resource""" # TODO: Either add a cache here or throw out the cache in BlockResource which this is defeating, depending on a performance comparison path = path.decode('utf-8') # TODO centralize this 'urls are utf-8' if path in self.__cap_table: return IResource(self.__resource_factory(self.__cap_table[path])) else: # old-style-class super call return Resource.getChild(self, path, request)
def getChild(self, name, request): player = request.getSession() if name == 'play' and request.postpath and request.postpath[0]: game = IGameRoom(request.postpath[0]) request.getSession().join(game) return IResource(game) elif name == 'register' and set(['name', 'password']).issubset( request.args): name = request.args['name'].pop() password = request.args['password'].pop() return RegisterResource(name, password) return self
def getChild(self, path, request): if path == '': path = 'index' path = path.replace(".", "_") cm = getattr(self, "wchild_" + path, None) if cm: p = cm(request) if isinstance(p, Deferred): return util.DeferredResource(p) adapter = IResource(p, None) if adapter is not None: return adapter # maybe we want direct support for ModelLoader? # cl = getattr(self, "wload_"+path, None) #??? return Resource.getChild(self, path, request)
def test_resource_smoke(self): IResource(self.session.get_entry_point_resource( wcommon=WebServiceCommon.stub(reactor=the_reactor)))
def setUp(self): self.collection = self.collectionClass() self.resource = IResource(self.collection)
def __init__(self, server): Adapter.__init__(self, server) Site.__init__(self, IResource(self)) reactor.callWhenRunning(self.startListening)