HEX
Server: LiteSpeed
System: Linux shams.tasjeel.ae 5.14.0-611.5.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Nov 11 08:09:09 EST 2025 x86_64
User: infowars (1469)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: //usr/lib/python3.9/site-packages/ipalib/__pycache__/text.cpython-39.pyc
a

}�f�R�@s�dZddlZddlZddlmZejr*eZdd�ZGdd�d�Z	ej
Gdd	�d	e	��Zej
Gd
d�de��ZGdd
�d
e	�Z
ej
Gdd�d��ZGdd�d�ZGdd�de�Ze�Ze�ZeZdS)a�
Defers gettext translation till request time.

IPA presents some tricky gettext challenges.  On the one hand, most translatable
message are defined as class attributes on the plugins, which means these get
evaluated at module-load time.  But on the other hand, each request to the
server can be in a different locale, so the actual translation must not occur
till request time.

The `text` module provides a mechanism for for deferred gettext translation.  It
was designed to:

    1. Allow translatable strings to be marked with the usual ``_()`` and
       ``ngettext()`` functions so that standard tools like xgettext can still
       be used

    2. Allow programmers to mark strings in a natural way without burdening them
       with details of the deferred translation mechanism

A typical plugin will use the deferred translation like this:

>>> from ipalib import Command, _, ngettext
>>> class my_plugin(Command):
...     my_string = _('Hello, %(name)s.')
...     my_plural = ngettext('%(count)d goose', '%(count)d geese', 0)
...

With normal gettext usage, the *my_string* and *my_plural* message would be
translated at module-load-time when your ``my_plugin`` class is defined.  This
would mean that all message are translated in the locale of the server rather
than the locale of the request.

However, the ``_()`` function above is actually a `GettextFactory` instance,
which when called returns a `Gettext` instance.  A `Gettext` instance stores the
message to be translated, and the gettext domain and localedir, but it doesn't
perform the translation till `Gettext.__unicode__()` is called.  For example:

>>> my_plugin.my_string
Gettext('Hello, %(name)s.', domain='ipa', localedir=None)
>>> unicode(my_plugin.my_string)
u'Hello, %(name)s.'

Translation can also be performed via the `Gettext.__mod__()` convenience
method.  For example, these two are equivalent:

>>> my_plugin.my_string % dict(name='Joe')
u'Hello, Joe.'
>>> unicode(my_plugin.my_string) % dict(name='Joe')  # Long form
u'Hello, Joe.'

Translation can also be performed via the `Gettext.format()` convenience
method.  For example, these two are equivalent:

>>> my_plugin.my_string = _('Hello, {name}.')
>>> my_plugin.my_string.format(name='Joe')
u'Hello, Joe.'

>>> my_plugin.my_string = _('Hello, {0}.')
>>> my_plugin.my_string.format('Joe')
u'Hello, Joe.'

Similar to ``_()``, the ``ngettext()`` function above is actually an
`NGettextFactory` instance, which when called returns an `NGettext` instance.
An `NGettext` instance stores the singular and plural messages, and the gettext
domain and localedir, but it doesn't perform the translation till
`NGettext.__call__()` is called.  For example:

>>> my_plugin.my_plural
NGettext('%(count)d goose', '%(count)d geese', domain='ipa', localedir=None)
>>> my_plugin.my_plural(1)
u'%(count)d goose'
>>> my_plugin.my_plural(2)
u'%(count)d geese'

Translation can also be performed via the `NGettext.__mod__()` convenience
method.  For example, these two are equivalent:

>>> my_plugin.my_plural % dict(count=1)
u'1 goose'
>>> my_plugin.my_plural(1) % dict(count=1)  # Long form
u'1 goose'

Translation can also be performed via the `NGettext.format()` convenience
method.  For example:

>>> my_plugin.my_plural = ngettext('{count} goose', '{count} geese', 0)
>>> my_plugin.my_plural.format(count=1)
u'1 goose'
>>> my_plugin.my_plural.format(count=2)
u'2 geese'

Lastly, 3rd-party plugins can create factories bound to a different gettext
domain.  The default domain is ``'ipa'``, which is also the domain of the
standard ``ipalib._()`` and ``ipalib.ngettext()`` factories.  But 3rd-party
plugins can create their own factories like this:

