示例#1
0
class ZopeTwoPageTemplateFile(PageTemplateFile):
    """A strange hybrid between Zope 2 and Zope 3 page template.

    Uses Zope 2's engine, but with security disabled and with some
    initialization and API from Zope 3.
    """
    def __init__(self, filename, _prefix=None, content_type=None):
        # XXX doesn't use content_type yet

        self.ZBindings_edit(self._default_bindings)

        path = self.get_path_from_prefix(_prefix)
        self.filename = os.path.join(path, filename)
        if not os.path.isfile(self.filename):
            raise ValueError("No such file", self.filename)

        basepath, ext = os.path.splitext(self.filename)
        self.__name__ = os.path.basename(basepath)

    def get_path_from_prefix(self, _prefix):
        if isinstance(_prefix, str):
            path = _prefix
        else:
            if _prefix is None:
                _prefix = sys._getframe(2).f_globals
            path = package_home(_prefix)
        return path

    _cook = rebindFunction(PageTemplateFile._cook, getEngine=getEngine)

    pt_render = rebindFunction(PageTemplateFile.pt_render, getEngine=getEngine)

    def _pt_getContext(self):
        view = self._getContext()
        try:
            root = self.getPhysicalRoot()
            here = view.context
        except AttributeError:
            # self has no attribute getPhysicalRoot.
            # This typically happens when the template has
            # no proper acquisition context. That means it has no view,
            # since that's the normal context for a template in Five. /regebro
            root = self.context.getPhysicalRoot()
            here = self.context
            view = None

        request = getattr(root, 'REQUEST', None)
        c = {
            'template': self,
            'here': here,
            'context': here,
            'container': self._getContainer(),
            'nothing': None,
            'options': {},
            'root': root,
            'request': request,
            'modules': ModuleImporter,
        }
        if view:
            c['view'] = view
            c['views'] = ViewMapper(here, request)

        return c

    pt_getContext = rebindFunction(_pt_getContext,
                                   SecureModuleImporter=ModuleImporter)
示例#2
0
class PathExpr(PathExpr):
    __init__ = rebindFunction(
        PathExpr.__init__.im_func,
        SubPathExpr=SubPathExpr,
    )
示例#3
0
class SubPathExpr(SubPathExpr):
    _eval = rebindFunction(
        SubPathExpr._eval.im_func,
        restrictedTraverse=trustedTraverse,
    )
示例#4
0
class StringExpr(StringExpr):
    __init__ = rebindFunction(
        StringExpr.__init__.im_func,
        PathExpr=PathExpr,
    )
示例#5
0
    __init__ = rebindFunction(
        PathExpr.__init__.im_func,
        SubPathExpr=SubPathExpr,
    )


class StringExpr(StringExpr):
    __init__ = rebindFunction(
        StringExpr.__init__.im_func,
        PathExpr=PathExpr,
    )


installHandlers = rebindFunction(
    installHandlers,
    PathExpr=PathExpr,
    StringExpr=StringExpr,
    PythonExpr=PythonExpr,
)


def installHandlers2(engine):
    installHandlers(engine)
    engine.registerType('provider', ProviderExpr)


_engine = None
getEngine = rebindFunction(getEngine,
                           _engine=_engine,
                           installHandlers=installHandlers2)
示例#6
0
class SubPathExpr(SubPathExpr):
  _eval = rebindFunction(SubPathExpr._eval.im_func,
                         restrictedTraverse=trustedTraverse,
                         )

class PathExpr(PathExpr):
  __init__ = rebindFunction(PathExpr.__init__.im_func,
                            SubPathExpr=SubPathExpr,
                            )

class StringExpr(StringExpr):
  __init__ = rebindFunction(StringExpr.__init__.im_func,
                            PathExpr=PathExpr,
                            )
  
installHandlers = rebindFunction(installHandlers,
                                 PathExpr=PathExpr,
                                 StringExpr=StringExpr,
                                 PythonExpr=PythonExpr,
                                 )

_engine=None
getEngine = rebindFunction(getEngine,
                           _engine=_engine,
                           installHandlers=installHandlers
                           )