a
    DøgC  ã                   @   s   d dl mZ G dd„ dƒZdS )é    )Úhooksc                   @   st   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zedd„ ƒZdS )ÚFeatureRegistryaW  
    A central store of information about optional features that can be enabled in rich text
    editors by passing a ``features`` list to the RichTextField, such as how to
    whitelist / convert HTML tags, and how to enable the feature on various editors.

    This information may come from diverse sources - for example, wagtailimages might define
    an 'images' feature and a Draftail plugin for it, while a third-party module might
    define a TinyMCE plugin for the same feature. The information is therefore collected into
    this registry via the 'register_rich_text_features' hook.
    c                 C   s(   d| _ i | _g | _i | _i | _i | _d S )NF)Úhas_scanned_for_featuresÚplugins_by_editorÚdefault_featuresÚ
link_typesÚembed_typesÚconverter_rules_by_converter©Úself© r   úa/var/www/lab.imftr.de/x/nb_venv/lib/python3.9/site-packages/wagtail/rich_text/feature_registry.pyÚ__init__   s    zFeatureRegistry.__init__c                 C   s   | j s|  ¡  | jS ©N)r   Ú_scan_for_featuresr   r
   r   r   r   Úget_default_features0   s    z$FeatureRegistry.get_default_featuresc                 C   s"   t  d¡D ]}|| ƒ q
d| _d S )NZregister_rich_text_featuresT)r   Z	get_hooksr   )r   Úfnr   r   r   r   6   s    
z"FeatureRegistry._scan_for_featuresc                 C   s   | j  |i ¡}|||< d S r   )r   Ú
setdefault)r   Úeditor_nameÚfeature_nameZpluginZpluginsr   r   r   Úregister_editor_plugin;   s    z&FeatureRegistry.register_editor_pluginc                 C   s8   | j s|  ¡  z| j| | W S  ty2   Y d S 0 d S r   )r   r   r   ÚKeyError)r   r   r   r   r   r   Úget_editor_plugin?   s    z!FeatureRegistry.get_editor_pluginc                 C   s   || j |j< d S r   )r   Ú
identifier©r   Úhandlerr   r   r   Úregister_link_typeH   s    z"FeatureRegistry.register_link_typec                 C   s   | j s|  ¡  | jS r   )r   r   r   r
   r   r   r   Úget_link_typesK   s    zFeatureRegistry.get_link_typesc                 C   s   || j |j< d S r   )r   r   r   r   r   r   Úregister_embed_typeP   s    z#FeatureRegistry.register_embed_typec                 C   s   | j s|  ¡  | jS r   )r   r   r   r
   r   r   r   Úget_embed_typesS   s    zFeatureRegistry.get_embed_typesc                 C   s   | j  |i ¡}|||< d S r   )r	   r   )r   Úconverter_namer   ZruleÚrulesr   r   r   Úregister_converter_ruleX   s    z'FeatureRegistry.register_converter_rulec                 C   s8   | j s|  ¡  z| j| | W S  ty2   Y d S 0 d S r   )r   r   r	   r   )r   r    r   r   r   r   Úget_converter_rule\   s    z"FeatureRegistry.get_converter_rulec                 C   s   t dtf| t|ƒdœƒS )z<Supports legacy registering of entity handlers as functions.Z!EntityHandlerRegisteredAsFunction)r   Zexpand_db_attributes)ÚtypeÚobjectÚstaticmethod)r   r   r   r   r   Úfunction_as_entity_handlere   s    þýz*FeatureRegistry.function_as_entity_handlerN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r   r   r"   r#   r&   r'   r   r   r   r   r      s    		r   N)Zwagtailr   r   r   r   r   r   Ú<module>   s   