>>> from ipalib import GettextFactory, NGettextFactory
>>> _ = GettextFactory(domain='ipa_foo')
>>> ngettext = NGettextFactory(domain='ipa_foo')
>>> class foo(Command):
...     msg1 = _('Foo!')
...     msg2 = ngettext('%(count)d bar', '%(count)d bars', 0)
...

Notice that these messages are bound to the ``'ipa_foo'`` domain:

>>> foo.msg1
Gettext('Foo!', domain='ipa_foo', localedir=None)
>>> foo.msg2
NGettext('%(count)d bar', '%(count)d bars', domain='ipa_foo', localedir=None)

For additional details, see `GettextFactory` and `Gettext`, and for plural
forms, see `NGettextFactory` and `NGettext`.
�N)�contextcCs>|tjvsJ�|\}}tj||ttdd�dd�}|tj|<|S)N�	languagesT)�	localedirr�fallback)r�__dict__�gettext�translation�getattr)�key�domainrr�r�//usr/lib/python3.9/site-packages/ipalib/text.py�create_translation�s
�
rc@sBeZdZdZdZdZddd�Zdd�Zdd	�Zd
d�Z	dd
�Z
dS)�LazyTextz�
    Base class for deferred translation.

    This class is not used directly.  See the `Gettext` and `NGettext`
    subclasses.

    Concatenating LazyText objects with the + operator gives
    ConcatenatedLazyText objects.
    �rrr
�argsNcCs ||_||_||f|_d|_dS)a�
        Initialize.

        :param domain: The gettext domain in which this message will be
            translated, e.g. ``'ipa'`` or ``'ipa_3rd_party'``; default is
            ``None``
        :param localedir: The directory containing the gettext translations,
            e.g. ``'/usr/share/locale/'``; default is ``None``, in which case
            gettext will use the default system locale directory.
        Nr��selfrrrrr
�__init__�s
zLazyText.__init__cCst|�|jurdS|j|jkS)z�
        Return ``True`` if this instances is equal to *other*.

        Note that this method cannot be used on the `LazyText` base class itself
        as subclasses must define an *args* instance attribute.
        F)�type�	__class__r�r�otherrrr
�__eq__�szLazyText.__eq__cCs|�|�S)z�
        Return ``True`` if this instances is not equal to *other*.

        Note that this method cannot be used on the `LazyText` base class itself
        as subclasses must define an *args* instance attribute.
        )rrrrr
