-
Notifications
You must be signed in to change notification settings - Fork 10
Upgrading from WebCore 1
There are a few notable changes in WebCore 2.
WebCore 2 utilizes a request-local context instead of relying on the presence of "super global" variables. If such access is required by your application (and certain situations do require thread locals) you can opt out of the ability to co-host multiple WebCore applications in the same process and enable the ThreadLocalExtension
which exposes the current context via web.core.local.context
. (The local
object from the web.core
package is safe to import early.)
If you relied on WebCore's former opinions on topics such as database layer, session/caching system, or widget library, these support extensions have been removed from core. Most applications will need/want to utilize an application specific WebCore extension to wire these bits back in using the appropriate callback hooks.
Several elements of dispatch have been altered or have been simplified away. Formerly index
was a special method name, handling the "default" for controller-level access. This is now handled by defining a __call__
method to make the instance itself a valid callable, freeing the name index
to be used for other purposes. Additionally, __lookup__
and the other double underscore methods are gone; instead, write a new dispatcher where needed, or fall back on __getattr__
if you only need to consume single path elements dynamically.
WebCore no longer depends on a generic template engine support interface. Recommendation for new projects is to use cinje instead, as it offers zero-boilerplate templates as native importable Python modules, and the result of calling a template function (a generator) is directly usable by WebCore as a return value from a controller. If pluggable third-party template engine and serializer support is desired, or if updating, install the web.template package and enable the TemplateExtension
to restore WebCore 1-like 2-tuple return functionality.
Currently WebCore contains no internal support for loading from a configuration file, and Paste is dead. WebCore offers a replacement for both configuration and pluggable command-line interface in the web.command package, giving you a web
shell command analogous to paster
.
The WebOb exception classes which represent HTTP response status codes that are also WSGI applications usable as responses have had their aliases removed from WebCore. Import them from their true location:
from webob.exc import HTTPNotFound, ...