[Checkins] SVN: grokcore.json/trunk/ Cleaning the package and isolated the JSON component and grokker.
Souheil CHELFOUH
souheil at chelfouh.com
Tue Nov 2 20:50:24 EDT 2010
Log message for revision 118127:
Cleaning the package and isolated the JSON component and grokker.
Changed:
U grokcore.json/trunk/CHANGES.txt
D grokcore.json/trunk/CREDITS.txt
D grokcore.json/trunk/INSTALL.txt
U grokcore.json/trunk/README.txt
D grokcore.json/trunk/TODO.txt
U grokcore.json/trunk/src/grokcore/json/__init__.py
U grokcore.json/trunk/src/grokcore/json/components.py
D grokcore.json/trunk/src/grokcore/json/directive.py
D grokcore.json/trunk/src/grokcore/json/events.py
D grokcore.json/trunk/src/grokcore/json/index.py
U grokcore.json/trunk/src/grokcore/json/interfaces.py
U grokcore.json/trunk/src/grokcore/json/meta.py
D grokcore.json/trunk/src/grokcore/json/publication.py
D grokcore.json/trunk/src/grokcore/json/rest.py
D grokcore.json/trunk/src/grokcore/json/util.py
-=-
Modified: grokcore.json/trunk/CHANGES.txt
===================================================================
--- grokcore.json/trunk/CHANGES.txt 2010-11-02 16:30:00 UTC (rev 118126)
+++ grokcore.json/trunk/CHANGES.txt 2010-11-03 00:50:24 UTC (rev 118127)
@@ -1,709 +1,7 @@
-Grok changes
-************
+Changes
+*******
-1.2.2 (unreleased)
+1.0 (unreleased)
==================
-- Nothing changed yet.
-
-
-1.2.1 (2010-10-26)
-==================
-
-- Grok tutorial example projects updated.
-
-- Documentation updates in preparation for the Grok Toolkit 1.2 release.
-
-- Use zc.buildout-1.5.2.
-
-1.2 (2010-10-13)
-================
-
-- No changes were necessary.
-
-1.2a (2010-10-07)
-=================
-
-- Grok and the Grok Toolkit now use zc.buildout-1.5.1 that should simplify
- Grok's installation story significantly. It is now possible to use a system
- Python installation for installing Grok. This obsoletes the ``virtualenv``
- requirement.
-
-- Grok and the Grok Toolkit will use the ZTK-1.0 release. Note though that
- several package versions are overridden to include bugfix releases.
-
-- Various dependencies have been updated.
-
-- Removed z3c.testsetup-specific test collector from grok.testing. You can
- still use z3c.testsetup with grok, but have to declare the dependency in your
- project's ``setup.py`` explicitly.
-
-- The grok.View component now uses the grokcore.message package for its
- `flash` method.
-
-- Grok test zcml now explicitly sets a defaultView name (to `index.html`).
- This has been added since we no longer depend on packages such as
- zope.app.zcmlfiles, that used to take care of that configuration step.
-
-- Internationalization of title and description of roles are not lost anymore.
-
-- `create_application` now raises a `KeyError`, in cases of key duplication,
- to match the ``zope.container`` behavior. Tests have been adapted accordingly.
-
-- Added `KeyError` error handling to the existing `DuplicationError`, to fit
- the ``zope.container`` changes. Tests have been adapted accordingly.
-
-1.1.1 (2010-05-30)
-==================
-
-- Make use of the groktoolkit 1.1.1 that includes several bugfix releases
- of Grok's dependencies such as:
-
- - zope.password, where the SSHAPasswordManager was fixed.
-
- - zope.publisher, that fixes the long standing XML-RPC "hanging" bug.
-
-- Cleanups in the buildout parts.
-
-- Remove zope.app.twisted.
-
-1.1 (2010-05-18)
-================
-
-- Add zope.pluggablauth as a dependency.
-
-1.1rc1 (2010-02-25)
-===================
-
-* Now using grokcore.content for the base content types : Model,
- Container and OrderedContainer.
-
-* Lifted the dependency on zope.app.authentication and depend on
- zope.password instead.
-
-* Lifted dependencies on deprecate packages zope.app.error and
- zope.app.securitypolicy and zope.app.session.
-
-Beside these changes lot of work has been undertaken to remove as much
-dependencies on "older" zope.app.* packages as possible from Grok itself
-and from the dependencies of Grok. This work is not complete yet.
-
-1.1a2 (2009-12-22)
-==================
-
-* Updated z3c.recipe.compattest's version and used it for a bin/compattest
- that tests grok and all its dependencies.
-
-* Add grok.getApplication() that, similar to grok.getSite() retrieves
- the "nearest" enclosing grok.Application object.
-
-* Use zope.container instead of zope.app.container.
-
-* Use zope.catalog instead of zope.app.catalog.
-
-* Use zope.intid instead of zope.app.intid.
-
-* Use zope.keyreference instead of zope.app.keyreference.
-
-1.1a1 (2009-11-17)
-==================
-
-* This release depends on grokcore.view 1.13a1.
-
-* Add ZTK support (currently ZTK 1.0dev).
-
-* Grokdocs now uses ZTK pinned versions.
-
-* The ``grok.permissions()``, that is used in the ``grok.Role`` component now
- accepts references to ``grok.Permission`` class, not just permission ids.
- This behaviour is now symetrical to the ``grok.require()`` directive.
-
-* Added an util function, ``create_application``, to create an
- application and trigger the correct events during the process.
-
-* Grok now provides an application-centric event to complete the
- zope.lifecycle ones. This event, ``ApplicationInitializedEvent``, is
- destined to be trigged after the application has been added to a
- container. At this particular step, the application is considered
- safe for additional content to be created.
-
-* Use grokcore.site and grokcore.annotation instead of builtins
- implementations.
-
-* Update the reference to mention ``zope.View``.
-
-* Update the reference to mention direct references to permissions in
- ``grok.require`` and ``grok.permissions`` in ``grok.Role``.
-
-* Fix documentation bug where virtualenv wasn't explained correctly.
-
-* Remove the ``grok.View`` permission declaration in ``etc/site.zcml.in``,
- should have gone in 1.0b2 already
-
-1.0 (2009-10-07)
-================
-
-* Removed IReRaiseException adapter registration for IUnauthorized again in
- favor of using grokcore.startup's configurable``debug_application_factory``
- WSGI application factory function.
-
-* Use newer versions of simplejson and pytz.
-
- See also https://bugs.launchpad.net/grok/+bug/432115
-
-1.0b2 (2009-09-17)
-==================
-
-See: `upgrade_notes_1.0b2` for special notes on upgrading to this release.
-
-* Revert back to an older version of ``grokui.admin`` that has not seen any
- changes related to the ``grok.View`` permission and the
- ``View``/``CodeView`` split and still has the introspector that is removed
- from newer versions.
-
-* ``grokcore.view``, ``grokcore.viewlet`` and ``grokcore.formlib`` and
- Grok itself have been updated to undo the ``View``/``CodeView``
- split that we had temporarily introduced in the development versions
- after Grok 1.0a4. This means the behavior of ``grok.View`` is
- unchanged from Grok 1.0a4. Nothing to see here!
-
-* Changed the default permission to ``zope.View`` instead of
- ``zope.Public``. This means a modification needs to be made to your
- ``site.zcml`` if you're upgrading an existing Grok-based
- project. See the upgrade notes for more information.
-
- See also https://bugs.launchpad.net/grok/+bug/387332
-
-* Bump used zope.app.wsgi version (now: 3.4.2) to support
- product-configs in zope.conf files with paster. Fix
- https://bugs.launchpad.net/grok/+bug/220440
-
-* Default location for Data.fs and logfiles of grok's sample application is
- now ``var/filestorage/`` and ``var/log/`` instead of ``parts/data/``
- and ``parts/log/``.
-
-* Bump used `z3c.testsetup` version (now: 0.4). Fix
- https://bugs.launchpad.net/grok/+bug/395125
-
-* Bump used ZODB3 version (now: 3.8.3). Fix
- https://bugs.launchpad.net/grok/+bug/410703
- https://bugs.launchpad.net/grok/+bug/424335
-
-* Added `zope.publisher.interfaces.IReRaiseException` adapter for
- IUnauthorized exceptions. Closes
- https://bugs.launchpad.net/grok/+bug/332061
-
-* Removed `docutils` and `Pygment` from versions.cfg. Both are pinned
- in grokdocs subpackage. Closes
- https://bugs.launchpad.net/grok/+bug/340170
-
-* Corrected Content-type; JSON views now report 'application/json'.
-
-* updated zope.publisher dependency to 3.4.8 (fix paster.httpserver
- related bugs in XMLRPC, PUT)
-
-* switched buildout to paster based template (like grokproject default)
- https://bugs.launchpad.net/grok/+bug/307197
-
-* changed interpreter name from 'python' to 'grokpy'.
-
-* Restructured the upgrade and change documentation so that they now
- get generated into separate files by Sphinx
-
-1.0b1 (2009-09-14)
-==================
-
-* This release happened but never really was fully completed. See the
- release notes for 1.0b2 instead.
-
-1.0a4 (2009-05-21)
-==================
-
-* Pin grokcore.view to 1.7.
-
-* Import zope.app.container interfaces from their actual definition not from a
- re-import.
-
-* JSON views now report a Content-type: text/json. See
- https://bugs.launchpad.net/bugs/362902
-
-
-1.0a3 (2009-04-10)
-==================
-
-* Pin grokui.admin to 0.3.2
-
-* Pin grokcore.view to 1.5.
-
-* Pin grokcore.component to 1.6.
-
-
-1.0a2 (2009-04-08)
-==================
-
-* Documentation and doc string updates.
-
-* Pin grokui.admin to 0.3.
-
-* Pin grokcore.view to 1.4.
-
-* Synced versions.cfg with the latest KGS release available at:
- http://download.zope.org/zope3.4/3.4.0/versions.cfg
-
-* Expose ``IBeforeTraverseEvent`` for import in the ``grok`` namespace.
-
-1.0a1 (2009-01-08)
-==================
-
-See: `upgrade_notes_1.0a1` for special notes on upgrading to this release.
-
-Feature changes
----------------
-
-* Introduced ``grok.interfaces.IGrokSecurityView``, a marker interface
- which non-Grok views can use to state that they want to be handled
- like regular Grok views by the Grok publisher.
-
-* Expose the ``DirectoryResource`` component from grokcore.view and the
- accompanying ``path`` directive.
-
-* Similar to the layers and skins restructuring, the ``grok.RESTProtocol``
- baseclass has been removed in favour of a ``grok.restskin(name)`` directive
- that can be used on REST layer interfaces. Introduced the IRESTLayer base
- interfaces for defining REST layers.
-
-* Besides our extensive existing documentation, we have also started
- to add a lot of docstrings to the Grok source code so it becomes
- easier to understand.
-
-Bug fixes
----------
-
-* Have GrokForm define an empty actions attribute by default, in order
- for "action-less" forms to work easily.
-
-* Allow the grok.layer() directive on JSON components. Closes
- https://bugs.launchpad.net/grok/+bug/310558
-
-* Close a bad security hole (also fixed in 0.14.1 and other
- releases). See
- http://grok.zope.org/blog/security-issue-in-grok-please-upgrade
-
-Restructuring
--------------
-
-* Viewlet-related base classes and helpers have been moved out to a
- ``grokcore.viewlet`` package which Grok now depends on.
-
-0.14 (2008-09-29)
-=================
-
-See: `upgrade_notes_0.14` for special notes on upgrading to this release.
-
-Feature changes
----------------
-
-* Grok now officially supports Python 2.5 and still supports Python 2.4.
-
-* Merged the versions from the zope 3.4c7 KGS (known good set):
- http://download.zope.org/zope3.4/versions-3.4.0c7.cfg
- So we are now using the latest Zope 3 releases for all Zope packages.
-
-Restructuring
--------------
-
-* The ``grok.admin`` subpackage has been factored out to a separate
- package ``grokui.admin``. To have the Grok admin UI available in
- your environment, add ``grokui.admin`` to the required packages in
- the ``setup.py`` of your package.
-
-* Removed ``grok.Skin`` baseclass in favour of a ``grok.skin(name)``
- directive that can be used on layer interfaces. Also removed the
- ``IGrokLayer`` interface in favour of exposing ``IBrowserRequest``
- from the grok package.
-
-* Security-related directives and helpers have been moved out to a
- ``grokcore.security`` package.
-
-* View-related base classes, directives and grokkers have been moved
- out to a ``grokcore.view`` package.
-
-* Form-related base classes and helpers have been moved out to a
- ``grokcore.formlib`` package.
-
-Bug fixes
----------
-
-* Replace zope.deprecation.tests.warn with grok.testing.warn to:
-
- * Make the signature identical to warnings.warn
-
- * To check for \*.pyc and \*.pyo files.
-
- When zope.deprecation is fixed this warn() function can be removed again.
- Makes all the tests pass under Python-2.5.
-
-0.13 (2008-06-23)
-=================
-
-See: `upgrade_notes_0.13` for special notes on upgrading to this release.
-
-Restructuring
--------------
-
-* The basic component base classes (``Adapter``, ``MultiAdapter``,
- ``GlobalUtility``), their grokkers, as well as many of the basic
- directives have been factored out to a reusable
- ``grokcore.component`` package.
-
-* Ported directives to Martian's new directive implementation. As a
- result, many helper functions that were available from ``grok.util``
- were removed. The functionality is mostly available from the
- directives themselves now.
-
-* Refactored class grokkers to make use of Martian's new declarative
- way for retrieving directive data from classes, and Martian's new
- declarative way to write grokkers. See `upgrade_notes_0.13`
- for more information.
-
-
-Feature changes
----------------
-
-* ``GrokTemplate`` sets up the namespaces for the template by calling
- ``default_namespace() ``on the view component the template is
- associated with. As a result, ``ViewletManagers`` and ``Viewlet``
- can now push in the ``viewletmanager`` and ``viewlet`` namespaces
- into the template.
-
-* Updated tutorial section about grokproject to fit the latest changes.
-
-* Added ``grok.traversable`` directive for easy traversal to attributes and
- methods.
-
-* ``grok.require()`` can refer to subclasses of ``grok.Permission``
- directly, instead of their id. This, for one, avoids making typos in
- permission ids. Permission components *do* still need the
- grok.name() directive for defining the permission's id.
-
-* Added an optional parameter ``data`` to the method ``url()`` that
- accepts a dictionary that is then converted to a query string. See
-
- http://grok.zope.org/documentation/how-to/generate-urls-with-the-url-function-in-views/view
-
-* Added an ``OrderedContainer`` component.
-
-* Introduced the new `sphinx`-based documentation engine. See
- grokdocs/README.txt for details.
-
-* Merged the versions from the 3.4 KGS (known good set):
- http://download.zope.org/zope3.4/versions-3.4.0c1.cfg
-
- We are now using the latest Zope 3 releases for all Zope packages.
- See `upgrade_notes_0.13` for more information.
-
-* Added support for easier test setup based on ``z3c.testsetup``. This
- is a more stable and more powerful implementation of
- ``grok.testing.register_all_tests()``. See
-
- http://grok.zope.org/documentation/how-to/tests-with-grok-testing
-
- for details.
-
-* There is now a new ``IContext`` interface available. If you make
- your class implement that interface, it (and its subclasses) will be
- candidates for being a context in a module (for automatic context
- lookup if ``grok.context`` is not present). This relies on a feature
- introduced in ``grokcore.component`` 1.1.
-
-* ``grok.Model`` implements ``grok.interfaces.IContext`` now (which is
- imported from ``grokcore.component``). ``grok.Container`` now
- implements ``grok.interfaces.IContainer``. Traversers and default
- views have been set up for these interfaces, so that new
- implementations that function as a model or container can be easily
- created. Just use ``grok.implements(IContainer)`` or
- ``grok.implements(IContext)``. This is useful for Grok extensions
- that want to implement new content classes.
-
-Bug fixes
----------
-
-* Fix https://bugs.launchpad.net/grok/+bug/226555: the ``url()`` method on
- ``ViewletManager`` and ``Viewlet`` has been removed now that there's easy
- access to the view component the viewlet(manager) is registered for.
-
-* Fix https://bugs.launchpad.net/grok/+bug/231106: Use the
- viewletmanager.sort() method for sorting viewlets by using
- util.sort_components().
-
-* grok.REST views now have a properly set ``__parent__`` attribute and
- will correctly allow acquisition from parent objects, as it's used
- by the security policy for acquiring local grants, for example.
-
-* Fix https://bugs.launchpad.net/grok/+bug/229677:
- zope.app.securitypolicy egg missing. Now zope.app.securitypolicy
- 3.4.6 is additionally required by Grok and fetched by buildout.
-
-* Removed first testsetup hack from grok.testing.
-
-* Version 2.1 of z3c.autoinclude contained code that caused Grok to
- fail to start on some platforms if the system-supplied Python was
- used (at least on some versions of Ubuntu and Debian). Now include
- version 2.2 of z3c.autoinclude which should fix this problem. This
- fix was also made on Grok 0.12 in its online versions list after
- release.
-
-* Port fix of zope.formlib to correctly adapt the context to a FormField's
- interface, not the field.
-
-0.12 (2008-04-22)
-=================
-
-See: `upgrade_notes_0.12` for special notes on upgrading to this release.
-
-Feature changes
----------------
-
-* The new release needs new version of grokproject, please do::
-
- $ easy_install -U grokproject
-
-* Added testsetup classes in grok.testing to improve easy setup of
- unit- and functional tests.
-
-* Add support for viewlets and viewlet managers, ``grok.Viewlet``
- and ``grok.ViewletManager``.
-
-* Add a new directive, ``grok.order()``, which can be used to help
- sort components. At the time it is not used yet, but we intend to
- use it for the viewlets support. Note that this means Grok now
- requires Martian 0.9.3 or higher. See ``grok.interfaces`` for more
- documentation on this directive.
-
-* Now depend on ``z3c.autoinclude``. This allows the use of the
- ``<includeDependencies package="."/>`` directive, which automatically loads
- up ZCML needed for the dependencies listed in your project's
- ``setup.py``. The new release of grokproject adds this line
- automatically. Upgrade ``grokproject`` to make use of this
- functionality in new projects::
-
- $ easy_install -U grokproject
-
-* Classes that end with "-Base" are no longer implicitly considered base
- classes. These classes need to have the grok.baseclass() directive added to
- them explicitly.
-
- See `upgrade_notes_0.12` for more information.
-
-Bug fixes
----------
-
-* Do not register the publishTraverse and browserDefault methods of the
- JSON component as views.
-
-* Methods with names that start with an '_' are not registered as views
- for XMLRPC, REST and JSON components.
-
-* Use a configuration action for the registration of the static directory.
-
-* Fix imports from zope.app.securitypolicy.
-
-* Grok does not raise a GrokError anymore when it finds unassociated
- templates, but will issue a UserWarning.
-
-* Fix https://bugs.launchpad.net/grok/+bug/161948: grok.testing.grok()
- now also loads the ZPT template factories so that unit tests that
- need to configure views with ZPT templates continue to work.
-
-* Changed a few remaining references to ``grok.grok`` and
- ``grok.grok_component`` to their correct equivalents in
- ``grok.testing``.
-
-* ``grok.testing.grok_component()`` could not be used in a pure
- doctest. This needed a bugfix in Martian (since 0.9.2). Add a test
- that demonstrates this problem.
-
-* Fix https://bugs.launchpad.net/grok/+bug/162437: grok.Form and its
- subclasses did not implement IBrowserView.
-
-* Fix https://bugs.launchpad.net/grok/+bug/185414: grok introspector
- was broken for zipped eggs.
-
-* Fix https://bugs.launchpad.net/grok/+bug/125720: server control form
- had shutdown as default action, even when entering an admin message.
-
-* Fix https://bugs.launchpad.net/grok/+bug/80403: Fix situation where
- a module name is identical to the package name. At least modules
- with templates can now have same name as their package.
-
-* Multiple skins and REST protocols could be registered under the same
- name, but this is actually a conflict. Now give configuration
- conflict error when someone tries this.
-
-* Overriding traversal behavior using the ``traverse()`` method or
- ``grok.Traverser`` failed in the face of (REST) ``PUT`` and
- ``DELETE``. XML-RPC also failed when custom traversal was in use.
-
-* Fix https://bugs.launchpad.net/grok/+bug/187590 where config action
- discriminators for permission and role registrations were incorrect.
-
-* Permission definitions received the wrong, too high, configure
- action priority (not to be confused with grokker priority). In some
- cases this caused permissions to be defined later than they were
- used. Use a low action priority instead for permissions.
-
-Restructuring
--------------
-
-* Refactor commonalities out of meta.py.
-
-* zope.app.securitypolicy is no longer used. zope.securitypolicy provides
- all securitypolicy features used by Grok.
-
-0.11 (2007-11-08)
-=================
-
-See: `upgrade_notes_0.11` for special notes on upgrading to this release.
-
-Feature changes
----------------
-
-* Integrated skins and layers: ``grok.layer``, ``grok.IGrokLayer``,
- ``grok.Skin``.
-
-* Grok now supports hooking in new template languages without much work.
- See also doc/minitutorials/template-languages.txt. See Restructuring below
- for more techinical info.
-
-* Accessing a template macro via context/@@the_view/the_template is now
- deprecated for the standard ZPT story of using
- context/@@the_view/macro/the_template.
-
-* There is now a grok.direct() directive that can be used on GlobalUtilities
- to mark that the class provides the utility interface directly and need
- no instantiation.
-
-* Removed ``grok.define_permission`` in favor of the
- ``grok.Permission`` component base class. You should now subclass
- this base class to define permissions. See also
- doc/minitutorials/permissions.txt
-
-* Added the ``grok.Role`` component base class to define roles.
-
-* The admin UI now displays and offers deletion of broken objects.
-
-* Removed support for defining model schemas using an inner class with
- the special name ``fields``. This was abandoned in favor the usual
- Zope 3 way of defining schemas in interfaces and implementing them
- in our Grok models.
-
-* Integrated REST support. See doc/minitutorials/rest.txt for usage
- information.
-
-Bug fixes
----------
-
-* Remove zc.recipe.egg, zc.recipe.filestorage, zc.recipe.testrunner,
- zc.zope3recipes from version requirements.
-
-* The admin UI now shows interfaces in modules.
-
-* ``handle...`` is not a special function name anymore.
-
-* Views no longer need a custom ``AbsoluteURL`` view to determine
- their URL, since each instance now properly gets a ``__name__``
- attribute.
-
-* buildout.cfg extends versions.cfg to pin down the versions of the
- dependency tree. See also http://grok.zope.org/releaseinfo/readme.html
-
-Restructuring
--------------
-
-* Grokkers now emit configuration actions, much like ZCML directive
- handlers do. If you defined custom grokkers,
- see `upgrade_notes_0.11` for more information.
-
-* The new pluggable template language support includes some restructuring:
-
- - GrokPageTemplate is now split up into two. BaseTemplate, on which all
- templates need to be based, and GrokTemplate, which also provides a
- set of methods for easy integration of templating languages.
-
- - All objects based on GrokTemplate are now grokked, instead of having
- separate grokkers for each type of template.
-
- - The View is now completely template-language agnostic, which makes it
- easy to hook in new page template languages.
-
- - There are now new interfaces (ITemplate and ITemplateFileFactory)
- used when you implement support for a new templating language.
-
-* Changed the way grok's functional tests are set up. Instead of each
- test case doing its own test setup, it is now done once by the
- ftesting layer. This avoids ordering problems when some ftests
- would influence the environment of other ftests that were run later
- in time.
-
-0.10.2 (2007-10-24)
-===================
-
-Bug fixes
----------
-
-* Remove zc.recipe.egg, zc.recipe.filestorage, zc.recipe.testrunner,
- zc.zope3recipes from version requirements.
-
-* Require zope.app.error = 3.5.1
-
-0.10.1 (2007-10-10)
-===================
-
-Bug fixes
----------
-
-* buildout.cfg extends versions.cfg to pin down the versions of the
- dependency tree. This should avoid the situation where we release
- Grok, some dependency changes, and Grok breaks as a result. In
- conjunction with this we will also be releasing a new version of
- grokproject that will use this version infrastructure by default.
-
- For more information about this change, see:
- http://grok.zope.org/releaseinfo/readme.html
-
-0.10 (2007-08-21)
-=================
-
-Feature changes
----------------
-
-* Integrated admin user interface.
-
-* Configuration using Martian (http://pypi.python.org/pypi/martian).
-
-* Flash message infrastructure included.
-
-* Adjust dependencies for Grok so that grokproject should work on
- Windows.
-
-Bug fixes
----------
-
-* A fix in Martian where multiple grok.Model or grok.Container classes
- could result in something being found as a context twice.
-
-0.9 series (early 2007 until July 2007)
-=======================================
-
-Feature changes
----------------
-
-Grok was released in "continuous release" mode from SVN during this period.
-
-0.1 series (September 2006 until early 2007)
-============================================
-
-Feature changes
----------------
-
-Grok was created in September 2006.
+- Factored out of the ``grok`` package.
Deleted: grokcore.json/trunk/CREDITS.txt
===================================================================
--- grokcore.json/trunk/CREDITS.txt 2010-11-02 16:30:00 UTC (rev 118126)
+++ grokcore.json/trunk/CREDITS.txt 2010-11-03 00:50:24 UTC (rev 118127)
@@ -1,83 +0,0 @@
-CREDITS
-=======
-
-* Martijn Faassen (original developer)
-
-* Wolfgang Schnerring (original developer)
-
-* Christian Theune (original developer)
-
-* Philipp von Weitershausen (original developer)
-
-* Jan-Wijbrand Kolman (early developer (Grok Zwei sprint), release manager)
-
-* Uli Fouquet (admin interface, introspector, summer of code student)
-
-* Darryl Cousins (website, admin interface)
-
-* Kevin Teague (website, documentation)
-
-* Tim Terlegård (JSON support, viewlets, grokproject)
-
-* Maurits van Rees (grokproject, eggbasket)
-
-* Sebastian Ware (website effort, documentation)
-
-* Christian Zagrodnick (early grok discussions)
-
-* Mikhail Kashkin
-
-* Wim Boucqaert (admin interface layout improvements)
-
-* Kevin M. Smith (skins and layers support, viewlets)
-
-* Luciano Ramalho
-
-* Lennart Regebro (template pluggability)
-
-* Guido Wesdorp (template pluggability)
-
-* Brandon Rhodes (template pluggability, grokcore.component)
-
-* Godefroid Chapelle (conversion to Z3 configuration actions)
-
-* Souheil Chelfouh
-
-* Sylvain Viollon (work on martian, grokcore.formlib, grokcore.view,
- grokcore.viewlet)
-
-* Michael Haubenwallner (WSGI support, ZTK support)
-
-* Vincent Fretin
-
-* Reinout van Rees
-
-* Maurits van Rees
-
-* ME GROK (team mascot)
-
-Thank you
----------
-
-* The Zope 3 developers, who provided the mountain for Grok to stand
- on.
-
-* gocept for hosting the first grok sprint in Halle, Germany. Special
- thanks to Felicia Faassen Wong, Christian Zagrodnick and Magda
- Motyka for the delicious food.
-
-* Philipp von Weitershausen for hosting the second grok sprint in
- Dresden, Germany. Special thanks to Heinrich von Jagwitz for the
- delicious food.
-
-* The organizers of EuroPython 2007 in Vilnius for allowing us to host
- the third Grok sprint after EuroPython there.
-
-* ID StudioLab of the faculty of Industrial Design at the Delft
- University of Technology for sponsoring the development of REST
- support in Grok.
-
-* The Health Agency for hosting the "Grokkerdam sprint" in 2008.
-
-* GfU Cyrus in Cologne for generously hosting the "Neanderthal sprint" in
- 2007 and the "Neanderthal II sprint" in 2009.
Deleted: grokcore.json/trunk/INSTALL.txt
===================================================================
--- grokcore.json/trunk/INSTALL.txt 2010-11-02 16:30:00 UTC (rev 118126)
+++ grokcore.json/trunk/INSTALL.txt 2010-11-03 00:50:24 UTC (rev 118127)
@@ -1,83 +0,0 @@
-Preparing for grok development
-------------------------------
-
-The Grok development sandbox is set up via `zc.buildout`_
-
-.. _zc.buildout: http://cheeseshop.python.org/pypi/zc.buildout
-
-You may have setuptools already installed for your system Python. In
-that case, you may need to upgrade it first because buildout requires
-a very recent version::
-
- $ sudo easy_install -U setuptools
-
-If this command fails because easy_install is not available, there is
-a good chance you do not have setuptools available for your system
-Python. If so, there is no problem because setuptools will be
-installed locally by buildout.
-
-Bootstrap the buildout environment::
-
- $ python bootstrap/bootstrap.py
-
-and run the buildout command::
-
- $ bin/buildout
- [lots of stuff will be downloaded and installed here]
-
-Note that if you have more than one sandbox for a Zope-based web
-application, it will probably make sense to share the eggs between the
-different sandboxes. You can tell zc.buildout to use a central eggs
-directory by creating ``~/.buildout/default.cfg`` with the following
-contents::
-
- [buildout]
- eggs-directory = /home/bruno/buildout-eggs
-
-Note, that this is the grok core package. If you want to develop Grok
-applications you might consider to use `grokproject
-<http://pypi.python.org/pypi/grokproject>`_ instead.
-
-
-Running the demo applications
------------------------------
-
-You can start Zope with the demo applications installed with the
-following command:
-
- $ bin/paster serve parts/etc/deploy.ini
-
-If you now connect to port 8080 and log in with username 'grok',
-password 'grok', you should be able to add the grok-based applications
-(such as grokwiki) from the menu.
-
-Running the tests
------------------
-
-Grok's tests are easily run by executing the test runner that's
-installed in the ``bin`` directory::
-
- $ bin/test
-
-Generating the website files
-----------------------------
-
-Grok's tutorial documents for the website can easily be generated
-using the following scripts in ``bin``::
-
- $ bin/grokdocs2html
-
-The output is by default written to ``build/html/``.
-
-Run::
-
- $ bin/grokdocs2html -h
-
-to get all options supported.
-
-With::
-
- $ bin/grokdocs2latex
-
-you get LaTeX output which can be used to generate PDF docs. This
-requires a working LaTeX installed on your system.
Modified: grokcore.json/trunk/README.txt
===================================================================
--- grokcore.json/trunk/README.txt 2010-11-02 16:30:00 UTC (rev 118126)
+++ grokcore.json/trunk/README.txt 2010-11-03 00:50:24 UTC (rev 118127)
@@ -1,48 +1,2 @@
-Grok
-****
-
-What is grok?
-=============
-
-Grok is a smashing web framework based on `Zope Toolkit`_ technology.
-
-.. _`Zope Toolkit`: http://docs.zope.org/zopetoolkit
-
-Grok uses the Component Architecture and builds on Zope concepts like
-content objects (models), views, and adapters. Its simplicity lies in
-using **convention over configuration** and **sensible defaults** when
-wiring components together. That means neither a configuration
-language like ZCML nor a lot of repetition are needed to create a web
-application with grok.
-
-You can find out much more about Grok at our http://grok.zope.org
-website.
-
-Who is grok?
-============
-
-Grok is a friendly caveman from the Stone Age. He has a big club that
-he hunts mammoths with. He will also use this club to smash anything
-he doesn't like.
-
-"ME GROK SMASH ZCML!"
-
-Getting grok
-============
-
-The easiest way to get started with grok is to install the
-`grokproject <http://cheeseshop.python.org/pypi/grokproject>`_ package
-(e.g. via ``easy_install grokproject``) and then create a new project
-area by calling the ``grokproject`` script like so::
-
- $ grokproject MyProject
- ... many lines of output here
-
-This will create a project area in ``MyProject`` as well as download
-and install grok.
-
-You can also get grok from the subversion repository::
-
- svn co svn://svn.zope.org/repos/main/grok/trunk grok
-
-Then follow the instructions of ``INSTALL.txt``.
+grokcore.viewlet
+****************
Deleted: grokcore.json/trunk/TODO.txt
===================================================================
--- grokcore.json/trunk/TODO.txt 2010-11-02 16:30:00 UTC (rev 118126)
+++ grokcore.json/trunk/TODO.txt 2010-11-03 00:50:24 UTC (rev 118127)
@@ -1,121 +0,0 @@
-====
-TODO
-====
-
-Meta
-====
-
-- Check demo applications for issues with patterns (grok wiki, ldap address
- book)
-
-
-Core
-====
-
-- choice fields / sources (theuni)
-
-- testing strategy for the tutorial (faassen)
-
-- make it easier to write tests (wosc, faassen)
-
-- error reporting during grokking (provide file/line-number information
- on our extrinsically generated errors) (philikon)
-
-- What will happen if we make a utility a old style class and use the
- MRO stuff. Since we don't support non-persistent local utilities yet this
- may be a rare case.
-
-- What about local utilities that don't subclass persistent? Perhaps we
- can look for IPersistent and give an error if the utility doesn't
- state it is.
-
-- Change error messages: whenever we report about a callable, add
- () to the name. Core Python expections do this.
-
-- JSON support similar to XMLRPC.
-
-
-Schema/formlib support
-----------------------
-
-- support nested class 'fields' directly on a view (do we really want this?)
-
-- list form for grok.Container (w/ zc.table?)
-
-- delete action on list form
-
-- make formlib macros available in some form?
-
-- what about subclassing a model that has a 'fields'?
-
-
-Need to discuss
----------------
-
-- Do we want to ship Grok with a javascript library dependency such as
- MochiKit, to enable out of-the-box AJAX?
-
-- Make it even easier to set up the catalog (intids should be set up
- automatically if not already present. Perhaps Index grokkers?).
-
-- Testing support. Test grokkers?
-
-- Error pages: make it easy to register application-specific error
- pages for exceptions.
-
-- Easier queries: integrate hurry.query in some way?
-
-- fall back to a static resource that is defined in a package on a higher
- level if no static resource directory is defined locally in a package?
-
-- grok.grokkable (to allow grokking of imported things)
-
-- skins
-
-- form redirect
-
-- authentication (pau integration) (faassen)
-
-- sessions (get the session information for something, similar to
- annotations?)
-
-- menus - define a menu, associate a view with a menu (module-level,
- class-level)
-
-- making new widgets (faassen, philikon)
-
-- IMPORTANT: different strategies: grok.definefoo() versus n =
- grok.Foo(), watch out for consistency/symmetry/...
-
-- use ZCML's conflict resolution machinery; actions for Grok.
-
-- do not accept automatic template directory guessing convention for
- __init__.py, bail out with grok error instead?
-
-- grok.name, grok.template class restrictions (e.g. grok.template
- should only be usable from grok.View subclasses)
-
-- support grok.template(template) in addition to
- grok.template('name_of_template')?
-
-- support grok.resource on view class level?
-
-- should grok.context and grok.Model be order-dependent?
- (so their meaning becomes "below here, this is the context")
-
-- Do we want to initialize model attributes for any schema that the model
- implements (in addition to the initialization that is taking place for the
- model-level fields)?
-
-
-Punt
-----
-
-- making new fields
-
-- viewlets / content providers (LATER)
-
-- RDB - via extension: megrok.sqlalchemy for example - make it easy to
- go between the different schema implementations
-
-- containment constraints (wait for zope 3 to do them right)
Modified: grokcore.json/trunk/src/grokcore/json/__init__.py
===================================================================
--- grokcore.json/trunk/src/grokcore/json/__init__.py 2010-11-02 16:30:00 UTC (rev 118126)
+++ grokcore.json/trunk/src/grokcore/json/__init__.py 2010-11-03 00:50:24 UTC (rev 118127)
@@ -11,92 +11,9 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
-"""Grok
-"""
-from zope.interface import implements
-from zope.component import adapts
-from martian import ClassGrokker, InstanceGrokker, GlobalGrokker
-from martian import baseclass
-from martian.error import GrokError, GrokImportError
+from grokcore.json.components import JSON
-from grokcore.component import Adapter, MultiAdapter, GlobalUtility, Context
-from grokcore.component.decorators import subscribe, adapter, implementer
-from grokcore.component.directive import (
- context, name, title, description, provides, global_utility, direct)
-
-from grokcore.content import Model, Container, OrderedContainer
-
-from grokcore.security import Permission
-from grokcore.security import Public
-from grokcore.security import require
-
-from grokcore.view import PageTemplate
-from grokcore.view import PageTemplateFile
-from grokcore.view import DirectoryResource
-from grokcore.view import layer
-from grokcore.view import template
-from grokcore.view import templatedir
-from grokcore.view import skin
-from grokcore.view import url
-from grokcore.view import path
-
-from grokcore.viewlet import Viewlet
-from grokcore.viewlet import ViewletManager
-from grokcore.viewlet import view
-from grokcore.viewlet import viewletmanager
-from grokcore.viewlet import order
-
-from grokcore.formlib import action
-from grokcore.formlib import AutoFields
-from grokcore.formlib import Fields
-
-from grokcore.annotation import Annotation
-
-from grokcore.site import LocalUtility
-from grokcore.site import Site
-from grokcore.site import local_utility
-
-from zope.event import notify
-from zope.site.hooks import getSite
-from grok.util import getApplication
-from zope.lifecycleevent import (
- IObjectCreatedEvent, ObjectCreatedEvent,
- IObjectModifiedEvent, ObjectModifiedEvent,
- IObjectCopiedEvent, ObjectCopiedEvent)
-from zope.app.publication.interfaces import IBeforeTraverseEvent
-
-from zope.publisher.interfaces.browser import IBrowserRequest
-from zope.publisher.interfaces.browser import IDefaultBrowserLayer
-
-from zope.container.interfaces import (
- IObjectAddedEvent,
- IObjectMovedEvent,
- IObjectRemovedEvent,
- IContainerModifiedEvent)
-from zope.container.contained import (
- ObjectAddedEvent,
- ObjectMovedEvent,
- ObjectRemovedEvent,
- ContainerModifiedEvent)
-
-from grok.events import ApplicationInitializedEvent
-from grok.components import Application
-from grok.components import View, Form, AddForm, EditForm, DisplayForm
-from grok.components import XMLRPC, REST, JSON
-from grok.components import Traverser
-from grok.components import Indexes
-from grok.components import Role
-from grok.interfaces import IRESTSkinType, IRESTLayer
-from grok.interfaces import IApplicationInitializedEvent
-
-from grok.directive import (
- permissions, site, restskin, traversable)
-
-# BBB These two functions are meant for test fixtures and should be
-# imported from grok.testing, not from grok.
-from grok.testing import grok, grok_component
-
# Our __init__ provides the grok API directly so using 'import grok' is enough.
from grok.interfaces import IGrokAPI
from zope.interface import moduleProvides
Modified: grokcore.json/trunk/src/grokcore/json/components.py
===================================================================
--- grokcore.json/trunk/src/grokcore/json/components.py 2010-11-02 16:30:00 UTC (rev 118126)
+++ grokcore.json/trunk/src/grokcore/json/components.py 2010-11-03 00:50:24 UTC (rev 118127)
@@ -18,203 +18,21 @@
provided here.
"""
-import simplejson
-import zope.location
-from zope import component
from zope import interface
-from zope.securitypolicy.role import Role as securitypolicy_Role
from zope.publisher.browser import BrowserPage
-from zope.publisher.interfaces import NotFound
-from zope.publisher.interfaces.browser import IBrowserPublisher
-from zope.publisher.interfaces.http import IHTTPRequest
from zope.publisher.publish import mapply
-from zope.publisher.defaultview import getDefaultViewName
-from zope.container.interfaces import IReadContainer
-import grok
-import martian.util
-
+import simplejson
import grokcore.view
import grokcore.site
import grokcore.message
-from grok import interfaces, util
+from zope.interface import implements
-# BBB this is for import backward compatibility.
-from grokcore.content import Model, Container, OrderedContainer
-
-class Application(grokcore.site.Site):
- """Mixin for creating Grok application objects.
-
- When a `grok.Container` (or a `grok.Model`, though most developers
- use containers) also inherits from `grok.Application`, it not only
- gains the component registration abilities of a `grok.Site`, but
- will also be listed in the Grok admin control panel as one of the
- applications that the admin can install directly at the root of
- their Zope database.
-
- """
- interface.implements(interfaces.IApplication)
-
-
-class View(grokcore.view.View):
- """The base class for views with templates in Grok applications.
-
- Each class that inherits from `grok.View` is designed to "render" a
- category of content objects by reducing them to a document (often an
- HTML document). Every view has a name, and is invoked when users
- visit the URL of an eligible context object followed by the name of
- the view itself::
-
- http://example.com/app/folder/object/viewname
-
- If the view name might conflict with actual content inside of the
- context (in the above URL, the context might already contain an
- attribute or item named ``viewname``), then the URL can be explicit
- that it is asking for a view by preceding its name with ``@@``::
-
- http://example.com/app/folder/object/@@viewname
-
- Instead of returning a full document, views are sometimes used to
- provide only a snippet of information for inclusion in some larger
- document; the view can then be called from inside of another view's
- page template::
-
- <li tal:content="context/@@viewname">snippet goes here</li>
-
- A view class can specify the category of objects that it can render
- by calling the `grok.context()` directive with either a class or an
- interface. Otherwise, Grok will attempt to determine the context
- automatically by searching the view's module for exactly one
- `grok.Model` or `grok.Container` class (or some other class
- providing the interface `IContext`) and using that class, if found.
-
- Grok normally creates a view's name (the name used in URLs) by
- downcasing the name of the view class itself. The developer can
- override this by supplying the `grok.name()` directive instead.
-
- The view name ``index`` is special (this works whether the view
- class itself is named ``Index``, or whether ``grok.name('index')``
- is used instead). A view named ``index`` is used to render an
- object when the user visits its URL without appending a view name.
-
- Each view needs to generate and return a document. There are two
- ways of doing so: either the view can provide a `render()` method
- that returns a document, or the view can be associated with a page
- template that Grok will. Page templates can be associated with a
- view in three different ways:
-
- * Grok will automatically associate a view with a page template
- defined in an accompanying ``templates`` directory. If a view
- class ``MammothList`` occurs in a module ``<src>/animal.py``, for
- example, then Grok will look for a page template with the name
- ``<src>/animal_templates/mammothlist.pt``, where ``.pt`` can be
- any page-template extension recognized by Grok.
-
- * Grok will automatically associate a view with a page template
- object in the same module whose name is the downcased name of the
- view class itself. For example, a view ``MammothList`` might be
- defined in a module alongside an actual template instance named
- ``mammothlist``.
-
- * The developer can explicitly define the path to the page template
- file by providing the ``grok.template()`` directive.
-
- Before a page template is rendered, Grok will call the `update()`
- method on the view, if one is supplied, which can pre-compute values
- that the template will need to display. Both `render()` methods and
- `update()` methods will find the context for which the view is being
- rendered under ``self.context``.
-
- """
- interface.implements(interfaces.IGrokView)
-
- def application_url(self, name=None, data=None):
- """Return the URL of the nearest enclosing `grok.Application`."""
- return util.application_url(self.request, self.context, name, data)
-
- def flash(self, message, type='message'):
- """Send a short message to the user."""
- grokcore.message.send(message, type=type, name='session')
-
-
-class Form(grokcore.formlib.Form, View):
- """The base class for forms in Grok applications.
-
- A class that inherits from `grok.Form` is a `grok.View` whose
- template will be given information about the fields in its context,
- and use that information to render an HTML form for adding or
- editing the form. Generally developers use one of the subclasses:
-
- * `grok.AddForm`
- * `grok.DisplayForm`
- * `grok.EditForm`
-
- """
- interface.implements(interfaces.IGrokForm)
-
-
-class AddForm(grokcore.formlib.AddForm, View):
- """Base class for add forms in Grok applications."""
- interface.implements(interfaces.IGrokForm)
-
-
-class DisplayForm(grokcore.formlib.DisplayForm, View):
- """Base class for display forms in Grok applications."""
- interface.implements(interfaces.IGrokForm)
-
-
-class EditForm(grokcore.formlib.EditForm, View):
- """Base class for edit forms in Grok applications."""
- interface.implements(interfaces.IGrokForm)
-
-
-class ViewishViewSupport(grokcore.view.ViewSupport):
-
- def application_url(self, name=None, data=None):
- return util.application_url(self.request, self.context, name, data)
-
-
-class XMLRPC(ViewishViewSupport):
- """Base class for XML-RPC endpoints in Grok applications.
-
- When an application creates a subclass of `grok.XMLRPC`, it is
- creating an XML-RPC view. Like other Grok views, each `grok.XMLRPC`
- component can either use an explicit `grok.context()` directive to
- specify the kind of object it wraps, or else Grok will look through
- the same module for exactly one `grok.Model` or `grok.Container` (or
- other `IGrokContext` implementor) and make that class its context
- instead.
-
- Every object that is an instance of the wrapped class or interface
- becomes a legitimate XML-RPC server URL, offering as available
- procedures whatever methods have been defined inside of that
- `grok.XMLRPC` component. When a method is called over XML-RPC, any
- parameters are translated into normal Python data types and supplied
- as normal positional arguments. When the method returns a value or
- raises an exception, the result is converted back into an XML-RPC
- response for the client. In both directions, values are marshalled
- transparently to and from XML-RPC data structures.
-
- During the execution of an XML-RPC method, the object whose URL was
- used for the XML-RPC call is available as ``self.context``.
-
- """
-
-
-class REST(zope.location.Location, ViewishViewSupport):
- """Base class for REST views in Grok applications."""
- interface.implements(interfaces.IREST)
-
- def __init__(self, context, request):
- self.context = self.__parent__ = context
- self.request = request
-
-
-class JSON(BrowserPage, ViewishViewSupport):
+class JSON(BrowserPage, grokcore.view.ViewSupport):
"""Base class for JSON views in Grok applications."""
- interface.implements(interfaces.IGrokSecurityView)
+ implements(grokcore.view.IGrokSecurityView)
def __call__(self):
view_name = self.__view_name__
@@ -223,161 +41,3 @@
self.request.response.setHeader('Content-Type', 'application/json')
return simplejson.dumps(method_result)
-
-class Traverser(object):
- """Base class for traversers in Grok applications."""
- interface.implements(IBrowserPublisher)
-
- def __init__(self, context, request):
- self.context = context
- self.request = request
-
- def browserDefault(self, request):
- # if we have a RESTful request, we will handle
- # GET, POST and HEAD differently (PUT and DELETE are handled already
- # but not on the BrowserRequest layer but the HTTPRequest layer)
- if interfaces.IRESTLayer.providedBy(request):
- rest_view = component.getMultiAdapter(
- (self.context, self.request), name=request.method)
- return rest_view, ()
- view_name = getDefaultViewName(self.context, request)
- view_uri = "@@%s" % view_name
- return self.context, (view_uri,)
-
- def publishTraverse(self, request, name):
- subob = self.traverse(name)
- if subob is not None:
- return util.safely_locate_maybe(subob, self.context, name)
-
- traversable_dict = grok.traversable.bind().get(self.context)
- if traversable_dict:
- if name in traversable_dict:
- subob = getattr(self.context, traversable_dict[name])
- if callable(subob):
- subob = subob()
- return util.safely_locate_maybe(subob, self.context, name)
-
- # XXX Special logic here to deal with containers. It would be
- # good if we wouldn't have to do this here. One solution is to
- # rip this out and make you subclass ContainerTraverser if you
- # wanted to override the traversal behaviour of containers.
- if IReadContainer.providedBy(self.context):
- item = self.context.get(name)
- if item is not None:
- return item
-
- view = component.queryMultiAdapter((self.context, request), name=name)
- if view is not None:
- return view
-
- raise NotFound(self.context, name, request)
-
- def traverse(self, name):
- # this will be overridden by subclasses
- pass
-
-
-class ContextTraverser(Traverser):
- """Base class for context traversers in Grok applications.
-
- A context traverser is like a normal `grok.Traverser` but, instead
- of supplying its own `traverse()` method, it directs Grok to go call
- the ``traverse()`` method on the context itself in order to process
- the next name in the URL.
-
- """
- component.adapts(interfaces.IContext, IHTTPRequest)
-
- def traverse(self, name):
- traverse = getattr(self.context, 'traverse', None)
- if traverse:
- return traverse(name)
-
-
-class ContainerTraverser(Traverser):
- """Base class for container traversers in Grok applications.
-
- A container traverser is like a normal `grok.Traverser` but, instead
- of supplying its own ``traverse()`` method, Grok will either call
- the ``traverse()`` method on the context itself, if any, else call
- ``get()`` on the container (a getitem-style lookup) in order to
- resolve the next name in the URL.
-
- """
- component.adapts(interfaces.IContainer, IHTTPRequest)
-
- def traverse(self, name):
- traverse = getattr(self.context, 'traverse', None)
- if traverse:
- result = traverse(name)
- if result is not None:
- return result
- # try to get the item from the container
- return self.context.get(name)
-
-
-class IndexesClass(object):
- """Base class for index collections in a Grok application.
-
- A `grok.Indexes` utility provides one or more Zope Database content
- indexes for use in a `grok.Site` or `grok.Application`. The site or
- application that the indexes are intended for should be named with
- the `grok.site()` directive, and the kind of object to index should
- be named with a `grok.context()` directive.
-
- Inside their class, the developer should specify one or more
- `grok.index.Field` instances naming object attributes that should be
- indexed (and therefore searchable)::
-
- class ArticleIndex(grok.Indexes):
- grok.site(Newspaper)
- grok.context(Article)
- author = index.Field()
- title = index.Field()
- body = index.Text()
-
- See the `grok.index` module for more information on field types.
-
- Note that indexes are persistent: they are stored in the Zope
- database alongside the site or application that they index. They
- are created when the site or application is first created, and so an
- already-created site will not change just because the definition of
- one of its `grok.Indexes` changes; it will either have to be deleted
- and re-created, or some other operation performed to bring its
- indexes up to date.
-
- """
- def __init__(self, name, bases=(), attrs=None):
- if attrs is None:
- return
- indexes = {}
- for name, value in attrs.items():
- # Ignore everything that's not an index definition object
- # except for values set by directives
- if '.' in name:
- setattr(self, name, value)
- continue
- if not interfaces.IIndexDefinition.providedBy(value):
- continue
- indexes[name] = value
- self.__grok_indexes__ = indexes
- # __grok_module__ is needed to make defined_locally() return True for
- # inline templates
- self.__grok_module__ = martian.util.caller_module()
-
-Indexes = IndexesClass('Indexes')
-
-
-class Role(securitypolicy_Role):
- """Base class for roles in Grok applications.
-
- A role is a description of a class of users that gives them a
- machine-readable name, a human-readable title, and a set of
- permissions which users belong to that role should possess::
-
- class Editor(grok.Role):
- grok.name('news.Editor')
- grok.title('Editor')
- grok.permissions('news.EditArticle', 'news.PublishArticle')
-
- """
Deleted: grokcore.json/trunk/src/grokcore/json/directive.py
===================================================================
--- grokcore.json/trunk/src/grokcore/json/directive.py 2010-11-02 16:30:00 UTC (rev 118126)
+++ grokcore.json/trunk/src/grokcore/json/directive.py 2010-11-03 00:50:24 UTC (rev 118127)
@@ -1,133 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2006-2007 Zope Foundation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""Grok directives.
-
-This module defines Grok directives: the markers that users place
-inside of their classes (and sometimes in their modules, too) to
-direct how Grok registers their components. For example, the first
-directive defined below is `site`, which people programming Grok
-applications normally use like this::
-
- class MyIndex(grok.Indexes):
- grok.site(MySite)
- ...
-
-If the set of directives in this module looks rather small, remember
-that most of the directives available in Grok actually come from the
-`grokcore` modules on which Grok depends, where they have been placed so
-that other projects can use them without having to pull in all of Grok.
-
-"""
-
-import grok
-import martian
-import martian.util
-from grokcore.view.directive import TaggedValueStoreOnce
-
-
-class site(martian.Directive):
- """The `grok.site()` directive.
-
- This directive is used when creating a `grok.Indexes` subclass, to
- indicate the Grok site object for which the indexes should be built.
-
- """
- scope = martian.CLASS
- store = martian.ONCE
- validate = martian.validateInterfaceOrClass
-
-
-class permissions(martian.Directive):
- """The `grok.permissions()` directive.
-
- This directive is used inside of a `grok.Role` subclass to list the
- permissions which each member of the role should always possess.
- Note that permissions should be passed as strings, and that several
- permissions they can simply be supplied as multiple arguments; there
- is no need to place them inside of a tuple or list::
-
- class MyRole(grok.Role):
- grok.permissions('page.CreatePage', 'page.EditPage')
- ...
-
- """
- scope = martian.CLASS
- store = martian.ONCE
- default = []
-
- def validate(self, *values):
- for value in values:
- if martian.util.check_subclass(value, grok.Permission):
- continue
- if martian.util.not_unicode_or_ascii(value):
- raise grok.GrokImportError(
- "You can only pass unicode values, ASCII values, or "
- "subclasses of grok.Permission to the '%s' directive."
- % self.name)
-
- def factory(self, *values):
- permission_ids = []
- for value in values:
- if martian.util.check_subclass(value, grok.Permission):
- permission_ids.append(grok.name.bind().get(value))
- else:
- permission_ids.append(value)
- return permission_ids
-
-
-class traversable(martian.Directive):
- """The `grok.traversable()` directive.
-
- Each time this directive is used inside of a class, it designates an
- attribute of that class which URLs should be able to traverse. For
- example, the declaration:
-
- class Mammoth(grok.Model):
- grok.traversable('thighbone')
-
- means that if the URL `/app/mymammoth` designates a Mammoth, then
- `/app/mymammoth/thighbone` will also be a valid URL (assuming that
- the Mammoth instance, at runtime, indeed has an attribute by that
- name)! By default, the name that must be appended to the URL should
- simply be the same as the name of the attribute; but by providing a
- `name` keyword argument, the programmer can designate another name
- to appear in the URL instead of the raw attribute name.
-
- """
- scope = martian.CLASS
- store = martian.DICT
-
- def factory(self, attr, name=None):
- if name is None:
- name = attr
- return (name, attr)
-
-
-class restskin(martian.Directive):
- """The `grok.restskin()` directive.
-
- This directive is placed inside of `grok.IRESTLayer` subclasses to
- indicate what their layer name will be within a REST URL. Giving
- the skin ``grok.restskin('b')``, for example, will enable URLs that
- look something like `http://localhost/++rest++b/app`.
-
- """
- # We cannot do any better than to check for a class scope. Ideally we
- # would've checked whether the context is indeed an Interface class.
- scope = martian.CLASS
- store = TaggedValueStoreOnce()
- validate = martian.validateText
-
- def factory(self, value=None):
- return value
Deleted: grokcore.json/trunk/src/grokcore/json/events.py
===================================================================
--- grokcore.json/trunk/src/grokcore/json/events.py 2010-11-02 16:30:00 UTC (rev 118126)
+++ grokcore.json/trunk/src/grokcore/json/events.py 2010-11-03 00:50:24 UTC (rev 118127)
@@ -1,31 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2006-2007 Zope Foundation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""Events for Grok application components.
-
-The events described here are *not* trigged by Grok itself. They are
-conveniently provided to be used in your own application.
-
-"""
-from grok import interfaces
-from zope.interface import implements
-
-
-class ApplicationInitializedEvent(object):
- """A Grok Application has been created and is now ready to be used.
- """
- implements(interfaces.IApplicationInitializedEvent)
-
- def __init__(self, app):
- assert interfaces.IApplication.providedBy(app)
- self.object = app
Deleted: grokcore.json/trunk/src/grokcore/json/index.py
===================================================================
--- grokcore.json/trunk/src/grokcore/json/index.py 2010-11-02 16:30:00 UTC (rev 118126)
+++ grokcore.json/trunk/src/grokcore/json/index.py 2010-11-03 00:50:24 UTC (rev 118127)
@@ -1,105 +0,0 @@
-#############################################################################
-#
-# Copyright (c) 2007-2008 Zope Foundation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""Grok index definitions
-"""
-import sys
-
-from zope.interface import implements
-from zope.interface.interfaces import IMethod, IInterface
-
-from zope.catalog.field import FieldIndex
-from zope.catalog.text import TextIndex
-from zc.catalog.catalogindex import SetIndex
-
-from martian.error import GrokError, GrokImportError
-from martian.util import frame_is_class
-
-from grok.interfaces import IIndexDefinition
-
-
-class IndexDefinition(object):
- """The definition of a particular index in a `grok.Indexes` class.
-
- This base class defines the actual behavior of `grok.index.Field`
- and the other kinds of attribute index that Grok supports. Upon our
- instantiation, we save every parameter that we were passed; later,
- if an index actually needs to be created (which is typically at the
- moment when a new `grok.Application` object is added to the Zope
- Database), then our `setup()` method gets called.
-
- The only parameter that is actually significant to us is `attribute`
- which (optionally) defines the attribute we should index. All other
- parameters are simply passed along to the Zope index we create,
- which interprets them as configuration details of its own.
-
- Note that, since index creation (and thus a call to our `setup()`
- method) currently occurs only during the creation of a new Grok
- `Application` object in the Zope Database, the presence of this
- declaration in Grok application code is nearly always a no-op.
-
- """
- implements(IIndexDefinition)
-
- index_class = None
-
- def __init__(self, *args, **kw):
- frame = sys._getframe(1)
- if not frame_is_class(frame):
- raise GrokImportError(
- "%r can only be instantiated on class level." % self.__class__)
- # store any extra parameters to pass to index later
- self._args = args
- self._attribute = kw.pop('attribute', None)
- self._kw = kw
-
- def setup(self, catalog, name, context, module_info):
- # If the user supplied attribute= when instantiating us, we
- # allow that value to override the attribute name under which we
- # are actually stored inside of the `grok.Indexes` instance.
- if self._attribute is not None:
- field_name = self._attribute
- else:
- field_name = name
-
- if IInterface.providedBy(context):
- try:
- method = context[field_name]
- except KeyError:
- raise GrokError("grok.Indexes in %r refers to an attribute or "
- "method %r on interface %r, but this does not "
- "exist." % (module_info.getModule(),
- field_name, context), None)
- call = IMethod.providedBy(method)
- else:
- call = callable(getattr(context, field_name, None))
- context = None # no interface lookup
- catalog[name] = self.index_class(field_name=field_name,
- interface=context,
- field_callable=call,
- *self._args, **self._kw)
-
-
-class Field(IndexDefinition):
- """A `grok.Indexes` index that matches against an entire field."""
- index_class = FieldIndex
-
-
-class Text(IndexDefinition):
- """A `grok.Indexes` index supporting full-text searches of a field."""
- index_class = TextIndex
-
-
-class Set(IndexDefinition):
- """A `grok.Indexes` index supporting keyword searches of a field."""
- index_class = SetIndex
Modified: grokcore.json/trunk/src/grokcore/json/interfaces.py
===================================================================
--- grokcore.json/trunk/src/grokcore/json/interfaces.py 2010-11-02 16:30:00 UTC (rev 118126)
+++ grokcore.json/trunk/src/grokcore/json/interfaces.py 2010-11-03 00:50:24 UTC (rev 118127)
@@ -13,225 +13,15 @@
##############################################################################
"""Grok interfaces
"""
-from zope import interface
-from zope.interface.interfaces import IInterface
-from zope.component.interfaces import IObjectEvent
-from zope.publisher.interfaces.http import IHTTPRequest
-from zope.container.interfaces import IContainer as IContainerBase
+from zope.interface import Attribute
# Expose interfaces from grokcore.* packages as well:
-import grokcore.annotation.interfaces
import grokcore.component.interfaces
-import grokcore.formlib.interfaces
import grokcore.security.interfaces
-import grokcore.site.interfaces
import grokcore.view.interfaces
-import grokcore.viewlet.interfaces
-from grokcore.component.interfaces import IContext
-from grokcore.component.interfaces import IGrokErrors
-
-class IGrokBaseClasses(grokcore.annotation.interfaces.IBaseClasses,
- grokcore.component.interfaces.IBaseClasses,
+class IGrokcoreJSONAPI(grokcore.component.interfaces.IBaseClasses,
grokcore.security.interfaces.IBaseClasses,
- grokcore.site.interfaces.IBaseClasses,
grokcore.view.interfaces.IBaseClasses):
- Model = interface.Attribute("Base class for persistent content objects "
- "(models).")
- Container = interface.Attribute("Base class for containers.")
- OrderedContainer = interface.Attribute("Base class for ordered containers.")
- Application = interface.Attribute("Base class for applications.")
- XMLRPC = interface.Attribute("Base class for XML-RPC methods.")
- JSON = interface.Attribute("Base class for JSON methods.")
- REST = interface.Attribute("Base class for REST views.")
- Traverser = interface.Attribute("Base class for custom traversers.")
- Indexes = interface.Attribute("Base class for catalog index definitions.")
- Role = interface.Attribute("Base class for roles.")
-
-
-class IGrokDirectives(grokcore.component.interfaces.IDirectives,
- grokcore.security.interfaces.IDirectives,
- grokcore.site.interfaces.IDirectives,
- grokcore.view.interfaces.IDirectives):
-
- def permissions(permissions):
- """Specify the permissions that comprise a role.
- """
-
- def site(class_or_interface):
- """Specifies the site that an indexes definition is for.
-
- It can only be used inside grok.Indexes subclasses.
- """
-
-
-class IGrokEvents(interface.Interface):
-
- IObjectCreatedEvent = interface.Attribute("")
-
- ObjectCreatedEvent = interface.Attribute("")
-
- IObjectModifiedEvent = interface.Attribute("")
-
- ObjectModifiedEvent = interface.Attribute("")
-
- IObjectCopiedEvent = interface.Attribute("")
-
- ObjectCopiedEvent = interface.Attribute("")
-
- IObjectAddedEvent = interface.Attribute("")
-
- ObjectAddedEvent = interface.Attribute("")
-
- IObjectMovedEvent = interface.Attribute("")
-
- ObjectMovedEvent = interface.Attribute("")
-
- IObjectRemovedEvent = interface.Attribute("")
-
- ObjectRemovedEvent = interface.Attribute("")
-
- IContainerModifiedEvent = interface.Attribute("")
-
- ContainerModifiedEvent = interface.Attribute("")
-
- IBeforeTraverseEvent = interface.Attribute("")
-
- IApplicationInitializedEvent = interface.Attribute("")
-
- ApplicationInitializedEvent = interface.Attribute("")
-
-
-class IGrokAPI(grokcore.formlib.interfaces.IGrokcoreFormlibAPI,
- grokcore.security.interfaces.IGrokcoreSecurityAPI,
- grokcore.site.interfaces.IGrokcoreSiteAPI,
- grokcore.view.interfaces.IGrokcoreViewAPI,
- grokcore.viewlet.interfaces.IGrokcoreViewletAPI,
- IGrokBaseClasses, IGrokDirectives,
- IGrokEvents, IGrokErrors):
-
- # BBB this is deprecated
- def grok(dotted_name):
- """Grok a module or package specified by ``dotted_name``.
-
- NOTE: This function will be removed from the public Grok
- public API. For tests and interpreter sessions, use
- grok.testing.grok().
- """
-
- # BBB this is deprecated
- def grok_component(name, component, context=None, module_info=None,
- templates=None):
- """Grok an arbitrary object. Can be useful during testing.
-
- name - the name of the component (class name, or global instance name
- as it would appear in a module).
- component - the object (class, etc) to grok.
- context - the context object (optional).
- module_info - the module being grokked (optional).
- templates - the templates registry (optional).
-
- Note that context, module_info and templates might be required
- for some grokkers which rely on them.
-
- NOTE: This function will be removed from the public Grok
- public API. For tests and interpreter sessions, use
- grok.testing.grok_component().
- """
-
- def notify(event):
- """Send ``event`` to event subscribers."""
-
- def getSite():
- """Get the current site."""
-
- def getApplication():
- """Return the nearest enclosing `grok.Application`."""
-
- IRESTSkinType = interface.Attribute('The REST skin type')
-
-
-class IGrokView(grokcore.view.interfaces.IGrokView):
- """Grok views all provide this interface."""
-
- def application_url(name=None):
- """Return the URL of the closest application object in the
- hierarchy or the URL of a named object (``name`` parameter)
- relative to the closest application object.
- """
-
- def flash(message, type='message'):
- """Send a short message to the user."""
-
-
-class IGrokForm(grokcore.formlib.interfaces.IGrokForm, IGrokView):
- """All Grok forms provides this interface."""
-
-
-class IREST(interface.Interface):
- context = interface.Attribute("Object that the REST handler presents.")
-
- request = interface.Attribute("Request that REST handler was looked"
- "up with.")
-
- body = interface.Attribute(
- """The text of the request body.""")
-
-
-class IApplication(interface.Interface):
- """Marker-interface for grok application factories.
-
- Used to register applications as utilities to look them up and
- provide a list of grokked applications.
- """
-
-
-class IIndexDefinition(interface.Interface):
- """Define an index for grok.Indexes.
- """
-
- def setup(catalog, name, context):
- """Set up index called name in given catalog.
-
- Use name for index name and attribute to index. Set up
- index for interface or class context.
- """
-
-
-class IRESTLayer(IHTTPRequest):
- """REST-specific Request functionality.
-
- Base Interfaces for defining REST-layers.
- """
-
-
-class IRESTSkinType(IInterface):
- """Skin type for REST requests.
- """
-
-
-class IContainer(IContext, IContainerBase):
- """A Grok container.
- """
-
-
-class IGrokSecurityView(interface.Interface):
- """A view treated special by the Grok publisher.
-
- Views that provide this interface are treated more generously by
- the Grok publisher, as they are allowed to use attributes, which
- are not covered by permission setttings.
-
- `grok.Permission` and `grok.require` settings however, will be
- applied to such views.
- """
-
-
-class IApplicationInitializedEvent(IObjectEvent):
- """A Grok Application has been created with success and is now ready
- to be used.
-
- This event can be used to trigger the creation of contents or other tasks
- that require the application to be fully operational : utilities installed
- and indexes created in the catalog."""
+ JSON = Attribute("Base class for JSON methods.")
Modified: grokcore.json/trunk/src/grokcore/json/meta.py
===================================================================
--- grokcore.json/trunk/src/grokcore/json/meta.py 2010-11-02 16:30:00 UTC (rev 118126)
+++ grokcore.json/trunk/src/grokcore/json/meta.py 2010-11-03 00:50:24 UTC (rev 118127)
@@ -11,193 +11,17 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
-"""Grokkers for Grok-configured components.
-
-This `meta` module contains the actual grokker mechanisms for which the
-Grok web framework is named. A directive in the adjacent `meta.zcml`
-file directs the `martian` library to scan this file, where it discovers
-and registers the grokkers you see below. The grokkers are then active
-and available as `martian` recursively examines the packages and modules
-of a Grok-based web application.
-
"""
-import zope.component.interface
-from zope import interface, component
-from zope.interface.interface import InterfaceClass
-from zope.publisher.interfaces.browser import (IDefaultBrowserLayer,
- IBrowserPublisher)
-from zope.publisher.interfaces.http import IHTTPRequest
-
-from zope.publisher.interfaces.xmlrpc import IXMLRPCRequest
-from zope.securitypolicy.interfaces import IRole
-from zope.securitypolicy.rolepermission import rolePermissionManager
-
-from zope.i18nmessageid import Message
-from zope.intid import IntIds
-from zope.intid.interfaces import IIntIds
-from zope.catalog.catalog import Catalog
-from zope.catalog.interfaces import ICatalog
-from zope.location import Location
-from zope.exceptions.interfaces import DuplicationError
-from zope.publisher.xmlrpc import XMLRPCView
-
+"""
import martian
-from martian.error import GrokError
-
import grok
-from grok import components
-from grok.util import make_checker
-from grok.interfaces import IRESTSkinType
+from grokcore.json import JSON
+from grokcore.view import layer, make_checker
+from zope.component import provideAdapter
+from zope.interface import Interface
+from zope.publisher.interfaces.browser import IDefaultBrowserLayer
-import grokcore.site.interfaces
-from grokcore.security.meta import PermissionGrokker
-from grokcore.view.meta.views import default_fallback_to_name
-
-
-class MethodPublisher(XMLRPCView, Location):
- """Copied from zope.app.publisher.xmlrpc to get rid of that dependency.
- """
- def __getParent(self):
- return hasattr(self, '_parent') and self._parent or self.context
-
- def __setParent(self, parent):
- self._parent = parent
-
- __parent__ = property(__getParent, __setParent)
-
-
-class XMLRPCGrokker(martian.MethodGrokker):
- """Grokker for methods of a `grok.XMLRPC` subclass.
-
- When an application defines a `grok.XMLRPC` view, we do not actually
- register the view with the Component Architecture. Instead, we grok
- each of its methods separately, placing them each inside of a new
- class that we create on-the-fly by calling `type()`. We make each
- method the `__call__()` method of its new class, since that is how
- Zope always invokes views. And it is this new class that is then
- made the object of the two configuration actions that we schedule:
- one to activate it as an XML-RPC adapter for the context, and the
- other to prepare a security check for the adapter.
-
- """
- martian.component(grok.XMLRPC)
- martian.directive(grok.context)
- martian.directive(grok.require, name='permission')
-
- def execute(self, factory, method, config, context, permission, **kw):
- name = method.__name__
-
- # Make sure that the class inherits MethodPublisher, so that the
- # views have a location
- method_view = type(
- factory.__name__, (factory, MethodPublisher),
- {'__call__': method})
-
- adapts = (context, IXMLRPCRequest)
- config.action(
- discriminator=('adapter', adapts, interface.Interface, name),
- callable=component.provideAdapter,
- args=(method_view, adapts, interface.Interface, name),
- )
- config.action(
- discriminator=('protectName', method_view, '__call__'),
- callable=make_checker,
- args=(factory, method_view, permission),
- )
- return True
-
-
-class RESTGrokker(martian.MethodGrokker):
- """Grokker for methods of a `grok.REST` subclass.
-
- When an application defines a `grok.REST` view, we do not actually
- register the view with the Component Architecture. Instead, we grok
- each of its methods separately, placing them each inside of a new
- class that we create on-the-fly by calling `type()`. We make each
- method the `__call__()` method of its new class, since that is how
- Zope always invokes views. And it is this new class that is then
- made the object of the two configuration actions that we schedule:
- one to activate it as a REST adapter for the context, and the other
- to prepare a security check for the adapter.
-
- This results in several registered views, typically with names like
- `GET`, `PUT`, and `POST` - one for each method that the `grok.REST`
- subclass defines.
-
- """
- martian.component(grok.REST)
- martian.directive(grok.context)
- martian.directive(grok.layer, default=grok.IRESTLayer)
- martian.directive(grok.require, name='permission')
-
- def execute(self, factory, method, config, permission, context,
- layer, **kw):
- name = method.__name__
-
- method_view = type(
- factory.__name__, (factory,),
- {'__call__': method})
-
- adapts = (context, layer)
- config.action(
- discriminator=('adapter', adapts, interface.Interface, name),
- callable=component.provideAdapter,
- args=(method_view, adapts, interface.Interface, name),
- )
- config.action(
- discriminator=('protectName', method_view, '__call__'),
- callable=make_checker,
- args=(factory, method_view, permission),
- )
- return True
-
-
-_restskin_not_used = object()
-
-
-class RestskinInterfaceDirectiveGrokker(martian.InstanceGrokker):
- """Grokker for interfaces providing the `grok.restskin()` directive.
-
- Applications create REST skins by subclassing `grok.IRESTLayer`
- and providing the subclass with a `grok.restskin()` directive giving
- the prefix string which distinguishes that REST layers from others.
- This grokker registers those skins.
-
- """
- martian.component(InterfaceClass)
-
- def grok(self, name, interface, module_info, config, **kw):
- # This `InstanceGrokker` will be called for every instance of
- # `InterfaceClass` - that is, for every interface defined in an
- # application module! So we have to do our own filtering, by
- # checking whether each interface includes the `grok.restskin()`
- # directive, and skipping those that do not.
- restskin = grok.restskin.bind(default=_restskin_not_used
- ).get(interface)
- if restskin is _restskin_not_used:
- # The restskin directive is not actually used on the found
- # interface.
- return False
-
- if not interface.extends(grok.IRESTLayer):
- # For REST layers it is required to extend IRESTLayer.
- raise GrokError(
- "The grok.restskin() directive is used on interface %r. "
- "However, %r does not extend IRESTLayer which is "
- "required for interfaces that are used as layers and are to "
- "be registered as a restskin."
- % (interface.__identifier__, interface.__identifier__),
- interface)
-
- config.action(
- discriminator=('restprotocol', restskin),
- callable=zope.component.interface.provideInterface,
- args=(restskin, interface, IRESTSkinType))
-
- return True
-
-
class JSONGrokker(martian.MethodGrokker):
"""Grokker for methods of a `grok.JSON` subclass.
@@ -212,10 +36,10 @@
to prepare a security check for the adapter.
"""
- martian.component(grok.JSON)
+ martian.component(JSON)
martian.directive(grok.context)
martian.directive(grok.require, name='permission')
- martian.directive(grok.layer, default=IDefaultBrowserLayer)
+ martian.directive(layer, default=IDefaultBrowserLayer)
def execute(
self, factory, method, config, context, permission, layer, **kw):
@@ -229,9 +53,9 @@
name = method.__name__
config.action(
- discriminator=('adapter', adapts, interface.Interface, name),
- callable=component.provideAdapter,
- args=(method_view, adapts, interface.Interface, name))
+ discriminator=('adapter', adapts, Interface, name),
+ callable=provideAdapter,
+ args=(method_view, adapts, Interface, name))
config.action(
discriminator=('protectName', method_view, '__call__'),
@@ -239,178 +63,3 @@
args=(factory, method_view, permission))
return True
-
-
-class TraverserGrokker(martian.ClassGrokker):
- """Grokker for subclasses of `grok.Traverser`."""
- martian.component(grok.Traverser)
- martian.directive(grok.context)
-
- def execute(self, factory, config, context, **kw):
- adapts = (context, IHTTPRequest)
- config.action(
- discriminator=('adapter', adapts, IBrowserPublisher, ''),
- callable=component.provideAdapter,
- args=(factory, adapts, IBrowserPublisher),
- )
- return True
-
-
-class RoleGrokker(martian.ClassGrokker):
- """Grokker for components subclassed from `grok.Role`.
-
- Each role is registered as a global utility providing the service
- `IRole` under its own particular name, and then granted every
- permission named in its `grok.permission()` directive.
-
- """
- martian.component(grok.Role)
- martian.priority(martian.priority.bind().get(PermissionGrokker()) - 1)
- martian.directive(grok.name)
- martian.directive(grok.title, get_default=default_fallback_to_name)
- martian.directive(grok.description)
- martian.directive(grok.permissions)
-
- def execute(self, factory, config, name, title, description,
- permissions, **kw):
- if not name:
- raise GrokError(
- "A role needs to have a dotted name for its id. Use "
- "grok.name to specify one.", factory)
- # We can safely convert to unicode, since the directives makes sure
- # it is either unicode already or ASCII.
- if not isinstance(title, Message):
- title = unicode(title)
- if not isinstance(description, Message):
- description = unicode(description)
- role = factory(unicode(name), title, description)
-
- config.action(
- discriminator=('utility', IRole, name),
- callable=component.provideUtility,
- args=(role, IRole, name),
- )
-
- for permission in permissions:
- config.action(
- discriminator=('grantPermissionToRole', permission, name),
- callable=rolePermissionManager.grantPermissionToRole,
- args=(permission, name),
- )
- return True
-
-
-class ApplicationGrokker(martian.ClassGrokker):
- """Grokker for Grok application classes."""
- martian.component(grok.Application)
- martian.priority(500)
-
- def grok(self, name, factory, module_info, config, **kw):
- # XXX fail loudly if the same application name is used twice.
- provides = grok.interfaces.IApplication
- name = '%s.%s' % (module_info.dotted_name, name)
- config.action(
- discriminator=('utility', provides, name),
- callable=component.provideUtility,
- args=(factory, provides, name),
- )
- return True
-
-
-class IndexesGrokker(martian.InstanceGrokker):
- """Grokker for Grok index bundles."""
- martian.component(components.IndexesClass)
-
- def grok(self, name, factory, module_info, config, **kw):
- site = grok.site.bind().get(factory)
- context = grok.context.bind().get(factory, module_info.getModule())
- catalog_name = grok.name.bind().get(factory)
-
- if site is None:
- raise GrokError("No site specified for grok.Indexes "
- "subclass in module %r. "
- "Use grok.site() to specify."
- % module_info.getModule(),
- factory)
- indexes = getattr(factory, '__grok_indexes__', None)
- if indexes is None:
- return False
-
- subscriber = IndexesSetupSubscriber(catalog_name, indexes,
- context, module_info)
- subscribed = (site, grok.IObjectAddedEvent)
- config.action(
- discriminator=None,
- callable=component.provideHandler,
- args=(subscriber, subscribed),
- )
- return True
-
-
-class IndexesSetupSubscriber(object):
- """Helper that sets up indexes when their Grok site is created.
-
- Each `grok.Indexes` class serves as an assertion that, whenever an
- instance of its `grok.site()` is created, the given list of indexes
- should be generated as well. But a long period of time could elapse
- between when the application starts (and its indexes are grokked),
- and the moment, maybe days or weeks later, when a new instance of
- that `grok.Site` is created. Hence this `IndexesSetupSubscriber`:
- it can be instantiated at grokking time with the index information,
- and then registered with the Component Architecture as an event that
- should be fired later, whenever the right kind of `grok.Site` is
- instantiated. At that point its `__call__` method is kicked off and
- it makes sure the index catalogs get created properly.
-
- """
- def __init__(self, catalog_name, indexes, context, module_info):
- self.catalog_name = catalog_name
- self.indexes = indexes
- self.context = context
- self.module_info = module_info
-
- def __call__(self, site, event):
- # make sure we have an intids
- self._createIntIds(site)
- # get the catalog
- catalog = self._createCatalog(site)
- # now install indexes
- for name, index in self.indexes.items():
- try:
- index.setup(catalog, name, self.context, self.module_info)
- except DuplicationError:
- raise GrokError(
- "grok.Indexes in module %r causes "
- "creation of catalog index %r in catalog %r, "
- "but an index with that name is already present." %
- (self.module_info.getModule(), name, self.catalog_name),
- None)
-
- def _createCatalog(self, site):
- """Create the catalog if needed and return it.
-
- If the catalog already exists, return that.
-
- """
- catalog = zope.component.queryUtility(
- ICatalog, name=self.catalog_name, context=site, default=None)
- if catalog is not None:
- return catalog
- catalog = Catalog()
- setupUtility = component.getUtility(
- grokcore.site.interfaces.IUtilityInstaller)
- setupUtility(site, catalog, ICatalog, name=self.catalog_name)
- return catalog
-
- def _createIntIds(self, site):
- """Create intids if needed, and return it.
- """
- intids = zope.component.queryUtility(
- IIntIds, context=site, default=None)
- if intids is not None:
- return intids
- intids = IntIds()
- setupUtility = component.getUtility(
- grokcore.site.interfaces.IUtilityInstaller)
- setupUtility(site, intids, IIntIds)
- return intids
Deleted: grokcore.json/trunk/src/grokcore/json/publication.py
===================================================================
--- grokcore.json/trunk/src/grokcore/json/publication.py 2010-11-02 16:30:00 UTC (rev 118126)
+++ grokcore.json/trunk/src/grokcore/json/publication.py 2010-11-03 00:50:24 UTC (rev 118127)
@@ -1,182 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2007 Zope Foundation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""Grok publication factories and classes.
-
-These factories, and the publication classes they return, make Grok
-security different from the way that security normal operates during
-Zope publication. Instead of security proxies being wrapped around
-every object generated during traversal, and then wrapped around the
-final object before it is viewed, only a single security check is done
-when Grok is in charge: a check to see whether the view selected at the
-end of the traversal process is, in fact, permitted to display the
-object.
-
-"""
-from grok.rest import GrokMethodNotAllowed
-
-from zope import component
-from zope.security.proxy import removeSecurityProxy
-from zope.security.checker import selectChecker
-from zope.publisher.publish import mapply
-
-from zope.publisher.interfaces.http import IHTTPException
-from zope.publisher.interfaces.browser import IBrowserView
-
-from zope.app.publication.http import BaseHTTPPublication, HTTPPublication
-from zope.app.publication.browser import BrowserPublication
-from zope.app.publication.requestpublicationfactories import \
- BrowserFactory, XMLRPCFactory, HTTPFactory
-
-from grok.interfaces import IGrokSecurityView
-
-
-class ZopePublicationSansProxy(object):
- """Grok mixin that makes a publisher remove security proxies.
-
- This mixin overrides three methods from the `IPublication`
- interface (defined in `zope.publisher.interfaces`) to alter their
- security behavior. The normal Zope machinery wraps a security
- proxy around the application object returned by
- `getApplication()`, and around each of the objects returned as
- `traverseName()` is then called for each URL component. The
- versions here strip the security proxy off instead, returning the
- bare object (unless the object is a non-Grok view, in which case
- we leave the proxy installed for important security
- reasons). Non-Grok views however, are handled like Grok views, if
- they provide `grok.interfaces.IGrokSecurityView`.
-
- Finally, when `callObject()` is asked to render
- the view, we quickly re-install a security proxy on the object, make
- sure that the current user is indeed allowed to invoke `__call__()`,
- then pass the bare object to the rendering machinery.
-
- The result is that, in place of the elaborate series of security
- checks made during the processing of a normal Zope request, Grok
- makes only a single security check: to see if the view can be
- permissibly rendered or not.
-
- """
- def getApplication(self, request):
- result = super(ZopePublicationSansProxy, self).getApplication(request)
- return removeSecurityProxy(result)
-
- def traverseName(self, request, ob, name):
- result = super(ZopePublicationSansProxy, self).traverseName(
- request, ob, name)
- bare_result = removeSecurityProxy(result)
- if IBrowserView.providedBy(bare_result):
- if IGrokSecurityView.providedBy(bare_result):
- return bare_result
- else:
- return result
- else:
- return bare_result
-
- def callObject(self, request, ob):
- checker = selectChecker(ob)
- if checker is not None:
- checker.check(ob, '__call__')
- return super(ZopePublicationSansProxy, self).callObject(request, ob)
-
-
-class GrokBrowserPublication(ZopePublicationSansProxy, BrowserPublication):
- """Combines `BrowserPublication` with the Grok sans-proxy mixin.
-
- In addition to the three methods that are overridden by the
- `ZopePublicationSansProxy`, this class overrides a fourth: the
- `getDefaultTraversal()` method, which strips the security proxy from
- the object being returned by the normal method.
-
- """
- def getDefaultTraversal(self, request, ob):
- obj, path = super(GrokBrowserPublication, self).getDefaultTraversal(
- request, ob)
- return removeSecurityProxy(obj), path
-
-
-class GrokBrowserFactory(BrowserFactory):
- """Returns the classes Grok uses for browser requests and publication.
-
- When an instance of this class is called, it returns a 2-element
- tuple containing:
-
- - The request class that Grok uses for browser requests.
- - The publication class that Grok uses to publish to a browser.
-
- """
- def __call__(self):
- request, publication = super(GrokBrowserFactory, self).__call__()
- return request, GrokBrowserPublication
-
-
-class GrokXMLRPCPublication(ZopePublicationSansProxy, BaseHTTPPublication):
- """Combines `BaseHTTPPublication` with the Grok sans-proxy mixin."""
-
-
-class GrokXMLRPCFactory(XMLRPCFactory):
- """Returns the classes Grok uses for browser requests and publication.
-
- When an instance of this class is called, it returns a 2-element
- tuple containing:
-
- - The request class that Grok uses for XML-RPC requests.
- - The publication class that Grok uses to publish to a XML-RPC.
-
- """
- def __call__(self):
- request, publication = super(GrokXMLRPCFactory, self).__call__()
- return request, GrokXMLRPCPublication
-
-
-class GrokHTTPPublication(ZopePublicationSansProxy, HTTPPublication):
- """Combines `HTTPPublication` with the Grok sans-proxy mixin.
-
- Because `HTTPPublication` provides its own, special `callObject()`
- implementation, this subclass does the same, providing what is
- basically the same call (you can verify, in fact, that most of its
- lines were copied directly from the superclass's version) but with a
- few extra lines added so that - as with the simpler `callObject()`
- method in `ZopePublicationSansProxy` - it quickly places a security
- proxy around the object, makes sure that this HTTP method is
- permitted, and finally passes the bare object to the view that will
- render it.
-
- """
- def callObject(self, request, ob):
- orig = ob
- if not IHTTPException.providedBy(ob):
- ob = component.queryMultiAdapter((ob, request),
- name=request.method)
- checker = selectChecker(ob)
- if checker is not None:
- checker.check(ob, '__call__')
- ob = getattr(ob, request.method, None)
- if ob is None:
- raise GrokMethodNotAllowed(orig, request)
- return mapply(ob, request.getPositionalArguments(), request)
-
-
-class GrokHTTPFactory(HTTPFactory):
- """Returns the classes Grok uses for HTTP requests and publication.
-
- When an instance of this class is called, it returns a 2-element
- tuple containing:
-
- - The request class that Grok uses for HTTP requests.
- - The publication class that Grok uses to publish to HTTP.
-
- """
- def __call__(self):
- request, publication = super(GrokHTTPFactory, self).__call__()
- return request, GrokHTTPPublication
Deleted: grokcore.json/trunk/src/grokcore/json/rest.py
===================================================================
--- grokcore.json/trunk/src/grokcore/json/rest.py 2010-11-02 16:30:00 UTC (rev 118126)
+++ grokcore.json/trunk/src/grokcore/json/rest.py 2010-11-03 00:50:24 UTC (rev 118127)
@@ -1,108 +0,0 @@
-"""Default REST view for Grok.
-
-The views provided by this module get invoked when an object receives an
-HTTP request in a REST skin for which no more-specific REST behavior has
-been defined. These all return the HTTP response Method Not Allowed.
-
-"""
-import grok
-from grok.interfaces import IRESTSkinType
-
-from zope import component
-from zope.component.interfaces import ComponentLookupError
-from zope.traversing.interfaces import TraversalError
-from zope.traversing.namespace import view
-from zope.interface import Interface
-from zope.publisher.interfaces.http import IHTTPRequest
-from zope.app.publication.http import MethodNotAllowed
-from zope.publisher.browser import applySkin
-
-
-class GrokMethodNotAllowed(MethodNotAllowed):
- """Exception indicating that an attempted REST method is not allowed."""
-
-
-class MethodNotAllowedView(grok.MultiAdapter):
- """View rendering a REST GrokMethodNotAllowed exception over HTTP.
-
- Not only does this view render the REST error as an HTTP status of
- 405 (Method Not Allowed) and a simple text message as the document
- body, but also offers an ``Allow:`` HTTP header listing any methods
- that can, in fact, succeed. It constructs this list by testing the
- current object to see which methods it supports; if none of the
- standard methods succeed, then the ``Allow:`` header is still
- provided, but its value will be empty.
-
- """
- grok.adapts(GrokMethodNotAllowed, IHTTPRequest)
- grok.name('index.html')
- grok.implements(Interface)
-
- def __init__(self, error, request):
- self.error = error
- self.request = request
- self.allow = self._getAllow()
-
- def _getAllow(self):
- allow = []
- # List methods here in the same order that they should appear in
- # the "Allow:" header.
- for method in 'DELETE', 'GET', 'POST', 'PUT':
- view = component.queryMultiAdapter(
- (self.error.object, self.error.request),
- name=method)
- if view is not None:
- is_not_allowed = getattr(view, 'is_not_allowed', False)
- if not is_not_allowed:
- allow.append(method)
- return allow
-
- def __call__(self):
- self.request.response.setHeader('Allow', ', '.join(self.allow))
- self.request.response.setStatus(405)
- return 'Method Not Allowed'
-
-
-class rest_skin(view):
- """A rest skin.
-
- This used to be supported by zope.traversing but the change was
- backed out. We need it for our REST support.
-
- """
- def traverse(self, name, ignored):
- self.request.shiftNameToApplication()
- try:
- skin = component.getUtility(IRESTSkinType, name)
- except ComponentLookupError:
- 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.IRESTLayer)
- 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)
Deleted: grokcore.json/trunk/src/grokcore/json/util.py
===================================================================
--- grokcore.json/trunk/src/grokcore/json/util.py 2010-11-02 16:30:00 UTC (rev 118126)
+++ grokcore.json/trunk/src/grokcore/json/util.py 2010-11-03 00:50:24 UTC (rev 118127)
@@ -1,120 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2006-2007 Zope Foundation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""Grok utility functions.
-"""
-import grok
-import grok.interfaces
-import zope.location.location
-
-from zope import interface
-from zope.schema.interfaces import WrongType
-from zope.security.checker import NamesChecker, defineChecker
-
-from grokcore.view.util import url
-from grokcore.security.util import check_permission
-
-
-def make_checker(factory, view_factory, permission, method_names=None):
- """Make a checker for a view_factory associated with factory.
-
- These could be one and the same for normal views, or different
- in case we make method-based views such as for JSON and XMLRPC.
- """
- if method_names is None:
- method_names = ['__call__']
- if permission is not None:
- check_permission(factory, permission)
- if permission is None or permission == 'zope.Public':
- checker = NamesChecker(method_names)
- else:
- checker = NamesChecker(method_names, permission)
- defineChecker(view_factory, checker)
-
-
-def safely_locate_maybe(obj, parent, name):
- """Set an object's __parent__ (and __name__) if the object's
- __parent__ attribute doesn't exist yet or is None.
-
- If the object provides ILocation, __parent__ and __name__ will be
- set directly. A location proxy will be returned otherwise.
- """
- if getattr(obj, '__parent__', None) is not None:
- return obj
- # This either sets __parent__ or wraps 'obj' in a LocationProxy
- return zope.location.location.located(obj, parent, name)
-
-
-def applySkin(request, skin, skin_type):
- """Change the presentation skin for this request.
- """
- # Remove all existing skin declarations (commonly the default skin).
- ifaces = [iface for iface in interface.directlyProvidedBy(request)
- if not skin_type.providedBy(iface)]
- # Add the new skin.
- ifaces.append(skin)
- interface.directlyProvides(request, *ifaces)
-
-
-def getApplication():
- """Return the nearest enclosing `grok.Application`.
-
- Raises ValueError if no Application can be found.
- """
- site = grok.getSite()
- if grok.interfaces.IApplication.providedBy(site):
- return site
- # Another sub-site is within the application. Walk up the object
- # tree until we get to the an application.
- obj = site
- while obj is not None:
- if isinstance(obj, grok.Application):
- return obj
- obj = obj.__parent__
- raise ValueError("No application found.")
-
-
-def application_url(request, obj, name=None, data={}):
- """Return the URL of the nearest enclosing `grok.Application`.
-
- Raises ValueError if no Application can be found.
- """
- return url(request, getApplication(), name, data)
-
-
-def create_application(factory, container, name):
- """Creates an application and triggers the events from
- the application lifecycle.
- """
- # Check the factory.
- if not grok.interfaces.IApplication.implementedBy(factory):
- raise WrongType(factory)
-
- # Check the availability of the name in the container.
- if name in container:
- raise KeyError(name)
-
- # Instanciate the application
- application = factory()
-
- # Trigger the creation event.
- grok.notify(grok.ObjectCreatedEvent(application))
-
- # Persist the application.
- # This may raise a KeyError.
- container[name] = application
-
- # Trigger the initialization event.
- grok.notify(grok.ApplicationInitializedEvent(application))
-
- return application
More information about the checkins
mailing list