B
    `                 @   s|   d dl Z ddlmZmZ ddlmZ ddlmZ dd Zddd	Z	dd
dZ
dddZdddZdd ZG dd deZdS )    N   )LoaderNotFoundMultipleLoadersFound)ILoaderInfo)	parse_uric             C   s   t | }| S )a  
    Load the list of named sections.

    .. code-block:: python

        sections = plaster.get_sections('development.ini')
        full_config = {
            section: plaster.get_settings('development.ini', section)
            for section in sections
        }

    :param config_uri: Anything that can be parsed by
        :func:`plaster.parse_uri`.

    :returns: A list of section names in the config file.

    )
get_loaderget_sections)
config_uriloader r   W/home/kop/projects/devel/pgwui/test_venv/lib/python3.7/site-packages/plaster/loaders.pyr      s    r   c             C   s   t | }|||S )af  
    Load the settings from a named section.

    .. code-block:: python

        settings = plaster.get_settings(...)
        print(settings['foo'])

    :param config_uri: Anything that can be parsed by
        :func:`plaster.parse_uri`.

    :param section: The name of the section in the config file. If this is
        ``None`` then it is up to the loader to determine a sensible default
        usually derived from the fragment in the ``path#name`` syntax of the
        ``config_uri``.

    :param defaults: A ``dict`` of default values used to populate the
        settings and support variable interpolation. Any values in ``defaults``
        may be overridden by the loader prior to returning the final
        configuration dictionary.

    :returns: A ``dict`` of settings. This should return a dictionary object
        even if no data is available.

    )r   get_settings)r	   sectiondefaultsr
   r   r   r   r   !   s    r   c             C   s   t | }||S )aa  
    Execute the logging configuration defined in the config file.

    This function should, at least, configure the Python standard logging
    module. However, it may also be used to configure any other logging
    subsystems that serve a similar purpose.

    :param config_uri: Anything that can be parsed by
        :func:`plaster.parse_uri`.

    :param defaults: A ``dict`` of default values used to populate the
        settings and support variable interpolation. Any values in ``defaults``
        may be overridden by the loader prior to returning the final
        configuration dictionary.

    )r   setup_logging)r	   r   r
   r   r   r   r   ?   s    r   c             C   sb   t | } | j}t||d}t|dk r2t||dt|dkrLt|||d|d }|| }|S )a   
    Find a :class:`plaster.ILoader` object capable of handling ``config_uri``.

    :param config_uri: Anything that can be parsed by
        :func:`plaster.parse_uri`.

    :param protocols: Zero or more :term:`loader protocol` identifiers that
        the loader must implement to match the desired ``config_uri``.

    :returns: A :class:`plaster.ILoader` object.
    :raises plaster.LoaderNotFound: If no loader could be found.
    :raises plaster.MultipleLoadersFound: If multiple loaders match the
        requested criteria. If this happens, you can disambiguate the lookup
        by appending the package name to the scheme for the loader you wish
        to use. For example if ``ini`` is ambiguous then specify
        ``ini+myapp`` to use the ini loader from the ``myapp`` package.

    )	protocolsr   r   )r   schemefind_loaderslenr   r   load)r	   r   Zrequested_schemeZmatched_loadersZloader_infor
   r   r   r   r   T   s    
r   c                s   dg r dd D 7    dd}t|dkryt|d }W n tjk
rd   Y n"X t||d  }|rt|gS fddtdD }d	d
 |D }t	t
d fdd|D }fdd|D S )a  
    Find all loaders that match the requested scheme and protocols.

    :param scheme: Any valid scheme. Examples would be something like ``ini``
        or ``ini+pastedeploy``.

    :param protocols: Zero or more :term:`loader protocol` identifiers that
        the loader must implement. If ``None`` then only generic loaders will
        be returned.

    :returns: A list containing zero or more :class:`plaster.ILoaderInfo`
        objects.

    zplaster.loader_factoryc             S   s   g | ]}d  |qS )zplaster.{0}_loader_factory)format).0protor   r   r   
<listcomp>   s   z find_loaders.<locals>.<listcomp>+r      r   c                s&   g | ]} d ks |j  kr|qS )N)namelower)r   ep)r   r   r   r      s   c             S   s   h | ]
}|j qS r   )dist)r   r   r   r   r   	<setcomp>   s    zfind_loaders.<locals>.<setcomp>Nc                s   g | ]}t | qS r   )_find_ep_in_dist)r   distro)matching_groupsr   r   r   r      s   c                s   g | ]}t | d qS ))r   )EntryPointLoaderInfo)r   r   )r   r   r   r      s   )r   splitr   pkg_resourcesget_distributionDistributionNotFoundr!   r$   iter_entry_pointslistfilter)r   r   partsr"   r   Zpossible_entry_pointsZdistrosmatched_entry_pointsr   )r#   r   r   r   r   x   s.    


r   c                s@   t td  fdd|D }tdd |D dkr<|d S d S )Nc                s   g | ]}  |qS r   )get_entry_info)r   group)r"   r   r   r   r      s   z$_find_ep_in_dist.<locals>.<listcomp>c             S   s   h | ]}t |qS r   )str)r   r   r   r   r   r       s    z#_find_ep_in_dist.<locals>.<setcomp>r   r   )r*   r+   r   )r"   r   groupsr-   r   )r"   r   r   r!      s
    r!   c               @   s*   e Zd ZdddZedd Zdd ZdS )	r$   Nc             C   s*   || _ d|jj|j| _|| _d | _d S )Nz{0}+{1})entry_pointr   r   project_namer   r   r   _factory)selfr   r   r   r   r   __init__   s    zEntryPointLoaderInfo.__init__c             C   s   | j d kr| j | _ | j S )N)r4   r2   r   )r5   r   r   r   factory   s    
zEntryPointLoaderInfo.factoryc             C   s   t |}| |S )N)r   r7   )r5   r	   r   r   r   r      s    zEntryPointLoaderInfo.load)N)__name__
__module____qualname__r6   propertyr7   r   r   r   r   r   r$      s   
r$   )NN)N)N)N)r&   
exceptionsr   r   Z
interfacesr   urir   r   r   r   r   r   r!   r$   r   r   r   r   <module>   s   


$
8