Esempio n. 1
0
def url(_context,
        for_,
        path_expression=None,
        urldata=None,
        attribute_to_parent=None,
        parent_utility=None,
        rootsite=None):
    """browser:url directive handler."""
    if (not attribute_to_parent and not parent_utility and not urldata):
        raise TypeError(
            'Must provide attribute_to_parent, urldata or parent_utility.')
    if attribute_to_parent:
        if attribute_to_parent not in for_:
            raise AttributeError(
                'The name "%s" is not in %s.%s' %
                (attribute_to_parent, for_.__module__, for_.__name__))
    if path_expression is not None:
        compiled_path_expression = TrustedEngine.compile(path_expression)

    # Dead chicken for the namespace gods.
    rootsite_ = rootsite

    if urldata:
        CanonicalUrlData = urldata
    elif attribute_to_parent:

        class CanonicalUrlData(CanonicalUrlDataBase):
            _for = for_
            _compiled_path_expression = compiled_path_expression
            rootsite = rootsite_

            @property
            def inside(self):
                return getattr(self.context, attribute_to_parent)
    else:

        class CanonicalUrlData(CanonicalUrlDataBase):
            _for = for_
            _compiled_path_expression = compiled_path_expression
            rootsite = rootsite_

            @property
            def inside(self):
                return getUtility(parent_utility)

    factory = [CanonicalUrlData]
    provides = ICanonicalUrlData
    adapter(_context, factory, provides, [for_])
Esempio n. 2
0
def url(_context, for_, path_expression=None, urldata=None,
        attribute_to_parent=None, parent_utility=None, rootsite=None):
    """browser:url directive handler."""
    if (not attribute_to_parent
        and not parent_utility
        and not urldata):
        raise TypeError(
            'Must provide attribute_to_parent, urldata or parent_utility.')
    if attribute_to_parent:
        if attribute_to_parent not in for_:
            raise AttributeError('The name "%s" is not in %s.%s'
                % (attribute_to_parent, for_.__module__, for_.__name__))
    if path_expression is not None:
        compiled_path_expression = TrustedEngine.compile(path_expression)

    # Dead chicken for the namespace gods.
    rootsite_ = rootsite

    if urldata:
        CanonicalUrlData = urldata
    elif attribute_to_parent:
        class CanonicalUrlData(CanonicalUrlDataBase):
            _for = for_
            _compiled_path_expression = compiled_path_expression
            rootsite = rootsite_

            @property
            def inside(self):
                return getattr(self.context, attribute_to_parent)
    else:
        class CanonicalUrlData(CanonicalUrlDataBase):
            _for = for_
            _compiled_path_expression = compiled_path_expression
            rootsite = rootsite_

            @property
            def inside(self):
                return getUtility(parent_utility)

    factory = [CanonicalUrlData]
    provides = ICanonicalUrlData
    adapter(_context, factory, provides, [for_])
Esempio n. 3
0
def clear():
    Engine.__init__()
    _Engine(Engine)
    TrustedEngine.__init__()
    _TrustedEngine(TrustedEngine)
Esempio n. 4
0
def registerType(name, handler):
    Engine.registerType(name, handler)
    TrustedEngine.registerType(name, handler)
Esempio n. 5
0
def clear():
    Engine.__init__()
    _Engine(Engine)
    TrustedEngine.__init__()
    _TrustedEngine(TrustedEngine)
Esempio n. 6
0
def registerType(name, handler):
    Engine.registerType(name, handler)
    TrustedEngine.registerType(name, handler)