[Checkins] SVN: z3c.restdemo/trunk/ Initial checkin of the REST
demo package. Got a simple Echo working.
Stephan Richter
srichter at cosmos.phy.tufts.edu
Mon Dec 10 19:14:03 EST 2007
Log message for revision 82251:
Initial checkin of the REST demo package. Got a simple Echo working.
Changed:
A z3c.restdemo/trunk/
A z3c.restdemo/trunk/CHANGES.txt
A z3c.restdemo/trunk/README.txt
A z3c.restdemo/trunk/bootstrap.py
A z3c.restdemo/trunk/buildout.cfg
A z3c.restdemo/trunk/setup.py
A z3c.restdemo/trunk/src/
A z3c.restdemo/trunk/src/z3c/
A z3c.restdemo/trunk/src/z3c/__init__.py
A z3c.restdemo/trunk/src/z3c/restdemo/
A z3c.restdemo/trunk/src/z3c/restdemo/__init__.py
A z3c.restdemo/trunk/src/z3c/restdemo/application.zcml
A z3c.restdemo/trunk/src/z3c/restdemo/configure.zcml
A z3c.restdemo/trunk/src/z3c/restdemo/echo.pt
A z3c.restdemo/trunk/src/z3c/restdemo/echo.py
A z3c.restdemo/trunk/src/z3c/restdemo/echo.zcml
A z3c.restdemo/trunk/src/z3c/restdemo/overview.pt
A z3c.restdemo/trunk/src/z3c/restdemo/overview.py
-=-
Added: z3c.restdemo/trunk/CHANGES.txt
===================================================================
--- z3c.restdemo/trunk/CHANGES.txt (rev 0)
+++ z3c.restdemo/trunk/CHANGES.txt 2007-12-11 00:14:02 UTC (rev 82251)
@@ -0,0 +1,12 @@
+=======
+CHANGES
+=======
+
+Version 0.1.0 (2007-??-??)
+--------------------------
+
+- Initial Release
+
+ * Demo Services Overview
+
+ * Simple Echo Demo
Property changes on: z3c.restdemo/trunk/CHANGES.txt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.restdemo/trunk/README.txt
===================================================================
--- z3c.restdemo/trunk/README.txt (rev 0)
+++ z3c.restdemo/trunk/README.txt 2007-12-11 00:14:02 UTC (rev 82251)
@@ -0,0 +1,24 @@
+==================================
+Demo Applications for ``z3c.rest``
+==================================
+
+This package contains several small demo applications for the ``z3c.rest``
+package.
+
+* A simple echo demo.
+
+
+Running the Demo out of the box
+-------------------------------
+
+You can also run the demo directly without manually installing Zope 3::
+
+ $ svn co svn://svn.zope.org/repos/main/z3c.restdemo/trunk restdemo
+ $ cd restdemo
+ $ python bootstrap.py
+ $ ./bin/buildout
+ $ ./bin/demo fg
+
+Then access the demo site using:
+
+ http://localhost:8080/
Property changes on: z3c.restdemo/trunk/README.txt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.restdemo/trunk/bootstrap.py
===================================================================
--- z3c.restdemo/trunk/bootstrap.py (rev 0)
+++ z3c.restdemo/trunk/bootstrap.py 2007-12-11 00:14:02 UTC (rev 82251)
@@ -0,0 +1,52 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Corporation 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.
+#
+##############################################################################
+"""Bootstrap a buildout-based project
+
+Simply run this script in a directory containing a buildout.cfg.
+The script accepts buildout command-line options, so you can
+use the -c option to specify an alternate configuration file.
+
+$Id$
+"""
+
+import os, shutil, sys, tempfile, urllib2
+
+tmpeggs = tempfile.mkdtemp()
+
+ez = {}
+exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
+ ).read() in ez
+ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)
+
+import pkg_resources
+
+cmd = 'from setuptools.command.easy_install import main; main()'
+if sys.platform == 'win32':
+ cmd = '"%s"' % cmd # work around spawn lamosity on windows
+
+ws = pkg_resources.working_set
+assert os.spawnle(
+ os.P_WAIT, sys.executable, sys.executable,
+ '-c', cmd, '-mqNxd', tmpeggs, 'zc.buildout',
+ dict(os.environ,
+ PYTHONPATH=
+ ws.find(pkg_resources.Requirement.parse('setuptools')).location
+ ),
+ ) == 0
+
+ws.add_entry(tmpeggs)
+ws.require('zc.buildout')
+import zc.buildout.buildout
+zc.buildout.buildout.main(sys.argv[1:] + ['bootstrap'])
+shutil.rmtree(tmpeggs)
Property changes on: z3c.restdemo/trunk/bootstrap.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: z3c.restdemo/trunk/buildout.cfg
===================================================================
--- z3c.restdemo/trunk/buildout.cfg (rev 0)
+++ z3c.restdemo/trunk/buildout.cfg 2007-12-11 00:14:02 UTC (rev 82251)
@@ -0,0 +1,34 @@
+[buildout]
+develop = .
+ ../z3c.rest
+ ../z3c.traverser
+parts = demo test coverage
+index = http://download.zope.org/zope3.4/
+
+[test]
+recipe = zc.recipe.testrunner
+eggs = z3c.restdemo [app, test]
+
+[coverage]
+recipe = zc.recipe.egg
+eggs = z3c.coverage
+
+[zope3]
+location = .
+
+[rest-demo-app]
+recipe = zc.zope3recipes:app
+site.zcml = <include package="z3c.restdemo" file="application.zcml" />
+eggs = z3c.restdemo [app]
+
+[demo]
+recipe = zc.zope3recipes:instance
+application = rest-demo-app
+zope.conf = ${database:zconfig}
+ <server>
+ type REST-HTTP
+ address 8081
+ </server>
+
+[database]
+recipe = zc.recipe.filestorage
Added: z3c.restdemo/trunk/setup.py
===================================================================
--- z3c.restdemo/trunk/setup.py (rev 0)
+++ z3c.restdemo/trunk/setup.py 2007-12-11 00:14:02 UTC (rev 82251)
@@ -0,0 +1,72 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+"""Setup
+
+$Id$
+"""
+import os
+from setuptools import setup, find_packages
+
+def read(*rnames):
+ return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
+
+setup (
+ name='z3c.restdemo',
+ version='0.1.0',
+ author = "Stephan Richter and the Zope Community",
+ author_email = "zope-dev at zope.org",
+ description = "A set of demo applications for z3c.rest",
+ long_description=(
+ read('README.txt')
+ + '\n\n' +
+ read('CHANGES.txt')
+ ),
+ license = "ZPL 2.1",
+ keywords = "zope3 rest http",
+ classifiers = [
+ 'Development Status :: 5 - Production/Stable',
+ 'Environment :: Web Environment',
+ 'Intended Audience :: Developers',
+ 'License :: OSI Approved :: Zope Public License',
+ 'Programming Language :: Python',
+ 'Natural Language :: English',
+ 'Operating System :: OS Independent',
+ 'Topic :: Internet :: WWW/HTTP',
+ 'Framework :: Zope3'],
+ url = 'http://cheeseshop.python.org/pypi/z3c.restdemo',
+ packages = find_packages('src'),
+ include_package_data = True,
+ package_dir = {'':'src'},
+ namespace_packages = ['z3c'],
+ extras_require = dict(
+ app = ['zc.configuration',
+ 'zope.app.appsetup',
+ 'zope.app.authentication',
+ 'zope.app.container',
+ 'zope.app.publisher',
+ 'zope.app.publication',
+ 'zope.app.security',
+ 'zope.app.securitypolicy',
+ 'zope.app.twisted',
+ 'zope.app.wsgi',
+ ],
+ test = ['z3c.coverage',
+ 'zope.app.testing'],
+ ),
+ install_requires = [
+ 'setuptools',
+ 'z3c.rest',
+ ],
+ zip_safe = False,
+ )
Property changes on: z3c.restdemo/trunk/setup.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: z3c.restdemo/trunk/src/z3c/__init__.py
===================================================================
--- z3c.restdemo/trunk/src/z3c/__init__.py (rev 0)
+++ z3c.restdemo/trunk/src/z3c/__init__.py 2007-12-11 00:14:02 UTC (rev 82251)
@@ -0,0 +1,8 @@
+try:
+ # Declare this a namespace package if pkg_resources is available.
+ import pkg_resources
+ pkg_resources.declare_namespace(__name__)
+except ImportError:
+ pass
+
+
Property changes on: z3c.restdemo/trunk/src/z3c/__init__.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: z3c.restdemo/trunk/src/z3c/restdemo/__init__.py
===================================================================
--- z3c.restdemo/trunk/src/z3c/restdemo/__init__.py (rev 0)
+++ z3c.restdemo/trunk/src/z3c/restdemo/__init__.py 2007-12-11 00:14:02 UTC (rev 82251)
@@ -0,0 +1 @@
+# Make a package.
Property changes on: z3c.restdemo/trunk/src/z3c/restdemo/__init__.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: z3c.restdemo/trunk/src/z3c/restdemo/application.zcml
===================================================================
--- z3c.restdemo/trunk/src/z3c/restdemo/application.zcml (rev 0)
+++ z3c.restdemo/trunk/src/z3c/restdemo/application.zcml 2007-12-11 00:14:02 UTC (rev 82251)
@@ -0,0 +1,41 @@
+<configure
+ xmlns="http://namespaces.zope.org/zope"
+ i18n_domain="rest">
+
+ <include package="zope.app.component" file="meta.zcml" />
+ <include package="zope.app.pagetemplate" file="meta.zcml" />
+ <include package="zope.app.publication" file="meta.zcml" />
+ <include package="zope.app.publisher" file="meta.zcml" />
+ <include package="zope.app.security" file="meta.zcml" />
+ <include package="zope.app.securitypolicy" file="meta.zcml" />
+ <include package="zc.configuration" file="meta.zcml" />
+
+ <exclude package="zope.app.error.browser" />
+ <exclude package="zope.app.securitypolicy.browser" />
+ <exclude package="zope.app.session" file="browser.zcml" />
+
+ <include package="zope.app.appsetup" />
+ <include package="zope.app.component" />
+ <include package="zope.app.container" />
+ <include package="zope.app.error" />
+ <include package="zope.app.publication" />
+ <include package="zope.app.security" />
+ <include package="zope.app.securitypolicy" />
+ <include package="zope.app.session" />
+ <include package="zope.app.twisted" />
+ <include package="zope.app.wsgi" />
+ <include package="zope.annotation" />
+ <include package="zope.component" />
+ <include package="zope.location" />
+ <include package="zope.publisher" />
+ <include package="zope.traversing" />
+
+ <include package="z3c.rest" />
+ <include package="." />
+
+ <securityPolicy
+ component="zope.securitypolicy.zopepolicy.ZopeSecurityPolicy" />
+
+ <role id="zope.Anonymous" title="Everybody" />
+ <grantAll role="zope.Anonymous" />
+</configure>
Property changes on: z3c.restdemo/trunk/src/z3c/restdemo/application.zcml
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.restdemo/trunk/src/z3c/restdemo/configure.zcml
===================================================================
--- z3c.restdemo/trunk/src/z3c/restdemo/configure.zcml (rev 0)
+++ z3c.restdemo/trunk/src/z3c/restdemo/configure.zcml 2007-12-11 00:14:02 UTC (rev 82251)
@@ -0,0 +1,15 @@
+<configure
+ xmlns="http://namespaces.zope.org/zope">
+
+ <view
+ for="zope.app.folder.interfaces.IRootFolder"
+ name="GET"
+ type="z3c.rest.interfaces.IRESTRequest"
+ factory=".overview.Overview"
+ permission="zope.Public"
+ allowed_attributes="GET"
+ />
+
+ <include file="echo.zcml" />
+
+</configure>
Property changes on: z3c.restdemo/trunk/src/z3c/restdemo/configure.zcml
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.restdemo/trunk/src/z3c/restdemo/echo.pt
===================================================================
--- z3c.restdemo/trunk/src/z3c/restdemo/echo.pt (rev 0)
+++ z3c.restdemo/trunk/src/z3c/restdemo/echo.pt 2007-12-11 00:14:02 UTC (rev 82251)
@@ -0,0 +1,25 @@
+<?xml version="1.0" ?>
+<echo xmlns:tal="http://xml.zope.org/namespaces/tal">
+ <path
+ tal:content="view/path">/myfolder1/echo</path>
+ <method
+ tal:content="view/method">PUT</method>
+ <protocol
+ tal:content="view/protocol">HTTP/1.1</protocol>
+ <parameters>
+ <parameter name="param-1"
+ tal:repeat="parameter view/parameters"
+ tal:attributes="name parameter/name"
+ tal:content="parameter/value">value-1</parameter>
+ </parameters>
+ <headers>
+ <header name="header-1"
+ tal:repeat="header view/headers"
+ tal:attributes="name header/name"
+ tal:content="header/value">header-value-1</header>
+ </headers>
+ <body tal:content="structure view/body"><![CDATA[
+ <?xml version="1.0" ?>
+ <data>Hello World!</data>
+ ]]></body>
+</echo>
Property changes on: z3c.restdemo/trunk/src/z3c/restdemo/echo.pt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.restdemo/trunk/src/z3c/restdemo/echo.py
===================================================================
--- z3c.restdemo/trunk/src/z3c/restdemo/echo.py (rev 0)
+++ z3c.restdemo/trunk/src/z3c/restdemo/echo.py 2007-12-11 00:14:02 UTC (rev 82251)
@@ -0,0 +1,59 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Corporation 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.
+#
+##############################################################################
+"""REST Echo Demo
+
+$Id$
+"""
+from z3c.rest import rest
+from z3c.traverser import traverser
+from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
+
+
+def fixHeaderName(header):
+ header = header[5:]
+ parts = [part.capitalize() for part in header.split('_')]
+ return '-'.join(parts)
+
+class EchoResource(object):
+ pass
+
+
+class EchoResourceTraverserPlugin(traverser.NameTraverserPlugin):
+ traversalName = 'echo'
+
+ def _traverse(self, request, name):
+ return EchoResource()
+
+
+class Echo(rest.RESTView):
+
+ template = ViewPageTemplateFile("echo.pt")
+
+ def GET(self):
+ self.path = self.request.environment['REQUEST_URI']
+ self.method = self.request.method
+ self.protocol = self.request.environment['SERVER_PROTOCOL']
+ self.parameters = [
+ {'name': name, 'value': value}
+ for name, value in sorted(self.request.parameters.items())]
+ self.headers = [
+ {'name': fixHeaderName(name), 'value': value}
+ for name, value in sorted(self.request.environment.items())
+ if name.startswith('HTTP_')]
+ self.body = self.request.bodyStream.read()
+ if self.body:
+ self.body = '<![CDATA[\n%s\n]]>' %self.body
+ return self.template()
+
+ POST = PUT = DELETE = GET
Property changes on: z3c.restdemo/trunk/src/z3c/restdemo/echo.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: z3c.restdemo/trunk/src/z3c/restdemo/echo.zcml
===================================================================
--- z3c.restdemo/trunk/src/z3c/restdemo/echo.zcml (rev 0)
+++ z3c.restdemo/trunk/src/z3c/restdemo/echo.zcml 2007-12-11 00:14:02 UTC (rev 82251)
@@ -0,0 +1,19 @@
+<configure xmlns="http://namespaces.zope.org/zope">
+
+ <subscriber
+ for="zope.interface.Interface
+ z3c.rest.interfaces.IRESTRequest"
+ provides="z3c.traverser.interfaces.ITraverserPlugin"
+ factory=".echo.EchoResourceTraverserPlugin"
+ />
+
+ <view
+ for=".echo.EchoResource"
+ name="GET"
+ type="z3c.rest.interfaces.IRESTRequest"
+ factory=".echo.Echo"
+ permission="zope.View"
+ allowed_attributes="GET"
+ />
+
+</configure>
Property changes on: z3c.restdemo/trunk/src/z3c/restdemo/echo.zcml
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.restdemo/trunk/src/z3c/restdemo/overview.pt
===================================================================
--- z3c.restdemo/trunk/src/z3c/restdemo/overview.pt (rev 0)
+++ z3c.restdemo/trunk/src/z3c/restdemo/overview.pt 2007-12-11 00:14:02 UTC (rev 82251)
@@ -0,0 +1,9 @@
+<?xml version="1.0" ?>
+<demos xmlns:xlink="http://www.w3.org/1999/xlink">
+ <greeting>Welcome the REST Demo</greeting>
+ <demo xlink:type="simple"
+ xlink:href="./echo"
+ xlink:title="Echo">
+ Echo -- Returns all request data as the result body.
+ </demo>
+</demos>
Property changes on: z3c.restdemo/trunk/src/z3c/restdemo/overview.pt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.restdemo/trunk/src/z3c/restdemo/overview.py
===================================================================
--- z3c.restdemo/trunk/src/z3c/restdemo/overview.py (rev 0)
+++ z3c.restdemo/trunk/src/z3c/restdemo/overview.py 2007-12-11 00:14:02 UTC (rev 82251)
@@ -0,0 +1,26 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Corporation 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.
+#
+##############################################################################
+"""REST Demo Overview
+
+$Id$
+"""
+from z3c.rest import rest
+from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
+
+class Overview(rest.RESTView):
+
+ template = ViewPageTemplateFile("overview.pt")
+
+ def GET(self):
+ return self.template()
Property changes on: z3c.restdemo/trunk/src/z3c/restdemo/overview.py
___________________________________________________________________
Name: svn:keywords
+ Id
More information about the Checkins
mailing list