Permalink
Browse files

initial unlacing chameleon

  • Loading branch information...
Reed O'Brien
Reed O'Brien committed Mar 13, 2012
1 parent a8b2df6 commit 7e75f116d268a7e03fe0e7fa8838aa16032a676f
View
@@ -1,144 +0,0 @@
-import sys
-
-from zope.deprecation import deprecated
-from zope.interface import implementer
-
-from pyramid.compat import reraise
-
-try:
- from chameleon.zpt.template import PageTextTemplateFile
- # prevent pyflakes complaining about a redefinition below
- PageTextTemplateFile
-except ImportError: # pragma: no cover
- exc_class, exc, tb = sys.exc_info()
- # Chameleon doesn't work on non-CPython platforms
- class PageTextTemplateFile(object):
- def __init__(self, *arg, **kw):
- reraise(ImportError, exc, tb)
-
-from pyramid.interfaces import ITemplateRenderer
-
-from pyramid.decorator import reify
-from pyramid import renderers
-from pyramid.path import caller_package
-
-def renderer_factory(info):
- return renderers.template_renderer_factory(info, TextTemplateRenderer)
-
-@implementer(ITemplateRenderer)
-class TextTemplateRenderer(object):
- def __init__(self, path, lookup):
- self.path = path
- self.lookup = lookup
-
- @reify # avoid looking up reload_templates before manager pushed
- def template(self):
- if sys.platform.startswith('java'): # pragma: no cover
- raise RuntimeError(
- 'Chameleon templates are not compatible with Jython')
- return PageTextTemplateFile(self.path,
- auto_reload=self.lookup.auto_reload,
- debug=self.lookup.debug,
- translate=self.lookup.translate)
-
- def implementation(self):
- return self.template
-
- def __call__(self, value, system):
- try:
- system.update(value)
- except (TypeError, ValueError):
- raise ValueError('renderer was passed non-dictionary as value')
- result = self.template(**system)
- return result
-
-def get_renderer(path):
- """ Return a callable object which can be used to render a
- :term:`Chameleon` text template using the template implied by the
- ``path`` argument. The ``path`` argument may be a
- package-relative path, an absolute path, or a :term:`asset
- specification`.
-
- .. warning::
-
- This API is deprecated in :app:`Pyramid` 1.0. Use
- :func:`pyramid.renderers.get_renderer` instead.
- """
- package = caller_package()
- factory = renderers.RendererHelper(path, package=package)
- return factory.get_renderer()
-
-deprecated(
- 'get_renderer',
- '(pyramid.chameleon_text.get_renderer is deprecated '
- 'as of Pyramid 1.0; instead use pyramid.renderers.get_renderer)')
-
-def get_template(path):
- """ Return the underyling object representing a :term:`Chameleon`
- text template using the template implied by the ``path`` argument.
- The ``path`` argument may be a package-relative path, an absolute
- path, or a :term:`asset specification`.
-
- .. warning::
-
- This API is deprecated in :app:`Pyramid` 1.0. Use
- the ``implementation()`` method of a template renderer retrieved via
- :func:`pyramid.renderers.get_renderer` instead.
- """
- package = caller_package()
- factory = renderers.RendererHelper(path, package=package)
- return factory.get_renderer().implementation()
-
-deprecated(
- 'get_template',
- '(pyramid.chameleon_text.get_template is deprecated '
- 'as of Pyramid 1.0; instead use '
- 'pyramid.renderers.get_renderer().implementation())')
-
-def render_template(path, **kw):
- """ Render a :term:`Chameleon` text template using the template
- implied by the ``path`` argument. The ``path`` argument may be a
- package-relative path, an absolute path, or a :term:`asset
- specification`. The arguments in ``*kw`` are passed as top-level
- names to the template, and so may be used within the template
- itself. Returns a string.
-
- .. warning::
-
- This API is deprecated in :app:`Pyramid` 1.0. Use
- :func:`pyramid.renderers.render` instead.
- """
- package = caller_package()
- request = kw.pop('request', None)
- renderer = renderers.RendererHelper(path, package=package)
- return renderer.render(kw, None, request=request)
-
-deprecated(
- 'render_template',
- '(pyramid.chameleon_text.render_template is deprecated '
- 'as of Pyramid 1.0; instead use pyramid.renderers.render)')
-
-def render_template_to_response(path, **kw):
- """ Render a :term:`Chameleon` text template using the template
- implied by the ``path`` argument. The ``path`` argument may be a
- package-relative path, an absolute path, or a :term:`asset
- specification`. The arguments in ``*kw`` are passed as top-level
- names to the template, and so may be used within the template
- itself. Returns a :term:`Response` object with the body as the
- template result.
-
- .. warning::
-
- This API is deprecated in :app:`Pyramid` 1.0. Use
- :func:`pyramid.renderers.render_to_response` instead.
- """
- package = caller_package()
- request = kw.pop('request', None)
- renderer = renderers.RendererHelper(path, package=package)
- return renderer.render_to_response(kw, None, request=request)
-
-deprecated(
- 'render_template_to_response',
- '(pyramid.chameleon_text.render_template_to_response is deprecated '
- 'as of Pyramid 1.0; instead use pyramid.renderers.render_to_response)')
-
View
@@ -1,142 +0,0 @@
-import sys
-
-from zope.deprecation import deprecated
-from zope.interface import implementer
-
-from pyramid.compat import reraise
-
-try:
- from chameleon.zpt.template import PageTemplateFile
- PageTemplateFile # prevent pyflakes complaining about a redefinition below
-except ImportError: # pragma: no cover
- exc_class, exc, tb = sys.exc_info()
- # Chameleon doesn't work on non-CPython platforms
- class PageTemplateFile(object):
- def __init__(self, *arg, **kw):
- reraise(ImportError, exc, tb)
-
-from pyramid.interfaces import ITemplateRenderer
-
-from pyramid.decorator import reify
-from pyramid.path import caller_package
-from pyramid import renderers
-
-def renderer_factory(info):
- return renderers.template_renderer_factory(info, ZPTTemplateRenderer)
-
-@implementer(ITemplateRenderer)
-class ZPTTemplateRenderer(object):
- def __init__(self, path, lookup):
- self.path = path
- self.lookup = lookup
-
- @reify # avoid looking up reload_templates before manager pushed
- def template(self):
- if sys.platform.startswith('java'): # pragma: no cover
- raise RuntimeError(
- 'Chameleon templates are not compatible with Jython')
- return PageTemplateFile(self.path,
- auto_reload=self.lookup.auto_reload,
- debug=self.lookup.debug,
- translate=self.lookup.translate)
-
- def implementation(self):
- return self.template
-
- def __call__(self, value, system):
- try:
- system.update(value)
- except (TypeError, ValueError):
- raise ValueError('renderer was passed non-dictionary as value')
- result = self.template(**system)
- return result
-
-def get_renderer(path):
- """ Return a callable object which can be used to render a
- :term:`Chameleon` ZPT template using the template implied by the
- ``path`` argument. The ``path`` argument may be a
- package-relative path, an absolute path, or a :term:`asset
- specification`.
-
- .. warning::
-
- This API is deprecated in :app:`Pyramid` 1.0. Use
- :func:`pyramid.renderers.get_renderer` instead.
- """
- package = caller_package()
- factory = renderers.RendererHelper(name=path, package=package)
- return factory.get_renderer()
-
-deprecated(
- 'get_renderer',
- '(pyramid.chameleon_zpt.get_renderer is deprecated '
- 'as of Pyramid 1.0; instead use pyramid.renderers.get_renderer)')
-
-def get_template(path):
- """ Return the underyling object representing a :term:`Chameleon`
- ZPT template using the template implied by the ``path`` argument.
- The ``path`` argument may be a package-relative path, an absolute
- path, or a :term:`asset specification`.
-
- .. warning::
-
- This API is deprecated in :app:`Pyramid` 1.0. Use
- the ``implementation()`` method of a template renderer retrieved via
- :func:`pyramid.renderers.get_renderer` instead.
- """
- package = caller_package()
- factory = renderers.RendererHelper(name=path, package=package)
- return factory.get_renderer().implementation()
-
-deprecated(
- 'get_template',
- '(pyramid.chameleon_zpt.get_template is deprecated '
- 'as of Pyramid 1.0; instead use '
- 'pyramid.renderers.get_renderer().implementation())')
-
-def render_template(path, **kw):
- """ Render a :term:`Chameleon` ZPT template using the template
- implied by the ``path`` argument. The ``path`` argument may be a
- package-relative path, an absolute path, or a :term:`asset
- specification`. The arguments in ``*kw`` are passed as top-level
- names to the template, and so may be used within the template
- itself. Returns a string.
-
- .. warning::
-
- This API is deprecated in :app:`Pyramid` 1.0. Use
- :func:`pyramid.renderers.render` instead.
- """
- package = caller_package()
- request = kw.pop('request', None)
- renderer = renderers.RendererHelper(name=path, package=package)
- return renderer.render(kw, None, request=request)
-
-deprecated(
- 'render_template',
- '(pyramid.chameleon_zpt.render_template is deprecated as of Pyramid 1.0; '
- 'instead use pyramid.renderers.render)')
-
-def render_template_to_response(path, **kw):
- """ Render a :term:`Chameleon` ZPT template using the template
- implied by the ``path`` argument. The ``path`` argument may be a
- package-relative path, an absolute path, or a :term:`asset
- specification`. The arguments in ``*kw`` are passed as top-level
- names to the template, and so may be used within the template
- itself. Returns a :term:`Response` object with the body as the
- template result.
-
- .. warning::
-
- This API is deprecated in :app:`Pyramid` 1.0. Use
- :func:`pyramid.renderers.render_to_response` instead.
- """
- package = caller_package()
- request = kw.pop('request', None)
- renderer = renderers.RendererHelper(name=path, package=package)
- return renderer.render_to_response(kw, None, request=request)
-
-deprecated(
- 'render_template_to_response',
- '(pyramid.chameleon_zpt.render_template_to_response is deprecated; as of '
- 'Pyramid 1.0, instead use pyramid.renderers.render_to_response)')
View
@@ -1,10 +1,7 @@
import os
import sys
-from translationstring import ChameleonTranslate
-
from pyramid.interfaces import (
- IChameleonTranslate,
ILocaleNegotiator,
ITranslationDirectories,
)
@@ -114,8 +111,8 @@ def register():
# utility to be registered zero or one times. We register the
# same function once for each added translation directory,
# which does too much work, but has the same effect.
- ctranslate = ChameleonTranslate(translator)
- self.registry.registerUtility(ctranslate, IChameleonTranslate)
+ pass
+ ### ???: What is this for now without Chameleon?
self.action(None, register, introspectables=introspectables)
@@ -8,17 +8,11 @@
from pyramid.config.util import action_method
-from pyramid import (
- renderers,
- chameleon_text,
- chameleon_zpt,
- )
+from pyramid import renderers
DEFAULT_RENDERERS = (
- ('.txt', chameleon_text.renderer_factory),
- ('.pt', chameleon_zpt.renderer_factory),
('json', renderers.json_renderer_factory),
- ('string', renderers.string_renderer_factory),
+ ('string', renderers.string_renderer_factory)
)
class RenderingConfiguratorMixin(object):
@@ -15,7 +15,7 @@
'configuration',
'authentication',
'authorization',
- 'chameleon_text',
+ 'chameleon_text', ## ???: leave in for BFG to pyramid < 1.4 ?
'chameleon_zpt',
'decorator',
'encode',
View
@@ -798,18 +798,6 @@ class IPackageOverrides(Interface):
# traversalwrapper)
VH_ROOT_KEY = 'HTTP_X_VHM_ROOT'
-class IChameleonLookup(Interface):
- translate = Attribute('IChameleonTranslate object')
- debug = Attribute('The ``debug_templates`` setting for this application')
- auto_reload = Attribute('The ``reload_templates`` setting for this app')
- def __call__(self, info):
- """ Return an ITemplateRenderer based on IRendererInfo ``info`` """
-
-class IChameleonTranslate(Interface):
- """ Internal interface representing a chameleon translate function """
- def __call__(msgid, domain=None, mapping=None, context=None,
- target_language=None, default=None):
- """ Translate a mess of arguments to a Unicode object """
class ILocalizer(Interface):
""" Localizer for a specific language """
Oops, something went wrong.

0 comments on commit 7e75f11

Please sign in to comment.