AlkantarClanX12
Current Path : /opt/imunify360/venv/lib/python3.11/site-packages/__pycache__/ |
Current File : //opt/imunify360/venv/lib/python3.11/site-packages/__pycache__/speaklater.cpython-311.pyc |
� c��f` � �n � d Z d� Zd� Zd� Z G d� de� � Zedk rddlZ ej � � dS dS ) a� speaklater ~~~~~~~~~~ A module that provides lazy strings for translations. Basically you get an object that appears to be a string but changes the value every time the value is evaluated based on a callable you provide. For example you can have a global `lazy_gettext` function that returns a lazy string with the value of the current set language. Example: >>> from speaklater import make_lazy_string >>> sval = u'Hello World' >>> string = make_lazy_string(lambda: sval) This lazy string will evaluate to the value of the `sval` variable. >>> string lu'Hello World' >>> unicode(string) u'Hello World' >>> string.upper() u'HELLO WORLD' If you change the value, the lazy string will change as well: >>> sval = u'Hallo Welt' >>> string.upper() u'HALLO WELT' This is especially handy when combined with a thread local and gettext translations or dicts of translatable strings: >>> from speaklater import make_lazy_gettext >>> from threading import local >>> l = local() >>> l.translations = {u'Yes': 'Ja'} >>> lazy_gettext = make_lazy_gettext(lambda: l.translations.get) >>> yes = lazy_gettext(u'Yes') >>> print yes Ja >>> l.translations[u'Yes'] = u'Si' >>> print yes Si Lazy strings are no real strings so if you pass this sort of string to a function that performs an instance check, it will fail. In that case you have to explicitly convert it with `unicode` and/or `string` depending on what string type the lazy string encapsulates. To check if a string is lazy, you can use the `is_lazy_string` function: >>> from speaklater import is_lazy_string >>> is_lazy_string(u'yes') False >>> is_lazy_string(yes) True New in version 1.2: It's now also possible to pass keyword arguments to the callback used with `make_lazy_string`. :copyright: (c) 2010 by Armin Ronacher. :license: BSD, see LICENSE for more details. c �, � t | t � � S )z,Checks if the given object is a lazy string.)� isinstance�_LazyString)�objs �j/builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib/python3.11/site-packages/speaklater.py�is_lazy_stringr F s � ��c�;�'�'�'� c �$ � t | ||� � S )z1Creates a lazy string by invoking func with args.)r )�__func�args�kwargss r �make_lazy_stringr K s � ��v�t�V�,�,�,r c � � � � fd�}|S )aP Creates a lazy gettext function dispatches to a gettext function as returned by `lookup_func`. Example: >>> translations = {u'Yes': u'Ja'} >>> lazy_gettext = make_lazy_gettext(lambda: translations.get) >>> x = lazy_gettext(u'Yes') >>> x lu'Ja' >>> translations[u'Yes'] = u'Si' >>> x lu'Si' c �V �� t | � � r| S t �� � | � � S �N)r r )�string�lookup_funcs �r �lazy_gettextz'make_lazy_gettext.<locals>.lazy_gettext_ s. �� ��&�!�!� ��M���� � �v�6�6�6r � )r r s ` r �make_lazy_gettextr P s$ �� �7� 7� 7� 7� 7� �r c �� � e Zd ZdZdZd� Z ed� � � Zd� Zd� Z d� Z d� Zd � Zd � Z d� Zd� Zd � Zd� Zd� Zd� Zd� Zd� Zd� Zd� Zd� Zd� Zd� Zd� Zd� Zd� Zd� Zd� Zd� Z dS )r z�Class for strings created by a function call. The proxy implementation attempts to be as complete as possible, so that the lazy objects should mostly work as expected, for example for sorting. ��_func�_args�_kwargsc �0 � || _ || _ || _ d S r r )�self�funcr r s r �__init__z_LazyString.__init__n s � ��� ��� �����r c �0 � | j | j i | j ��S r r )�xs r �<lambda>z_LazyString.<lambda>s s � �w�q�w���=�1�9�=�=� r c � � || j v S r ��value�r �keys r �__contains__z_LazyString.__contains__u s � ��d�j� � r c �* � t | j � � S r )�boolr$ �r s r �__nonzero__z_LazyString.__nonzero__x � � ��D�J���r c �* � t t � � S r )�dir�unicoder* s r �__dir__z_LazyString.__dir__{ s � ��7�|�|�r c �* � t | j � � S r )�iterr$ r* s r �__iter__z_LazyString.__iter__~ r, r c �* � t | j � � S r )�lenr$ r* s r �__len__z_LazyString.__len__� � � ��4�:���r c �* � t | j � � S r )�strr$ r* s r �__str__z_LazyString.__str__� r7 r c �* � t | j � � S r )r/ r$ r* s r �__unicode__z_LazyString.__unicode__� s � ��t�z�"�"�"r c � � | j |z S r r# �r �others r �__add__z_LazyString.__add__� � � ��z�E�!�!r c � � || j z S r r# r>