� !��g�>��:�UdZddlmZddlZddlZddlZddlZddlZddl m Z m Z Gd�de ��Z dd�Zdd �Zd �Zeejd ��dz��dzZeejdd ��Zgaded<dad�Zd�Zd�Zd d�Zd!d�Zd�Zd�Z d"d�Z!d�Z"d#d�Z#dS)$z;Miscellaneous stuff that does not really fit anywhere else.�)� annotationsN)�fill�dedentc��eZdZdS)� UndecidableN)�__name__� __module__� __qualname__���d/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/sympy/utilities/misc.pyrr s������ �Dr r�Fc ��dttt|�����d��fd|i|��zS)a� Strips leading and trailing empty lines from a copy of ``s``, then dedents, fills and returns it. Empty line stripping serves to deal with docstrings like this one that start with a newline after the initial triple quote, inserting an empty line at the beginning of the string. Additional keyword arguments will be passed to ``textwrap.fill()``. See Also ======== strlines, rawlines � �width)rr�str�strip)�s�w�kwargss r � filldedentrs>�� �$�v�c�!�f�f�~�~�+�+�D�1�1�E�E��E�f�E�E� E�Er �@Fc��t|t��std���d|vrt|��St |���d��rdnd}|fdz}d|vrd|z}d|z}|d z}nd |z}d |z}|dz}g}|r)|�|d |���||d �}|�)|r6t|��d kr#||dz���d S||� |��zS)aXReturn a cut-and-pastable string that, when printed, is equivalent to the input. The lines will be surrounded by parentheses and no line will be longer than c (default 64) characters. If the line contains newlines characters, the `rawlines` result will be returned. If ``short`` is True (default is False) then if there is one line it will be returned without bounding parentheses. Examples ======== >>> from sympy.utilities.misc import strlines >>> q = 'this is a long string that should be broken into shorter lines' >>> print(strlines(q, 40)) ( 'this is a long string that should be b' 'roken into shorter lines' ) >>> q == ( ... 'this is a long string that should be b' ... 'roken into shorter lines' ... ) True See Also ======== filldedent, rawlines zexpecting string inputr�"�'��\z ( r%s%%s%s )z%s r%s�z ( %s%%s%s )z%s %sN�r) � isinstancer� ValueError�rawlines�repr� startswith�append�len� splitlines�join)r�c�short�q�m�j�outs r �strlinesr/&s3��: �a�� � �3��1�2�2�2� �q�y�y���{�{���A�w�w�!�!�#�&�&�/���C�A� ��Q��A� �q�y�y� �q� �� ��M�� �Q���� �a� �� �q�L�� �Q��� �C� �� � � �1�R�a�R�5���� �A�B�B�%�� �� �,��S���Q����C��F� �&�&�(�(��+�+� �q�v�v�c�{�{�?�r c�~�|�d��}t|��dkrt|d��Sd|vd|vg}td�|D����sd|vst |��r�g}|�d��}t|��dz }t |��D]U\}}||ks|r&|�t|dz�����3|�t|�����Vdd �|��zSd �|��}|drd |zSd |zS) axReturn a cut-and-pastable string that, when printed, is equivalent to the input. Use this when there is more than one line in the string. The string returned is formatted so it can be indented nicely within tests; in some cases it is wrapped in the dedent function which has to be imported from textwrap. Examples ======== Note: because there are characters in the examples below that need to be escaped because they are themselves within a triple quoted docstring, expressions below look more complicated than they would be if they were printed in an interpreter window. >>> from sympy.utilities.misc import rawlines >>> from sympy import TableForm >>> s = str(TableForm([[1, 10]], headings=(None, ['a', 'bee']))) >>> print(rawlines(s)) ( 'a bee\n' '-----\n' '1 10 ' ) >>> print(rawlines('''this ... that''')) dedent('''\ this that''') >>> print(rawlines('''this ... that ... ''')) dedent('''\ this that ''') >>> s = """this ... is a triple ''' ... """ >>> print(rawlines(s)) dedent("""\ this is a triple ''' """) >>> print(rawlines('''this ... that ... ''')) ( 'this\n' 'that\n' ' ' ) See Also ======== filldedent, strlines rrrz'''z"""c3�@K�|]}|�d��V��dS)� N)�endswith)�.0�lis r � <genexpr>zrawlines.<locals>.<genexpr>�s.���� ,� ,��2�;�;�s� � � ,� ,� ,� ,� ,� ,r rz ( %s )z zdedent("""\ %s""")zdedent('''\ %s''')) �splitr&r#�any�allr3� enumerater%r()r�lines�triple�rv�trailing�last�ir5s r r"r"ZsG��x �G�G�D�M�M�E� �5�z�z�Q����E�!�H�~�~���q�j�%�1�*� %�F� � ,� ,�e� ,� ,� ,�,�,�3��� � �S��[�[� � ���:�:�d�#�#���5�z�z�A�~���u�%�%� $� $�E�A�r��D�y�y�H�y�� � �$�r�D�y�/�/�*�*�*�*�� � �$�r�(�(�#�#�#�#��� � �b� 1� 1�1�1� �]�]�5� !� !�� �!�9� 3�-��2� 2�-��2� 2r �P�z-bit�hash_randomizationz list[str]� _debug_tmpc�0���ddlm}|s�Sd����fd�}|S)z�If SYMPY_DEBUG is True, it will print a nice execution tree with arguments and results of all decorated functions, else do nothing. r�� SYMPY_DEBUGc�6�t}gatdz ad�}||i|��}tdza|j�|�d|�d�}tgkr||t��z }|at�|��tdkrt td��ga|S)Nrc��dd�}t|��dkrdSg}|dd�D] }|�||�����!|�||dd����d�|��S)Nrc��|�d��}d|dz}|dd�D] }|dkr� |dkr |d|zz }�|d|zz }�!|S)Nrz+-%s rr�z| %s z %s )r7)r�variant�x�r�as r �indentz?debug_decorator.<locals>.maketree.<locals>.tree.<locals>.indent�so���G�G�D�M�M���q��t�O���1�2�2��*�*�A��B�w�w� ��!�|�|��X��\�)����X��\�)����r rrK�����r)r)r&r%r()�subtreesrP�frOs r �treez/debug_decorator.<locals>.maketree.<locals>.tree�s��� � � � ��8�}�}��!�!��r��A��c�r�c�]� $� $����������#�#�#�#� �H�H�V�V�H�R�L�!�,�,� -� -� -��7�7�1�:�:� r z = rr)rD� _debug_iterrr%�print)rS�args�kw�oldtmprTrNrs r �maketreez!debug_decorator.<locals>.maketree�s������ ��q�� � � � �6 �A�t�N�r�N�N���q�� ��Z�Z����q�q�q� 1�� �� � � ���j�!�!� !�A�� ����!���� �!� � � �*�Q�-� � � ��J��r c�����g|�Ri|��S�Nr )rWr�funcrZs ��r � decoratedz"debug_decorator.<locals>.decorated�s#����x��.�t�.�.�.�v�.�.�.r )�sympyrG)r]rGr^rZs` @r �debug_decoratorr`�s[����"�!�!�!�!�!� ��� �-�-�-�^/�/�/�/�/�/� �r c�F�ddlm}|rt|dtji�dSdS)zB Print ``*args`` if SYMPY_DEBUG is True, else do nothing. rrF�fileN�r_rGrV�sys�stderr)rWrGs r �debugrf�sC��"�!�!�!�!�!��&� �t�%�#�*�%�%�%�%�%�&�&r c�V�ddlm}|r t||ztj���dSdS)z� Print ``string%args`` if SYMPY_DEBUG is True, else do nothing. This is intended for debug messages using formatted strings. rrF)rbNrc)�stringrWrGs r �debugfri�sG�� "�!�!�!�!�!��,� �f�T�k�� �+�+�+�+�+�+�,�,r c��ddlm}|ddd���|�tjd}|�tj��}d g}tjd kr*tj�|��\}}|s|d z}n�tj d kr{tjd � ���tj��}tj�|��\}}|� ��|vr|}|D]t}||z}tj� |��r|cS|D]G} tj� | |��} tj� | ��r| ccS�H�udS)z�Try to find 'executable' in the directories listed in 'path' (a string listing directories separated by 'os.pathsep'; defaults to os.environ['PATH']). Returns the complete filename or None if not found r)�sympy_deprecation_warningz� sympy.utilities.misc.find_executable() is deprecated. Use the standard library shutil.which() function instead. z1.7zdeprecated-find-executable)�deprecated_since_version�active_deprecations_targetN�PATHrK�os2z.exe�win32�PATHEXT)� exceptionsrk�os�environr7�pathsep�name�path�splitextrd�platform�lower�isfiler() � executablerwrk�paths�extlist�base�ext�pathext�execname�prSs r �find_executabler�s��� 6�5�5�5�5�5��� �"'�#?� ���� �|��z�&�!�� �J�J�r�z� "� "�E��d�G� �w�%����g�&�&�z�2�2� ��s�� -�#�f�,�J�� ��� � ��*�Y�'�-�-�/�/�5�5�b�j�A�A���g�&�&�z�2�2� ��s� �9�9�;�;�g� %� %��G�������#�� �7�>�>�(� #� #� ��O�O�O�� � ���G�L�L��H�-�-���7�>�>�!�$�$���H�H�H�H�H�� � �4r c�r�ddddddd�}t|��}t|���d��rBt|���d ��d �d ��d }nct|���d ��rAt|���d ��d �d ��d }t t |d |��d|��}d|vr|�d��d}|r|�||��}|S)a�Return function name of `x` (if defined) else the `type(x)`. If short is True and there is a shorter alias for the result, return the alias. Examples ======== >>> from sympy.utilities.misc import func_name >>> from sympy import Matrix >>> from sympy.abc import x >>> func_name(Matrix.eye(3)) 'MutableDenseMatrix' >>> func_name(x < 1) 'StrictLessThan' >>> func_name(x < 1, short=True) 'Lt' �Ge�Gt�Le�Lt�Eq�Ne)� GreaterThan�StrictGreaterThan�LessThan�StrictLessThan�Equality� Unequalityz<type 'rrrz<class 'r]r�.rQ)�typerr$r7�getattr�get)rMr*�alias�typr=s r � func_namer�1s!��&������  � �E� �q�'�'�C� �3�x�x���9�%�%�3��#�h�h�n�n�S�!�!�!�$�*�*�3�/�/��2��� �S��� � �Z� (� (�3��#�h�h�n�n�S�!�!�!�$�*�*�3�/�/��2�� ���F�A�&�&� �C� 8� 8�B� �b�y�y� �X�X�c�]�]�2� �� �� �Y�Y�r�2� � �� �Ir c�������sd�S�fd��tjd�d�����D����tj�����fd�S)aUReturn a function that can make the replacements, given in ``reps``, on a string. The replacements should be given as mapping. Examples ======== >>> from sympy.utilities.misc import _replace >>> f = _replace(dict(foo='bar', d='t')) >>> f('food') 'bart' >>> f = _replace({}) >>> f('food') 'food' c��|Sr\r )rMs r �<lambda>z_replace.<locals>.<lambda>hs���r c�:���|�d��S)Nr)�group)�match�repss �r r�z_replace.<locals>.<lambda>is���d�5�;�;�q�>�>�*�r �|c�<�g|]\}}tj|����Sr )�_re�escape)r4�k�vs r � <listcomp>z_replace.<locals>.<listcomp>ks$��0�0�0�4�1�a���A���0�0�0r c�0�����|��Sr\)�sub)rh�D�patterns ��r r�z_replace.<locals>.<lambda>ls���'�+�+�a��0�0�r )r��compiler(�items�M)r�r�r�s`@@r �_replacer�Xsv����� ���{��*�*�*�*�A��k�#�(�(�0�0�4�:�:�<�<�0�0�0�2�2�36�5�:�:�G� 0� 0� 0� 0� 0�0r c���t|��dkr*|d}t|t��r|}n|j|�St|��}t |��|��S)arReturn ``string`` with all keys in ``reps`` replaced with their corresponding values, longer strings first, irrespective of the order they are given. ``reps`` may be passed as tuples or a single mapping. Examples ======== >>> from sympy.utilities.misc import replace >>> replace('foo', {'oo': 'ar', 'f': 'b'}) 'bar' >>> replace("spamham sha", ("spam", "eggs"), ("sha","md5")) 'eggsham md5' There is no guarantee that a unique answer will be obtained if keys in a mapping overlap (i.e. are the same length and have some identical sequence at the beginning/end): >>> reps = [ ... ('ab', 'x'), ... ('bc', 'y')] >>> replace('abc', *reps) in ('xc', 'ay') True References ========== .. [1] https://stackoverflow.com/questions/6116978/how-to-replace-multiple-substrings-of-a-string rr)r&r �dict�replacer�)rhr��kvs r r�r�ose��> �4�y�y�A�~�~� �!�W�� �b�$� � � '��D�D�!�6�>�2�&� &��D�z�z�� �8�D�>�>�&� !� !�!r c� �i}|�|�td|z���|�|S|}dx}}n�t|t��r�i}t|�����D]F}t |��dkr1t ||��dkr|�|��||<�G|}|}|r6d�tt|������D��\}}n4dx}}n/t |��t |��krtd���|r1t� dd|��}|� |��}t||��}t� ||��}|� |��S)a�Return ``s`` where characters have been replaced or deleted. SYNTAX ====== translate(s, None, deletechars): all characters in ``deletechars`` are deleted translate(s, map [,deletechars]): all characters in ``deletechars`` (if provided) are deleted then the replacements defined by map are made; if the keys of map are strings then the longer ones are handled first. Multicharacter deletions should have a value of ''. translate(s, oldchars, newchars, deletechars) all characters in ``deletechars`` are deleted then each character in ``oldchars`` is replaced with the corresponding character in ``newchars`` Examples ======== >>> from sympy.utilities.misc import translate >>> abc = 'abc' >>> translate(abc, None, 'a') 'bc' >>> translate(abc, {'a': 'x'}, 'c') 'xb' >>> translate(abc, {'abc': 'x', 'a': 'y'}) 'x' >>> translate('abcd', 'ac', 'AC', 'd') 'AbC' There is no guarantee that a unique answer will be obtained if keys in a mapping overlap are the same length and have some identical sequences at the beginning/end: >>> translate(abc, {'ab': 'x', 'bc': 'y'}) in ('xc', 'ay') True Nz6c should be None when a=None is passed, instead got %srKrc�8�g|]}d�|����S)rK)r()r4r@s r r�ztranslate.<locals>.<listcomp>�s"��F�F�F�q����� � �F�F�Fr z,oldchars and newchars have different lengths) r!r r��list�keysr&�pop�zipr�r� maketrans� translater�) rrO�br)�mrr*r��val�ns r r�r��s|��T �B��y� �=��U�XY�Y�Z�Z� Z� �9��H� ��� ��A�A� �a�� � � M��E��!�&�&�(�(�^�^� (� (���q�6�6�Q�;�;�3�q��t�9�9��>�>� �u�u�Q�x�x�E�!�H���B��A�� �F�F�D��e�k�k�m�m�1D�,E�,E�F�F�F���1�1�� ��A�A� ��V�V�s�1�v�v� � ��K�L�L� L����m�m�B��A�&�&�� �K�K�� � ����2���A� � � �a����A� �;�;�q�>�>�r c���t|��}t|��dz}d|cxkrdkrnnd}n&|dzdkrd}n|dzdkrd }n|dzd krd }nd}t|��|zS) z=Return ordinal number string of num, e.g. 1 becomes 1st. �d� � �th� r�str�ndr�rd)�as_int�absr)�numr�r��suffixs r �ordinalr��s��� �s� � �A� �A���� �A� �Q�}�}�}�}�"�}�}�}�}�}���� �R��1������ �R��1������ �R��1�������� �q�6�6�F�?�r Tc�<�|rQ t|t��rt�tj|��S#t$rt |�d����wxYw t |��}n #t$rt |�d����wxYw||z rt |�d����|S)a� Convert the argument to a builtin integer. The return value is guaranteed to be equal to the input. ValueError is raised if the input has a non-integral value. When ``strict`` is True, this uses `__index__ <https://docs.python.org/3/reference/datamodel.html#object.__index__>`_ and when it is False it uses ``int``. Examples ======== >>> from sympy.utilities.misc import as_int >>> from sympy import sqrt, S The function is primarily concerned with sanitizing input for functions that need to work with builtin integers, so anything that is unambiguously an integer should be returned as an int: >>> as_int(S(3)) 3 Floats, being of limited precision, are not assumed to be exact and will raise an error unless the ``strict`` flag is False. This precision issue becomes apparent for large floating point numbers: >>> big = 1e23 >>> type(big) is float True >>> big == int(big) True >>> as_int(big) Traceback (most recent call last): ... ValueError: ... is not an integer >>> as_int(big, strict=False) 99999999999999991611392 Input that might be a complex representation of an integer value is also rejected by default: >>> one = sqrt(3 + 2*sqrt(2)) - sqrt(2) >>> int(one) == 1 True >>> as_int(one) Traceback (most recent call last): ... ValueError: ... is not an integer z is not an integer)r �bool� TypeError�operator�indexr!�int)r��strict�results r r�r��s���d�� <��!�T�"�"� ����>�!�$�$� $��� <� <� <��q�q�q�:�;�;� ;� <���� <���V�V�F�F��� <� <� <��q�q�q�:�;�;� ;� <���� �v�:� <��q�q�q�:�;�;� ;�� s�/4�A�A%�%B)r)rFr\)F)NN)T)$�__doc__� __future__rr�rdrs�rer��struct�textwraprrr!rrr/r"r�calcsize�ARCHr��flags�HASH_RANDOMIZATIONrD�__annotations__rUr`rfrir�r�r�r�r�r�r�r r r �<module>r�s���A�A�A�"�"�"�"�"�"����� � � � � � � � ����� � � � �!�!�!�!�!�!�!�!� � � � � �*� � � � F�F�F�F�&1�1�1�1�hP3�P3�P3�d �s�?�6�?�3� � �!� #�$�$�v�-���W�S�Y�(<�e�D�D��� ������ �;�;�;�|&�&�&�,�,�,�(�(�(�(�V$�$�$�$�N1�1�1�.'"�'"�'"�TF�F�F�F�R���&@�@�@�@�@�@r
Memory