# Path: feincms3/plugins/external.py
# def oembed_json(url, *, cache_failures=True, force_refresh=False, params=None):
# def oembed_html(url, **kwargs):
# def render_external(plugin, **kwargs):
#     def __str__(self):
#     def clean(self):
# class External(models.Model):
#     class Meta:
# class NoembedValidationForm(forms.ModelForm):
# class ExternalInline(ContentEditorInline):
# 
# Path: feincms3/plugins/html.py
# class HTML(models.Model):
#     class Meta:
# class HTMLInline(ContentEditorInline):
#     def __str__(self):
# def render_html(plugin, **kwargs):
# 
# Path: feincms3/plugins/richtext.py
# class RichText(models.Model):
#     class Meta:
# class RichTextInline(ContentEditorInline):
#     def __str__(self):
# def render_richtext(plugin, **kwargs):
# 
# Path: feincms3/regions.py
# class Regions:
#     """
#     ``Regions`` uses ``content_editor.contents.Contents`` and the
#     ``feincms3.renderer.TemplatePluginRenderer`` to convert a list of plugins
#     into a rendered representation, most often a HTML fragment.
# 
#     This class may also be instantiated directly but using the factory methods
#     (starting with ``from_``) below is probably more comfortable.
#     """
# 
#     @classmethod
#     def from_contents(cls, contents, *, renderer, **kwargs):
#         """
#         Create and return a regions instance using the bare minimum of a
#         contents instance and a renderer. Additional keyword arguments are
#         forwarded to the regions constructor.
#         """
#         return cls(contents=contents, renderer=renderer, **kwargs)
# 
#     @classmethod
#     def from_item(cls, item, *, renderer, inherit_from=None, timeout=None, **kwargs):
#         """
#         Create and return a regions instance for an item (for example a page,
#         an article or anything else managed by django-content-editor).
# 
#         The item's plugins are determined by what is registered with the
#         renderer. The plugin instances themselves are loaded lazily, and
#         loading every time can be avoided completely by specifying a
#         ``timeout``.
#         """
#         if timeout is not None and "cache_key" not in kwargs:
#             key = f"{item._meta.label_lower}-{item.pk}"
#             kwargs["cache_key"] = lambda region: f"{key}-{region}"
#         return cls.from_contents(
#             SimpleLazyObject(
#                 lambda: contents_for_item(
#                     item, renderer.plugins(), inherit_from=inherit_from
#                 )
#             ),
#             renderer=renderer,
#             timeout=timeout,
#             **kwargs,
#         )
# 
#     def __init__(self, *, contents, renderer, cache_key=None, timeout=None):
#         self.contents = contents
#         self.renderer = renderer
#         self.cache_key = cache_key
#         self.timeout = timeout
#         self.handlers = {
#             key[7:]: getattr(self, key)
#             for key in dir(self)
#             if key.startswith("handle_")
#         }
# 
#     @property
#     def regions(self):
#         return self.contents.regions
# 
#     @cached_render
#     def render(self, region, context=None):
#         """
#         Main function for rendering.
# 
#         Starts the generator and assembles all fragments into a safe HTML
#         string.
#         """
#         return mark_safe("".join(self.generate(self.contents[region], context)))
# 
#     def generate(self, items, context):
#         """
#         Inspects all items in the region for a  ``subregion`` attribute and
#         passes control to the subregions' respective rendering handler, named
#         ``handle_<subregion>``. If ``subregion`` is not set or is falsy
#         ``handle_default`` is invoked instead. This method raises a
#         ``KeyError`` exception if no matching handler exists.
# 
#         You probably want to call this method when overriding ``render``.
#         """
#         items = deque(items)
#         while items:
#             subregion = getattr(items[0], "subregion", None) or "default"
#             yield from self.handlers[subregion](items, context)
# 
#     def handle_default(self, items, context):
#         """
#         Renders items from the queue using the renderer instance as long as the
#         items either have no ``subregion`` attribute or whose ``subregion``
#         attribute is an empty string.
#         """
#         while True:
#             yield self.renderer.render_plugin_in_context(items.popleft(), context)
#             if not items or not matches(items[0], subregions={None, ""}):
#                 break
# 
# Path: feincms3/renderer.py
# class TemplatePluginRenderer(RegionRenderer):
#     """
#     TemplatePluginRenderer is deprecated, use
#     :class:`~feincms3.renderer.RegionRenderer`.
#     """
# 
#     def __init__(self, *args, **kwargs):
#         warnings.warn(
#             "TemplatePluginRenderer is deprecated. Switch to the RegionRenderer now.",
#             DeprecationWarning,
#             stacklevel=2,
#         )
#         super().__init__(*args, **kwargs)
# 
# Path: tests/testapp/models.py
# class HTML(html.HTML, PagePlugin):
#     pass
# 
# class External(external.External, PagePlugin):
#     pass
# 
# class Image(image.Image, PagePlugin):
#     pass
# 
# class RichText(richtext.RichText, PagePlugin):
#     pass
# 
# class Snippet(snippet.Snippet, PagePlugin):
#     TEMPLATES = [
#         (
#             "snippet.html",
#             _("snippet"),
#             lambda plugin, context: {"plugin": plugin, "additional": "context"},
#         )
#     ]