�__ne__�szLazyText.__ne__cCst|�|S�N��ConcatenatedLazyTextrrrr
�__add__�szLazyText.__add__cCs|t|�Srrrrrr
�__radd__�szLazyText.__radd__)NN)�__name__�
__module__�__qualname__�__doc__�	__slots__�__hash__rrrrrrrrr
r�s

	rcs`eZdZdZdZd�fdd�	Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zddd�Z�Z
S)�Gettexta�
    Deferred translation using ``gettext.ugettext()``.

    Normally the `Gettext` class isn't used directly and instead is created via
    a `GettextFactory` instance.  However, for illustration, we can create one
    like this:

    >>> msg = Gettext('Hello, %(name)s.')

    When you create a `Gettext` instance, the message is stored on the *msg*
    attribute:

    >>> msg.msg
    'Hello, %(name)s.'

    No translation is performed till `Gettext.__unicode__()` is called.  This
    will translate *msg* using ``gettext.ugettext()``, which will return the
    translated string as a Python ``unicode`` instance.  For example:

    >>> unicode(msg)
    u'Hello, %(name)s.'

    `Gettext.__unicode__()` should be called at request time, which in a
    nutshell means it should be called from within your plugin's
    ``Command.execute()`` method.  `Gettext.__unicode__()` will perform the
    translation based on the locale of the current request.

    `Gettext.__mod__()` is a convenience method for Python "percent" string
    formatting.  It will translate your message using `Gettext.__unicode__()`
    and then perform the string substitution on the translated message.  For
    example, these two are equivalent:

    >>> msg % dict(name='Joe')
    u'Hello, Joe.'
    >>> unicode(msg) % dict(name='Joe')  # Long form
    u'Hello, Joe.'

    `Gettext.format()` is a convenience method for Python string formatting.
    It will translate your message using `Gettext.__unicode__()` and then
    perform the string substitution on the translated message.  For example,
    these two are equivalent:

    >>> msg = Gettext('Hello, {name}.')
    >>> msg.format(name='Joe')
    u'Hello, Joe.'

    >>> msg = Gettext('Hello, {0}.')
    >>> msg.format('Joe')
    u'Hello, Joe.'

    See `GettextFactory` for additional details.  If you need to pick between
    singular and plural form, use `NGettext` instances via the
    `NGettextFactory`.
    �msgNcs(tt|��||�||_|||f|_dSr)�superr&rr'r)rr'rr�rrr
rszGettext.__init__cCsd|jj|j|j|jfS)Nz%s(%r, domain=%r, localedir=%r))rr r'rr�rrrr
�__repr__s�zGettext.__repr__cCsF|jtjvrtj|j}n
t|j�}tjr6|�|j�S|�|j�SdS)zN
        Translate this message and return as a ``unicode`` instance.
        N)	r
rrr�six�PY2�ugettextr'r)r�trrr
�
as_unicodes
zGettext.as_unicodecCst|���Sr)�unicoder0r*rrr
�__str__'szGettext.__str__cCst|�Sr�r1r*rrr
�__json__*szGettext.__json__cCst|�|Srr3�r�kwrrr
�__mod__-szGettext.__mod__cOst|�j|i|��Sr�r1�format�rr�kwargsrrr
r90szGettext.format�cCst|��|�S�z,Compatibility for sphinx prepare_docstring()��str�
expandtabs�r�tabsizerrr
r@3szGettext.expandtabs)NN)r<)r r!r"r#r$rr+r0r2r4r7r9r@�
__classcell__rrr)r
r&�s7
r&c@s&eZdZdZe�Zdd�Zdd�ZdS)�FixMea@
    Non-translated place-holder for UI labels.

    `FixMe` is a subclass of `Gettext` and is used for automatically created
    place-holder labels.  It generally behaves exactly like `Gettext` except no
    translation is ever performed.

    `FixMe` allows programmers to get plugins working without first filling in
    all the labels that will ultimately be required, while at the same time it
    creates conspicuous looking UI labels that remind the programmer to
    "fix-me!".  For example, the typical usage would be something like this:

    >>> class Plugin:
    ...     label = None
    ...     def __init__(self):
    ...         self.name = self.__class__.__name__
    ...         if self.label is None:
    ...             self.label = FixMe(self.name + '.label')
    ...         assert isinstance(self.label, Gettext)
    ...
    >>> class user(Plugin):
    ...     pass # Oops, we didn't set user.label yet
    ...
    >>> u = user()
    >>> u.label
    FixMe('user.label')

    Note that as `FixMe` is a subclass of `Gettext`, is passes the above type
    check using ``isinstance()``.

    Calling `FixMe.__unicode__()` performs no translation, but instead returns
    said conspicuous looking label:

    >>> unicode(u.label)
    u'<user.label>'

    For more examples of how `FixMe` is used, see `ipalib.parameters`.
    cCsd|jj|jfS�Nz%s(%r))rr r'r*rrr
r+cszFixMe.__repr__cCs
d|jS)Nz<%s>)r'r*rrr
r2fsz
FixMe.__str__N)r r!r"r#�tupler$r+r2rrrr
rD8s'rDcsFeZdZdZdZd�fdd�	Zdd�Zdd	�Zd
d�Zdd
�Z	�Z
S)�NGettexta�

    Deferred translation for plural forms using ``gettext.ungettext()``.

    Normally the `NGettext` class isn't used directly and instead is created via
    a `NGettextFactory` instance.  However, for illustration, we can create one
    like this:

    >>> msg = NGettext('%(count)d goose', '%(count)d geese')

    When you create an `NGettext` instance, the singular and plural forms of
    your message are stored on the *singular* and *plural* instance attributes:

    >>> msg.singular
    '%(count)d goose'
    >>> msg.plural
    '%(count)d geese'

    The translation and number selection isn't performed till
    `NGettext.__call__()` is called.  This will translate and pick the correct
    number using ``gettext.ungettext()``.  As a callable, an `NGettext` instance
    takes a single argument, an integer specifying the count.  For example:

    >>> msg(0)
    u'%(count)d geese'
    >>> msg(1)
    u'%(count)d goose'
    >>> msg(2)
    u'%(count)d geese'

    `NGettext.__mod__()` is a convenience method for Python "percent" string
    formatting.  It can only be used if your substitution ``dict`` contains the
    count in a ``'count'`` item.  For example:

    >>> msg % dict(count=0)
    u'0 geese'
    >>> msg % dict(count=1)
    u'1 goose'
    >>> msg % dict(count=2)
    u'2 geese'

    Alternatively, these longer forms have the same effect as the three examples
    above:

    >>> msg(0) % dict(count=0)
    u'0 geese'
    >>> msg(1) % dict(count=1)
    u'1 goose'
    >>> msg(2) % dict(count=2)
    u'2 geese'

    A ``KeyError`` is raised if your substitution ``dict`` doesn't have a
    ``'count'`` item.  For example:

    >>> msg2 = NGettext('%(num)d goose', '%(num)d geese')
    >>> msg2 % dict(num=0)
    Traceback (most recent call last):
      ...
    KeyError: 'count'

    However, in this case you can still use the longer, explicit form for string
    substitution:

    >>> msg2(0) % dict(num=0)
    u'0 geese'

    `NGettext.format()` is a convenience method for Python string formatting.
    It can only be used if your substitution ``dict`` contains the count in a
    ``'count'`` item.  For example:

    >>> msg = NGettext('{count} goose', '{count} geese')
    >>> msg.format(count=0)
    u'0 geese'
    >>> msg.format(count=1)
    u'1 goose'
    >>> msg.format(count=2)
    u'2 geese'

    A ``KeyError`` is raised if your substitution ``dict`` doesn't have a
    ``'count'`` item.  For example:

    >>> msg2 = NGettext('{num} goose', '{num} geese')
    >>> msg2.format(num=0)
    Traceback (most recent call last):
      ...
    KeyError: 'count'

    However, in this case you can still use the longer, explicit form for
    string substitution:

    >>> msg2(0).format(num=0)
    u'0 geese'

    See `NGettextFactory` for additional details.
    )�singular�pluralNcs0tt|��||�||_||_||||f|_dSr)r(rGrrHrIr)rrHrIrrr)rr
r�szNGettext.__init__cCsd|jj|j|j|j|jfS)Nz#%s(%r, %r, domain=%r, localedir=%r))rr rHrIrrr*rrr
r+�s�zNGettext.__repr__cCs|d}||�|S�N�countr)rr6rKrrr
r7�szNGettext.__mod__cOs|d}||�j|i|��SrJ)r9)rrr;rKrrr
r9�szNGettext.formatcCsR|jtjvrtj|j}n
t|j�}tjr<|�|j|j|�S|�	|j|j|�SdSr)
r
rrrr,r-Z	ungettextrHrI�ngettext)rrKr/rrr
�__call__�s
zNGettext.__call__)NN)r r!r"r#r$rr+r7r9rMrCrrr)r
rGjs_rGc@sZeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zddd�ZdS)rafConcatenation of multiple strings, or any objects convertible to unicode

    Used to concatenate several LazyTexts together.
    This allows large strings like help text to be split, so translators
    do not have to re-translate the whole text when only a small part changes.

    Additional strings may be added to the end with the + or += operators.
    cGst|�|_dSr)�list�
components)rrOrrr
r�szConcatenatedLazyText.__init__cCsd|jj|jfSrE)rr rOr*rrr
r+�szConcatenatedLazyText.__repr__cCsd�dd�|jD��S)N�css|]}t|�VqdSrr3)�.0�crrr
�	<genexpr>��z/ConcatenatedLazyText.__str__.<locals>.<genexpr>)�joinrOr*rrr
r2�szConcatenatedLazyText.__str__cCst|�Srr3r*rrr
r4�szConcatenatedLazyText.__json__cCst|�|Srr3r5rrr
r7�szConcatenatedLazyText.__mod__cOst|�j|i|��Srr8r:rrr
r9szConcatenatedLazyText.formatcCs.t|t�rt|j|j�St|j|g�SdSr��
isinstancerrOrrrr
rs
zConcatenatedLazyText.__add__cCs.t|t�rt|j|j�St|g|j�SdSrrVrrrr
rs
zConcatenatedLazyText.__radd__r<cCst|��|�Sr=r>rArrr
r@szConcatenatedLazyText.expandtabsN)r<)
r r!r"r#rr+r2r4r7r9rrr@rrrr
r�src@s*eZdZdZd
dd�Zdd�Zdd	�ZdS)�GettextFactorya�
    Factory for creating ``_()`` functions.

    A `GettextFactory` allows you to mark translatable messages that are
    evaluated at initialization time, but deferred their actual translation till
    request time.

    When you create a `GettextFactory` you can provide a specific gettext
    *domain* and *localedir*.  By default the *domain* will be ``'ipa'`` and
    the *localedir* will be ``None``.  Both are available via instance
    attributes of the same name.  For example:

    >>> _ = GettextFactory()
    >>> _.domain
    'ipa'
    >>> _.localedir is None
    True

    When the *localedir* is ``None``, gettext will use the default system
    localedir (typically ``'/usr/share/locale/'``).  In general, you should
    **not** provide a *localedir*... it is intended only to support in-tree
    testing.

    Third party plugins will most likely want to use a different gettext
    *domain*.  For example:

    >>> _ = GettextFactory(domain='ipa_3rd_party')
    >>> _.domain
    'ipa_3rd_party'

    When you call your `GettextFactory` instance, it will return a `Gettext`
    instance associated with the same *domain* and *localedir*.  For example:

    >>> my_msg = _('Hello world')
    >>> my_msg.domain
    'ipa_3rd_party'
    >>> my_msg.localedir is None
    True

    The message isn't translated till `Gettext.__unicode__()` is called, which
    should be done during each request.  See the `Gettext` class for additional
    details.
    �ipaNcCs||_||_dS)a�
        Initialize.

        :param domain: The gettext domain in which this message will be
            translated, e.g. ``'ipa'`` or ``'ipa_3rd_party'``; default is
            ``'ipa'``
        :param localedir: The directory containing the gettext translations,
            e.g. ``'/usr/share/locale/'``; default is ``None``, in which case
            gettext will use the default system locale directory.
        N)rrrrrr
rCszGettextFactory.__init__cCsd|jj|j|jfS)Nz%s(domain=%r, localedir=%r))rr rrr*rrr
r+Qs�zGettextFactory.__repr__cCst||j|j�Sr)r&rr)rr'rrr
rMUszGettextFactory.__call__)rYN)r r!r"r#rr+rMrrrr
rXs,
rXc@seZdZdZdd�ZdS)�NGettextFactorya�
    Factory for creating ``ngettext()`` functions.

    `NGettextFactory` is similar to `GettextFactory`, except `NGettextFactory`
    is for plural forms.

    So that standard tools like xgettext can find your plural forms, you should
    reference your `NGettextFactory` instance using a variable named
    *ngettext*.  For example:

    >>> ngettext = NGettextFactory()
    >>> ngettext
    NGettextFactory(domain='ipa', localedir=None)

    When you call your `NGettextFactory` instance to create a deferred
    translation, you provide the *singular* message, the *plural* message, and
    a dummy *count*.  An `NGettext` instance will be returned.  For example:

    >>> my_msg = ngettext('%(count)d goose', '%(count)d geese', 0)
    >>> my_msg
    NGettext('%(count)d goose', '%(count)d geese', domain='ipa', localedir=None)

    The *count* is ignored (because the translation is deferred), but you should
    still provide it so parsing tools aren't confused.  For consistency, it is
    recommended to always provide ``0`` for the *count*.

    See `NGettext` for details on how the deferred translation is later
    performed.  See `GettextFactory` for details on setting a different gettext
    *domain* (likely needed for 3rd-party plugins).
    cCst|||j|j�Sr)rGrr)rrHrIrKrrr
rMyszNGettextFactory.__call__N)r r!r"r#rMrrrr
rZYsrZ)r#rr,Zipalib.requestrZPY3r?r1rrZpython_2_unicode_compatibler&rDrGrrXrZ�_rLr.rrrr
�<module>s&s9a1,C%