HEX
Server: Apache
System: Linux infong-uk86 4.4.400-icpu-106 #2 SMP Mon Sep 15 08:23:40 UTC 2025 x86_64
User: u44115835 (4976590)
PHP: 8.4.17
Disabled: NONE
Upload Files
File: //kunden/lib/python3/dist-packages/breezy/__pycache__/plugin.cpython-39.pyc
a

�*�^�]�@s�dZddlmZddlZddlZddlZddlZddlmZddl	m	Z	e	e
�d�ddlmZd	Zd
srej
dkrxdZnd
ZdPdd�ZdQdd�Zdd�Zdd�Zdd�ZGdd�de�Zdd�ZdRdd�ZdSd d!�ZdTd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Z dUd4d5�Z!d6d7�Z"d8d9�Z#d:d;�Z$d<d=�Z%d>d?�Z&d@dA�Z'dBdC�Z(dVdDdE�Z)GdFdG�dGe*�Z+GdHdI�dIe*�Z,GdJdK�dKe*�Z-GdLdM�dMe*�Z.GdNdO�dOe*�Z/dS)Wa�Breezy plugin support.

Which plugins to load can be configured by setting these environment variables:

- BRZ_PLUGIN_PATH: Paths to look for plugins in.
- BRZ_DISABLE_PLUGINS: Plugin names to block from being loaded.
- BRZ_PLUGINS_AT: Name and paths for plugins to load from specific locations.

The interfaces this module exports include:

- disable_plugins: Load no plugins and stop future automatic loading.
- load_plugins: Load all plugins that can be found in configuration.
- describe_plugins: Generate text for each loaded (or failed) plugin.
- extend_path: Mechanism by which the plugins package path is set.
- plugin_name: Gives unprefixed name of a plugin module.

See the plugin-api developer documentation for information about writing
plugins.
�)�absolute_importN�)�osutils)�lazy_importz�
import imp
from importlib import util as importlib_util

from breezy import (
    bedding,
    debug,
    help_topics,
    trace,
    )
)�errorszbreezy.plugins.T)�z.pycz.pyocCs|durt��}i|_dS)z�Disable loading plugins.

    Future calls to load_plugins() will be ignored.

    :param state: The library state object that records loaded plugins.
    N)�breezy�get_global_state�plugins)�state�r�//usr/lib/python3/dist-packages/breezy/plugin.py�disable_pluginsHsrcCsf|durt��}t|dd�dur$dS|dur8ddlm}i|_t||�dt�vrZt|�t	�|_	dS)a�Load breezy plugins.

    The environment variable BRZ_PLUGIN_PATH is considered a delimited
    set of paths to look through. Each entry is searched for `*.py`
    files (and whatever other extensions are used in the platform,
    such as `*.pyd`).

    :param path: The list of paths to search for plugins.  By default,
        it is populated from the __path__ of the breezy.plugins package.
    :param state: The library state object that records loaded plugins.
    Nr
r)�__path__)N�entrypoints)
rr	�getattrZbreezy.pluginsr�plugin_warnings�_load_plugins_from_path�_env_plugin_path�_load_plugins_from_entrypointsr
)�pathrrrr
�load_pluginsTs

rcCsXzddl}WntyYn60|�d�D](}t|j}|tjvrDq*|��tj|<q*dS)Nrz
breezy.plugin)�
pkg_resources�ImportErrorZiter_entry_points�_MODULE_PREFIX�name�sys�modules�load)rrZep�fullnamerrr
rqs

rcCs,|�t�r(|�d�}t|�dkr(|dSdS)z/Gives unprefixed name from module_name or None.�.�N)�
startswithr�split�len)Zmodule_name�partsrrr
�plugin_names