from feincms3.plugins import external, html, richtext
from feincms3.regions import Regions
from feincms3.renderer import TemplatePluginRenderer
from .models import HTML, External, Image, RichText, Snippet



renderer = TemplatePluginRenderer()
renderer.register_string_renderer(RichText, richtext.render_richtext)
renderer.register_template_renderer(Image, "renderer/image.html")
Snippet.register_with(renderer)
renderer.register_string_renderer(External, external.render_external)
renderer.register_string_renderer(HTML, html.render_html)



# Path: feincms3/plugins/external.py
# def oembed_json(url, *, cache_failures=True, force_refresh=False, params=None):
# def oembed_html(url, **kwargs):
# def render_external(plugin, **kwargs):
#     def __str__(self):
#     def clean(self):
# class External(models.Model):
#     class Meta:
# class NoembedValidationForm(forms.ModelForm):
# class ExternalInline(ContentEditorInline):
# 
# Path: feincms3/plugins/html.py
# class HTML(models.Model):
#     class Meta:
# class HTMLInline(ContentEditorInline):
#     def __str__(self):
# def render_html(plugin, **kwargs):
# 
# Path: feincms3/plugins/richtext.py
# class RichText(models.Model):
#     class Meta:
# class RichTextInline(ContentEditorInline):
#     def __str__(self):
# def render_richtext(plugin, **kwargs):
# 
# Path: feincms3/regions.py
# class Regions:
#     """
#     ``Regions`` uses ``content_editor.contents.Contents`` and the
#     ``feincms3.renderer.TemplatePluginRenderer`` to convert a list of plugins
#     into a rendered representation, most often a HTML fragment.
# 
#     This class may also be instantiated directly but using the factory methods
#     (starting with ``from_``) below is probably more comfortable.
#     """
# 
#     @classmethod
#     def from_contents(cls, contents, *, renderer, **kwargs):
#         """
#         Create and return a regions instance using the bare minimum of a
#         contents instance and a renderer. Additional keyword arguments are
#         forwarded to the regions constructor.
#         """
#         return cls(contents=contents, renderer=renderer, **kwargs)
# 
#     @classmethod
#     def from_item(cls, item, *, renderer, inherit_from=None, timeout=None, **kwargs):
#         """
#         Create and return a regions instance for an item (for example a page,
#         an article or anything else managed by django-content-editor).
# 
#         The item's plugins are determined by what is registered with the
#         renderer. The plugin instances themselves are loaded lazily, and
#         loading every time can be avoided completely by specifying a
#         ``timeout``.
#         """
#         if timeout is not None and "cache_key" not in kwargs:
#             key = f"{item._meta.label_lower}-{item.pk}"
#             kwargs["cache_key"] = lambda region: f"{key}-{region}"
#         return cls.from_contents(
#             SimpleLazyObject(
#                 lambda: contents_for_item(
#                     item, renderer.plugins(), inherit_from=inherit_from
#                 )
#             ),
#             renderer=renderer,
#             timeout=timeout,
#             **kwargs,
#         )
# 
#     def __init__(self, *, contents, renderer, cache_key=None, timeout=None):
#         self.contents = contents
#         self.renderer = renderer
#         self.cache_key = cache_key
#         self.timeout = timeout
#         self.handlers = {
#             key[7:]: getattr(self, key)
#             for key in dir(self)
#             if key.startswith("handle_")
#         }
# 
#     @property
#     def regions(self):
#         return self.contents.regions
# 
#     @cached_render
#     def render(self, region, context=None):
#         """
#         Main function for rendering.
# 
#         Starts the generator and assembles all fragments into a safe HTML
#         string.
#         """
#         return mark_safe("".join(self.generate(self.contents[region], context)))
# 
#     def generate(self, items, context):
#         """
#         Inspects all items in the region for a  ``subregion`` attribute and
#         passes control to the subregions' respective rendering handler, named
#         ``handle_<subregion>``. If ``subregion`` is not set or is falsy
#         ``handle_default`` is invoked instead. This method raises a
#         ``KeyError`` exception if no matching handler exists.
# 
#         You probably want to call this method when overriding ``render``.
#         """
#         items = deque(items)
#         while items:
#             subregion = getattr(items[0], "subregion", None) or "default"
#             yield from self.handlers[subregion](items, context)
# 
#     def handle_default(self, items, context):
#         """
#         Renders items from the queue using the renderer instance as long as the
#         items either have no ``subregion`` attribute or whose ``subregion``
#         attribute is an empty string.
#         """
#         while True:
#             yield self.renderer.render_plugin_in_context(items.popleft(), context)
#             if not items or not matches(items[0], subregions={None, ""}):
#                 break
# 
# Path: feincms3/renderer.py
# class TemplatePluginRenderer(RegionRenderer):
#     """
#     TemplatePluginRenderer is deprecated, use
#     :class:`~feincms3.renderer.RegionRenderer`.
#     """
# 
#     def __init__(self, *args, **kwargs):
#         warnings.warn(
#             "TemplatePluginRenderer is deprecated. Switch to the RegionRenderer now.",
#             DeprecationWarning,
#             stacklevel=2,
#         )
#         super().__init__(*args, **kwargs)
# 
# Path: tests/testapp/models.py
# class HTML(html.HTML, PagePlugin):
#     pass
# 
# class External(external.External, PagePlugin):
#     pass
# 
# class Image(image.Image, PagePlugin):
#     pass
# 
# class RichText(richtext.RichText, PagePlugin):
#     pass
# 
# class Snippet(snippet.Snippet, PagePlugin):
#     TEMPLATES = [
#         (
#             "snippet.html",
#             _("snippet"),
#             lambda plugin, context: {"plugin": plugin, "additional": "context"},
#         )
#     ]


# Path: tests/testapp/renderer.py
from feincms3.plugins import external, html, richtext
from feincms3.regions import Regions
from feincms3.renderer import TemplatePluginRenderer
from .models import HTML, External, Image, RichText, Snippet




renderer = TemplatePluginRenderer()
renderer.register_string_renderer(RichText, richtext.render_richtext)
renderer.register_template_renderer(Image, "renderer/image.html")
Snippet.register_with(renderer)
renderer.register_string_renderer(External, external.render_external)
renderer.register_string_renderer(HTML, html.render_html)



def page_context(request, *, page):