B
    `}                 @   sF   d dl mZ d dlmZ d dlmZmZ d dlmZ G dd dZ	dS )    )action_method)ConfigurationError)ILocaleNegotiatorITranslationDirectories)AssetResolverc               @   s,   e Zd Zedd Zdd Zedd ZdS )I18NConfiguratorMixinc                sB    fdd} dd d} |d< jt||fd dS )a  
        Set the :term:`locale negotiator` for this application.  The
        :term:`locale negotiator` is a callable which accepts a
        :term:`request` object and which returns a :term:`locale
        name`.  The ``negotiator`` argument should be the locale
        negotiator implementation or a :term:`dotted Python name`
        which refers to such an implementation.

        Later calls to this method override earlier calls; there can
        be only one locale negotiator active at a time within an
        application.  See :ref:`activating_translation` for more
        information.

        .. note::

           Using the ``locale_negotiator`` argument to the
           :class:`pyramid.config.Configurator` constructor can be used to
           achieve the same purpose.
        c                  s      d S )N)_set_locale_negotiator )
negotiatorselfr	   [/home/kop/projects/devel/pgwui/test_venv/lib/python3.7/site-packages/pyramid/config/i18n.pyregister   s    z=I18NConfiguratorMixin.set_locale_negotiator.<locals>.registerzlocale negotiatorNr
   )introspectables)introspectableZobject_descriptionactionr   )r   r
   r   intrr	   )r
   r   r   set_locale_negotiator   s    z+I18NConfiguratorMixin.set_locale_negotiatorc             C   s   |  |}| j|t d S )N)Zmaybe_dottedregistryregisterUtilityr   )r   r
   Zlocale_negotiatorr	   r	   r   r   *   s    
z,I18NConfiguratorMixin._set_locale_negotiatorc                sL   g  | dd|r&tdt|  fdd}jd| d dS )a  Add one or more :term:`translation directory` paths to the
        current configuration state.  The ``specs`` argument is a
        sequence that may contain absolute directory paths
        (e.g. ``/usr/share/locale``) or :term:`asset specification`
        names naming a directory path (e.g. ``some.package:locale``)
        or a combination of the two.

        Example:

        .. code-block:: python

           config.add_translation_dirs('/usr/share/locale',
                                       'some.package:locale')

        The translation directories are defined as a list in which
        translations defined later have precedence over translations defined
        earlier.

        By default, consecutive calls to ``add_translation_dirs`` will add
        directories to the start of the list. This means later calls to
        ``add_translation_dirs`` will have their translations trumped by
        earlier calls. If you explicitly need this call to trump an earlier
        call then you may set ``override`` to ``True``.

        If multiple specs are provided in a single call to
        ``add_translation_dirs``, the directories will be inserted in the
        order they're provided (earlier items are trumped by later items).

        .. versionchanged:: 1.8

           The ``override`` parameter was added to allow a later call
           to ``add_translation_dirs`` to override an earlier call, inserting
           folders at the beginning of the translation directory list.

        overrideFzinvalid keyword arguments: %sc                 s   g } t j}xxD ]p}|ds*|d7 }||}| }| sPtd| d||d}||d< ||d<  | | | qW j	
t}|d krg }j	|t r||  nxt| D ]}|d| qW d S )N/z"%s" is not a directoryztranslation directoriesztranslation directory	directoryspecr   )r   package_nameendswithresolveabspathisdirr   r   appendr   ZqueryUtilityr   r   extendreversedinsert)directoriesresolverr   Zassetr   r   Ztdirs)r   r   r   specsr	   r   r   X   s6    





z<I18NConfiguratorMixin.add_translation_dirs.<locals>.registerN)r   )pop	TypeErrorsortedkeysr   )r   r$   kwr   r	   )r   r   r   r$   r   add_translation_dirs.   s    %%z*I18NConfiguratorMixin.add_translation_dirsN)__name__
__module____qualname__r   r   r   r*   r	   r	   r	   r   r      s   "r   N)
Zpyramid.config.actionsr   Zpyramid.exceptionsr   Zpyramid.interfacesr   r   Zpyramid.pathr   r   r	   r	   r	   r   <module>   s   