r&cCs6t�}t|�t�}t|�tt�|�}t||||�S)aEHelper so breezy.plugins can be a sort of namespace package.

    To be used in similar fashion to pkgutil.extend_path:

        from breezy.plugins import extend_path
        __path__ = extend_path(__path__, __name__)

    Inspects the BRZ_PLUGIN* envvars, sys.path, and the filesystem to find
    plugins. May mutate sys.modules in order to block plugin loading, and may
    append a new meta path finder to sys.meta_path for plugins@ loading.

    Returns a list of paths to import from, as an enhanced object that also
    contains details of the other configuration used.
    )�_env_disable_plugins�_block_plugins�_env_plugins_at�_install_importer_if_needed�_iter_plugin_pathsr�_Path)rrZblocks�
extra_details�pathsrrr
�extend_path�sr/cs(eZdZdZ�fdd�Zdd�Z�ZS)r,z�List type to use as __path__ but containing additional details.

    Python 3 allows any iterable for __path__ but Python 2 is more fussy.
    cs&tt|��|�||_||_||_dS�N)�superr,�__init__�package_name�
blocked_namesr-)�selfr3ZblockedZextrar.��	__class__rr
r2�sz_Path.__init__cCs"d|jj|j|j|jt�|�fS)Nz%s(%r, %r, %r, %s))r7�__name__r3r4r-�list�__repr__�r5rrr
r:�s�z_Path.__repr__)r8�
__module__�__qualname__�__doc__r2r:�
__classcell__rrr6r
r,�sr,cCs,t�d|�dur$t�d|||�dSt|�S)aValidate given name from envvar is usable as a Python identifier.

    Returns the name as a native str, or None if it was invalid.

    Per PEP 3131 this is no longer strictly correct for Python 3, but as MvL
    didn't include a neat way to check except eval, this enforces ascii.
    z^[A-Za-z_][A-Za-z0-9_]*$NzInvalid name '%s' in %s='%s')�re�match�trace�warning�str)rZenv_keyZ	env_valuerrr
�_expect_identifier�srE�BRZ_DISABLE_PLUGINScCsFg}t�|�}|rB|�tj�D]"}t|||�}|dur|�|�q|S)z<Gives list of names for plugins to disable from environ key.N)r�path_from_environr#�os�pathseprE�append)�keyZdisabled_names�envrrrr
r'�s
r'�BRZ_PLUGINS_ATcCs~g}t�|�}|rz|�tj�D]Z}d|vr<|�dd�\}}n|}t�|��dd�d}t|||�}|dur|�||f�q|S)zCGives list of names and paths of specific plugins from environ key.�@rr rN)rrGr#rHrI�basenamerErJ)rK�plugin_detailsrLZpairrrrrr
r)�s
r)�BRZ_PLUGIN_PATHcCs�g}t�|�}|dddd�}|r�|�tj�D]h}|dd�|dd�}}|dvr�||vr�|dkr~||dur~|�d|f�d||<q.|�|df�q.d	D]}||r�|�d|f�q�|S)
z�Gives list of paths and contexts for plugins from environ key.

    Each entry is either a specific path to load plugins from and the value
    'path', or None and one of the values 'user', 'core', 'entrypoints', 'site'.
    TF)�user�core�siterNr)�+�-rUr)rRrSrrT)rrGr#rHrIrJ)rKZpath_detailsrL�defaults�p�flagrrrr
