work in progress: interfaces, types, views, ...
This commit is contained in:
parent
419902ae3f
commit
94ac7c81db
4 changed files with 38 additions and 35 deletions
3
interfaces.py
Normal file
3
interfaces.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# scopes.interfaces
|
||||||
|
|
||||||
|
|
24
scopes/interfaces.py
Normal file
24
scopes/interfaces.py
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
# scopes.interfaces
|
||||||
|
|
||||||
|
from zope.interface import Interface
|
||||||
|
|
||||||
|
|
||||||
|
class ITraversable(Interface):
|
||||||
|
|
||||||
|
def items():
|
||||||
|
"""Return a sequence of key, value pairs of child objects."""
|
||||||
|
|
||||||
|
def keys():
|
||||||
|
"""Return a sequence of keys of child objects."""
|
||||||
|
|
||||||
|
def get(key, default):
|
||||||
|
"""Return the item addressed by `key`; return `default` if not found."""
|
||||||
|
|
||||||
|
def __getitem__(key):
|
||||||
|
"""Return the item addressed by `key`; rais KeyError if not found."""
|
||||||
|
|
||||||
|
def __setitem__(key, value):
|
||||||
|
"""Store the `value` under the `key`.
|
||||||
|
|
||||||
|
May modify `value` so that the attributes referencing this object
|
||||||
|
and the value object (e.g. `parent´ and `name`) are stored correctly."""
|
|
@ -8,47 +8,21 @@ from zope.traversing.publicationtraverse import PublicationTraverser
|
||||||
from scopes.storage.folder import Root
|
from scopes.storage.folder import Root
|
||||||
|
|
||||||
|
|
||||||
def demo_app(environ, start_response):
|
|
||||||
print(f'*** environ {environ}.')
|
|
||||||
status = '200 OK'
|
|
||||||
headers = [("Content-type", "text/plain; charset=utf-8")]
|
|
||||||
start_response(status, headers)
|
|
||||||
return ['Hello World'.encode()]
|
|
||||||
|
|
||||||
|
|
||||||
def zope_app_factory(config):
|
def zope_app_factory(config):
|
||||||
config.storageFactory = config.StorageFactory(config)
|
storageFactory = config.StorageFactory(config)
|
||||||
def zope_app(environ, start_response):
|
def zope_app(environ, start_response):
|
||||||
request = BrowserRequest(environ['wsgi.input'], environ)
|
storage = storageFactory(config.dbschema)
|
||||||
storage = config.storageFactory(config.dbschema)
|
|
||||||
appRoot = Root(storage, config)
|
appRoot = Root(storage, config)
|
||||||
request.setPublication(DefaultPublication(appRoot))
|
request = BrowserRequest(environ['wsgi.input'], environ)
|
||||||
request = publish(request, False)
|
request.setPublication(Publication(appRoot))
|
||||||
|
request = publish(request, True)
|
||||||
response = request.response
|
response = request.response
|
||||||
start_response(response.getStatusString(), response.getHeaders())
|
start_response(response.getStatusString(), response.getHeaders())
|
||||||
return response.consumeBodyIter()
|
return response.consumeBodyIter()
|
||||||
return zope_app
|
return zope_app
|
||||||
|
|
||||||
|
|
||||||
class AppRoot:
|
class Publication(DefaultPublication):
|
||||||
"""Zope Demo AppRoot"""
|
|
||||||
|
|
||||||
def __init__(self, config):
|
|
||||||
self.config = config
|
|
||||||
|
|
||||||
def __call__(self):
|
|
||||||
"""calling AppRoot"""
|
|
||||||
return 'At root'
|
|
||||||
|
|
||||||
def __getitem__(self, key):
|
|
||||||
def child():
|
|
||||||
"""get child"""
|
|
||||||
print(f'--- getitem {key}')
|
|
||||||
return 'getitem'
|
|
||||||
return child
|
|
||||||
|
|
||||||
def hello(self):
|
|
||||||
"""method hello"""
|
|
||||||
return 'Hello AppRoot'
|
|
||||||
|
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
|
@ -10,9 +10,11 @@ class Folder(Track):
|
||||||
headFields = ['parent', 'name', 'ref']
|
headFields = ['parent', 'name', 'ref']
|
||||||
prefix = 'fldr'
|
prefix = 'fldr'
|
||||||
|
|
||||||
|
def items(self):
|
||||||
|
return ((f.name, f) for f in self.container.query(parent=self.rid))
|
||||||
|
|
||||||
def keys(self):
|
def keys(self):
|
||||||
for f in self.container.query(parent=self.rid):
|
return (k for k, v in self.items())
|
||||||
yield f.name
|
|
||||||
|
|
||||||
def get(self, key, default=None):
|
def get(self, key, default=None):
|
||||||
value = self.container.queryLast(parent=self.rid, name=key)
|
value = self.container.queryLast(parent=self.rid, name=key)
|
||||||
|
|
Loading…
Add table
Reference in a new issue