Author: reebalazs
Date: Sun Dec 9 12:23:14 2007
New Revision: 49567
Modified:
kukit/kss.demo/branch/kss-zope-transition/kss/demo/browser/configure.zcml
kukit/kss.demo/branch/kss-zope-transition/kss/demo/browser/ecmaview.py
kukit/kss.demo/branch/kss-zope-transition/kss/demo/browser/registry.py
Log:
Add fixed exmaview support
Modified:
kukit/kss.demo/branch/kss-zope-transition/kss/demo/browser/configure.zcml
==============================================================================
--- kukit/kss.demo/branch/kss-zope-transition/kss/demo/browser/configure.zcml
(original)
+++ kukit/kss.demo/branch/kss-zope-transition/kss/demo/browser/configure.zcml
Sun Dec 9 12:23:14 2007
@@ -100,6 +100,14 @@
permission="zope.View"
/>
+ <!-- Resources for ECMA unittests -->
+
+ <page
+ for="kss.demo.interfaces.ISimpleContent"
+ class=".ecmaview.EcmaView"
+ name="kukittestsuite"
+ permission="zope.Public"
+ />
</configure>
Modified: kukit/kss.demo/branch/kss-zope-transition/kss/demo/browser/ecmaview.py
==============================================================================
--- kukit/kss.demo/branch/kss-zope-transition/kss/demo/browser/ecmaview.py
(original)
+++ kukit/kss.demo/branch/kss-zope-transition/kss/demo/browser/ecmaview.py
Sun Dec 9 12:23:14 2007
@@ -17,22 +17,16 @@
try:
from Products.Five import BrowserView
+ BrowserView # satisfy pyflakes
except ImportError:
from zope.app.publisher.browser import BrowserView
-from zope.interface import Interface, implements
-from zope.app import zapi
+from zope.interface import implements
from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
import os.path
from zope.publisher.interfaces.browser import IBrowserPublisher
from zope.publisher.interfaces import NotFound
-
-# Oh well... file resource has different import locations in zope and five,
-# the factories take different parameters order,
-# plus these are not "entirely clean" as far as caching is concerned...
-# Instead, use the resources implemented from concatresource:
-# this is version free and has properly implemented cache control.
-from kss.core.pluginregistry._concatresource.resource import
ConcatResourceFactory
+import sys
_marker = object()
@@ -47,28 +41,40 @@
'''A wrapper for file resources that can be used in a view
Similar to ViewPageTemplate in usage.
- (We only use the FileResource here, no distinction on content types
- like in the resourceDirectory code.)
'''
- def __init__(self, name, path):
- # Create the resource with cache control most proper for debugging.
- self.resource_factory = ConcatResourceFactory([path], name,
- compress_level='none', caching='memory', lmt_check_period=0.0,
- checker=checker)
+ def __init__(self, request, name, path):
+ self.request = request
self.name = name
+ self.path = path
+
+ def __call__(self):
+ ##self.request.response.setHeader('Content-type',
'x-application/javascript;charset=utf-8')
+ return open(self.path).read()
- def __get__(self, obj, cls=None):
- 'The view wants a method only.'
- request = obj.request
- resource = self.resource_factory(request)
- resource.__parent__ = obj
- resource.__name__ = self.name
- return resource
-
-def absolute_dir(path):
- here = os.path.split(globals()['__file__'])[0]
- return os.path.abspath(os.path.join(here, path))
+def absolute_dir(path, module_name=None):
+ # module_initpath will be the path of __init__.py (ecmaview.py) in the
module
+ if module_name is None:
+ # Take the path of this file
+ module_initpath = globals()['__file__']
+ else:
+ # traverse to module __init__.py
+ module_traverse = module_name.split('.')
+ next = module_traverse[0]
+ module = None
+ try:
+ # we take first module section
+ module = sys.modules[next]
+ # and we traverse to the module
+ for next in module_traverse[1:]:
+ module = getattr(module, next)
+ except (KeyError, AttributeError):
+ raise ImportError, 'Can not traverse path %s from %r while
importing module %s.' % \
+ (next, module, module_name)
+ module_initpath = module.__file__
+ # we take off xxxx.py from the end
+ module_root = os.path.split(module_initpath)[0]
+ return os.path.abspath(os.path.join(module_root, path))
class EcmaView(BrowserView):
'''Kukit test view
@@ -82,9 +88,10 @@
implements(IBrowserPublisher)
- _testdir = absolute_dir('../kukit/tests')
+ _testdir = absolute_dir('kukit/tests', 'kss.base')
- _runner = ViewPageTemplateFile('../kukit/tests/runner.html',
content_type='text/html; charset=utf-8')
+ _runner = ViewPageTemplateFile(os.path.join(_testdir, 'runner.html'),
+ content_type='text/html; charset=utf-8')
# The next is only necessary on Zope (<=) 2.9,
# provides a docstring to the method
@@ -127,10 +134,8 @@
path = os.path.join(self._testdir, name)
if os.path.isfile(path):
# Ok, this is a file. Cook it.
- resource = ViewFile(name, path)
- setattr(self.__class__, name, resource)
- # important: return accessed *from* the view.
- return getattr(self, name)
+ resource = ViewFile(self.request, name, path)
+ return resource
# Not found.
if default is _marker:
Modified: kukit/kss.demo/branch/kss-zope-transition/kss/demo/browser/registry.py
==============================================================================
--- kukit/kss.demo/branch/kss-zope-transition/kss/demo/browser/registry.py
(original)
+++ kukit/kss.demo/branch/kss-zope-transition/kss/demo/browser/registry.py
Sun Dec 9 12:23:14 2007
@@ -102,7 +102,7 @@
raise Exception, "Nonexistent resource"
# Return the file's content.
self.request.response.setHeader('Content-type',
'text/html;charset=utf-8')
- return file(filename).read()
+ return open(filename).read()
def getZuiteHomePage(self, path):
"""Redirects to the Zuite home page, Zuite object is found from
path."""
_______________________________________________
Kukit-checkins mailing list
[email protected]
http://codespeak.net/mailman/listinfo/kukit-checkins