r�s&
�
rccs�|D]�\}}|dkr|Vq|dkr>t�}tj�|�r�|Vq|dkr\t|�D]
}|VqNq|dkrttj�D]}tj�|�rn|VqnqdS)z3Generate paths using paths_from_env and core_paths.rrRrSrTN)�get_user_plugin_pathrHr�isdir�_get_core_plugin_paths�_get_site_plugin_pathsr)Zpaths_from_envZ
core_pathsr�contextrrr
r+s
r+cCs |rtt|�}tj�d|�dS)z;Install a meta path finder to handle plugin_details if any.r!N)�_PluginsAtFinderrr�	meta_path�insert)rP�finderrrr
r*s
r*cCsTt�}t|�D]@\}}||vrt||�}|durD|j�|g��|�|�|�qdS)z(Do the importing all plugins from paths.N)�set�_iter_possible_plugins�_load_plugin_moduler�
setdefaultrJ�add)rr.Zimported_namesrr�msgrrr
rs
rcCs<|D]2}t|}tj�|�dur,t�d|�dtj|<qdS)z1Add names to sys.modules to block future imports.Nz!Blocked plugin %s already loaded.)rrr�getrB�mutter)�namesrr3rrr
r(&s
r(cCs@t�|d�}tj�|�r|S|dd�t}tj�|�r<|SdS)zEGet path of __init__ file from package_path or None if not a package.z__init__.pyN���)r�pathjoinrHr�exists�COMPILED_EXT)�package_path�	init_pathrrr
�_get_package_init/srrccslt|dd�D]\}}||fVq|D]B}tj�|�rJ|�d�rft�d�q$t|�D]\}}||fVqRq$dS)z?Generate names and paths of possible plugins from plugin_paths.r-rz.zipz+Don't yet support loading plugins from zip.N)rrHr�isfile�endswithrBrj�
_walk_modules)Zplugin_pathsrrrrr
rd:s
rdccs�t�|�D]�\}}}|��|D]8}|dd�dkr |�dtf�r |�dd�d|fVq |��|D]:}|dd�dkrft�||�}t|�}|durf||fVqf|dd�=q
dS)z7Generate name and path of modules and packages on path.Nr!�__�.pyr rr)	rH�walk�sortrtro�rsplitrrmrr)r�root�dirs�files�f�dZpackage_dir�fullpathrrr
ruIsruFccs�|durt��}t|di�}tt|dg��}tt|����|��}|D]�}||vr�||}|j}|dkrld}d||fV|jj	}|r�|�
d�d}	nd	}	d
|	V|r�d|��Vn
d|V||jvr�|j|D]}
d
|
dVq�dVqFdS)a Generate text description of plugins.

    Includes both those that have loaded, and those that failed to load.

    :param show_paths: If true, include the plugin path.
    :param state: The library state object to inspect.
    :returns: Iterator of text lines (including newlines.)
    Nr
r�unknown�z%s %s
�
rz(no description)z  %s
z   %s
z%s (failed to load)
z  ** )
rr	rrc�sorted�keys�union�__version__�moduler>r#rr)Z
show_pathsrZloaded_pluginsrZ	all_namesrZplugin�versionr�doc�linerrr
�describe_plugins\s0	


r�ccs<ttdd�r(t�t�t�t�d��Vn|D]
}|Vq,dS)z@Generate possible locations for plugins based on existing_paths.�frozenFz../../../pluginsN)rrr�abspathrm�dirname�__file__)Zexisting_pathsrrrr
r\�s
�
r\ccs.|D]$}tj�|�dvrt�|dd�VqdS)z=Generate possible locations for plugins from given sys_paths.)z
dist-packagesz
site-packagesrr
N)rHrrOrrm)Z	sys_pathsrrrr
r]�sr]cCst�t��d�S)Nr
)rrmZbeddingZ
config_dirrrrr
rZ�srZcCst�|�|Sr0)rBrj)�warning_messagerrr
�record_plugin_warning�s
r�c
Cs t|tjvrdSztt|�W�n�tjyj}z,d||jj|j|j	f}t
|�WYd}~Sd}~0t�y}z�t�
�dtjvr�t�t��tj�t�d|�r�t�dd|�}|�d�r�|td�d�}t�d|||f�nt
d	|||f�WYd}~SWYd}~n
d}~00dS)
z�Load plugin by name.

    :param name: The plugin name in the breezy.plugins namespace.
    :param dir: The directory the plugin is loaded from for error messages.
    NzRUnable to load plugin %r. It supports %s versions %r but the current version is %s�errorz\.|-| z[-. ]�_Zbrz_zkUnable to load %r in %r as a plugin because the file path isn't a valid module name; try renaming it to %r.z$Unable to load plugin %r from %r: %s)rrr�
__import__rZIncompatibleVersionZapir8ZwantedZcurrentr��	ExceptionrB�log_exception_quietly�debugZdebug_flags�print_exception�exc_info�stderrr@�search�subr"r$rC)r�dir�er�Zsanitised_namerrr
re�s0��

��recCsXi}tjD]H}|�t�r
|tt�d�}d|vr
tj|dur
t|tj|�||<q
|S)z]Return a dictionary of the plugins.

    Each item in the dictionary is a PlugIn object.
    Nr )rrr"rr$�PlugIn)�resultrrrrr
r
�s

r
cCs>ztjt|}Wnty&YdS0|dur4dSt||�S)z[Retrieve an already loaded plugin.

    Returns None if there is no such plugin loaded
    N)rrr�KeyErrorr��rr�rrr
�get_loaded_plugin�sr�cCsP|durt��}g}tt|di����D]\}}|�d||jf�q(d�|�S)zIReturn a string holding a concise list of plugins and their version.
    Nr
z%s[%s]z, )rr	r�r�itemsrJr��join)rr�rZa_pluginrrr
�format_concise_plugin_list�s�r�c@s eZdZdZdd�Zdd�ZdS)�PluginsHelpIndexz2A help index that returns help topics for plugins.cCs
d|_dS)Nzplugins/��prefixr;rrr
r2�szPluginsHelpIndex.__init__cCsb|sgS|�|j�r&|t|j�d�}t|}ztj|}WntyRgYS0t|�gSdS)z�Search for topic in the loaded plugins.

        This will not trigger loading of new plugins.

        :param topic: A topic to search for.
        :return: A list which is either empty or contains a single
            RegisteredTopic entry.
        N)r"r�r$rrrr��ModuleHelpTopic)r5ZtopicZplugin_module_namer�rrr
�
get_topics�s	
zPluginsHelpIndex.get_topicsN)r8r<r=r>r2r�rrrr
r��sr�c@s*eZdZdZdd�Zd
dd�Zdd	�ZdS)r�z6A help topic which returns the docstring for a module.cCs
||_dS)z\Constructor.

        :param module: The module for which help should be generated.
        N)r�)r5r�rrr
r2szModuleHelpTopic.__init__NTcCsD|jjsd|jj}n|jj}|ddkr2|d7}|t�|�7}|S)z�Return a string with the help for this topic.

        :param additional_see_also: Additional help topics to be
            cross-referenced.
        zPlugin '%s' has no docstring.
���r�)r�r>r8Zhelp_topicsZ_format_see_also)r5Zadditional_see_also�verboser�rrr
�
get_help_textszModuleHelpTopic.get_help_textcCs|jjtt�d�S)z+Return the module help topic: its basename.N)r�r8r$rr;rrr
�get_help_topic$szModuleHelpTopic.get_help_topic)NT)r8r<r=r>r2r�r�rrrr
r�s
r�c@sLeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	e
dd��ZdS)r�zvThe breezy representation of a plugin.

    The PlugIn object provides a way to manipulate a given plugin module.
    cCs||_||_dS)zConstruct a plugin for module.Nr�)r5rr�rrr
r2/szPlugIn.__init__cCs�t|jdd�dur&tj�|jjd�St|jdd�dur|tj�|jj�}|dd�tkrx|dd�d}tj�|�rx|}|St	|j�SdS)z.Get the path that this plugin was loaded from.rNrr����rw)
rr�rHrr�rr�rors�repr)r5rZpypathrrr
r4szPlugIn.pathcCsd|jj|jj|j|jfS)Nz<%s.%s name=%s, module=%s>)r7r<r8rr�r;rrr
r:Bs�zPlugIn.__repr__cCs$t|jdd�dur|j��SdSdS)zReturn the plugin's test suite.�
test_suiteN)rr�r�r;rrr
r�Gs
zPlugIn.test_suitecCs&t|jdd�dur|�|j�SdSdS)z�Return the adapted plugin's test suite.

        :param loader: The custom loader that should be used to load additional
            tests.
        Z
load_testsN)rr�ZloadTestsFromModule)r5�loaderrrr
�load_plugin_testsNszPlugIn.load_plugin_testscCsnt|jdd�}|durjz2t|t�r.|�d�}nt|�dkrFt|�d}Wn tyht�	�|f}Yn0|S)z5Return the plugin's version_tuple or None if unknown.�version_infoNr r)�finalr)
rr��
isinstancerDr#r$�tuple�	TypeErrorrBr�)r5r�rrr
r�Ys
zPlugIn.version_infoc
Csd|��}|dust|�dkr dSzt�|�}Wn0tttfy^t��d�	t
t|��}Yn0|S)Nrr�r )r�r$rZ_format_version_tuple�
ValueErrorr��
IndexErrorrBr�r��maprD)r5r�Zversion_stringrrr
r�hszPlugIn.__version__N)r8r<r=r>r2rr:r�r�r��propertyr�rrrr
r�)sr�c@s2eZdZdZdd�Zdd�Zddd�Zd	d
�ZdS)r_z9Meta path finder to support BRZ_PLUGINS_AT configuration.cs"�|_t�fdd�|D��|_dS)Nc3s|]\}}�||fVqdSr0r)�.0�nrXr�rr
�	<genexpr>{�z,_PluginsAtFinder.__init__.<locals>.<genexpr>)r��dict�
names_to_path)r5r�Znames_and_pathsrr�r
r2ysz_PluginsAtFinder.__init__cCsd|jj|jfS�Nz<%s %r>)r7r8r�r;rrr
r:}sz_PluginsAtFinder.__repr__NcCsP||jvrdS|j|}tj�|�rDt|�}|durDtd||f��t�||�S)z&New module spec returning find method.Nz&Not loading namespace package %s as %s)r�rHrr[rrrZimportlib_util�spec_from_file_location)r5rr.�targetrrrr
�	find_spec�s

�z_PluginsAtFinder.find_speccCs||jvrdSt|j|�S)z+Old PEP 302 import hook find_module method.N)r��
_LegacyLoader)r5rrrrr
�find_module�s
z_PluginsAtFinder.find_module)N)r8r<r=r>r2r:r�r�rrrr
r_vs

r_c@s(eZdZdZdd�Zdd�Zdd�ZdS)	r�zCSource loader implementation for Python versions without importlib.cCs
||_dSr0)�filepath)r5r�rrr
r2�sz_LegacyLoader.__init__cCsd|jj|jfSr�)r7r8r�r;rrr
r:�sz_LegacyLoader.__repr__c
Cs�|j}d}tj�|�r:t|�}|dur`|}d}d}tj}n&t��D]\}}}|�|�rB|}q`qB|durxt	d||f��|tjur�d}n
t
||�}z4t�||||||f�}	||	_|	W|dur�|�
�Sn|dur�|�
�0dS)z2Load a plugin from a specific directory (or file).Nr�z%s cannot be loaded from %s)r�rHrr[rr�imp�
PKG_DIRECTORYZget_suffixesrtr�open�load_module�__package__�close)
r5rZplugin_pathZloading_pathrq�suffix�mode�kindr~�modrrr
r��sB
�


���z_LegacyLoader.load_moduleN)r8r<r=r>r2r:r�rrrr
r��sr�)N)NN)rF)rM)rQ)FN)N)0r>Z
__future__rrHr@rrr�rr�globalsrrr�rorrrr&r/r9r,rEr'r)rr+r*rr(rrrdrur�r\r]rZr�rer
r�r��objectr�r�r�r_r�rrrr
�<module>sX

	


!	
%"
M