File: //usr/lib/python3/dist-packages/trac/util/__pycache__/text.cpython-310.pyc
o
�k�`�k � @ s� d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlmZm Z m
Z
d dlmZ d dl
Z
dZG dd� de�Ze� Z[dd� Zd�d
d�Zd�dd
�Zd�dd�Zdd� Ze�dej�Ze�dej�Zd�dd�Zd�dd�Zdddddddd d!�Zeed"��d#d$� d%D � D ]Z e�!e"e �d&e � q�e�d'�Z#e�d(�Z$d)d*� Z%d+d,� Z&d�d.d/�Z'd�d1d2�Z(d3d4� Z)d�d5d6�Z*d0�+d7d8� ed9d:�D ��Z,d;d<� Z-d�d>d?�Z.G d@dA� dAe�Z/dBdC� Z0dDdE� Z1dFdG� Z2dHdI� Z3dJdK� Z4dLdM� Z5dNdO� Z6e�7� Z8dPdQ� Z7d�dSdT�Z9dUdV� Z:e:� Z;d�dXdY�Z<d�d[d\�Z=G d]d^� d^ej>�Z?dZd0d0ej@dRfd_d`�ZAdaZBdbdc� ZCddde� ZDdfdg� ZEd�djdk�ZFdldm� ZGdndo� ZHd�dqdr�ZId�dtdu�ZJdvdw� ZKd�dxdy�ZLdzd{� ZMd|d}� ZNe�d~�ZOdd�� ZPdS )�� N)�quote�
quote_plus�unquote��east_asian_width�
c @ s e Zd ZdZg ZdS )�Emptyz3A special tag object evaluating to the empty stringN)�__name__�
__module__�__qualname__�__doc__� __slots__� r r �0/usr/lib/python3/dist-packages/trac/util/text.pyr # s r c sb d� dd� }� fdd�}t dddd d
d
g d�||d� }|�| � tjdi |��}|jjtd
� |S )a8 Creates a Jinja2 ``Environment`` configured with Trac conventions.
All default parameters can optionally be overriden. The ``loader``
parameter is not set by default, so unless it is set by the
caller, only inline templates can be created from the environment.
:rtype: `jinja.Environment`
)�html�rss�xmlc S s | d u rdS | S �N� r )�vr r r �filterout_none9 s z!jinja2env.<locals>.filterout_nonec s | o| � dd�d � v S )N�.� )�rsplit)�template��extsr r �autoescape_extensions; s z(jinja2env.<locals>.autoescape_extensionsz${�}�#z##T)z
jinja2.ext.dozjinja2.ext.i18nzjinja2.ext.with_) �variable_start_string�variable_end_string�line_statement_prefix�line_comment_prefix�trim_blocks�
lstrip_blocks�
extensions�finalize�
autoescape��lenNr )�dict�update�jinja2�Environment�globalsr* )�kwargsr r �defaults�jenvr r r � jinja2env. s(
�
�r3 Fc K s t dd| i|���| �S )aZ Creates a Jinja2 ``Template`` from inlined source.
:param template: the template content
:param text: if set to `False`, the result of the variable
expansion will be XML/HTML escaped
:param kwargs: additional arguments to pass to `jinja2env`. See
`jinja2.Environment` for supported arguments.
r( Nr )r3 �from_string)r �textr0 r r r �jinja2templateO s r6 c C s� t | t�rzt| |pd�W S ty t| d� Y S w t | t�rnzt| �}W n ty; d�dd� | jD �� Y S w tj dkrlt | t
�rO| jrOt| j�}nt | t
j�r^| jr^t| j�}nd}|rl|�||�dd ��}|S t| �S )
a Convert input to a `str` object.
For a `bytes` object, we'll first try to decode the bytes using the given
`charset` encoding (or UTF-8 if none is specified), then we fall back to
the latin1 encoding which might be correct or not, but at least preserves
the original byte sequence by mapping each byte to the corresponding
unicode code point in the range U+0000 to U+00FF.
For anything else, a simple `str()` conversion is attempted,
with special care taken with `Exception` objects.
�utf-8�latin1� c s � � | ]}t |�V qd S �N��
to_unicode)�.0�argr r r � <genexpr>u � � zto_unicode.<locals>.<genexpr>�ntN�\\�\)�
isinstance�bytes�str�UnicodeDecodeError� Exception�UnicodeError�join�args�os�name�EnvironmentError�filename�repr�configparser�ParsingError�source�replace)r5 �charset�resultrT r r r r= ] s,
�
�
r= c C sR d| j jt| �f }|r'ddlm} |� �d�dd� }dtd�|��|f }|S )z�Convert an `Exception` to a `str` object.
In addition to `to_unicode`, this representation of the exception
also contains the class name and optionally the traceback.
z%s: %sr )�get_last_traceback�
N���z
%s
%s)� __class__r r= � trac.utilrX �splitrK )�e� traceback�messagerX �traceback_onlyr r r �exception_to_unicode� s rb c C s@ t | t�rzt| t�� �W S ty t| d� Y S w t| �S )z@Convert a filesystem path to str, using the filesystem encoding.r8 )rE rF rG �sys�getfilesystemencodingrH )�pathr r r �path_to_unicode� s
�rf u
\A[\s]+u
[\s]+\ZTc C s$ |rt �d| �} |rt�d| �} | S )a Strips unicode white-spaces and ZWSPs from ``text``.
:param leading: strips leading spaces from ``text`` unless ``leading`` is
`False`.
:param trailing: strips trailing spaces from ``text`` unless ``trailing``
is `False`.
r )�_ws_leading_re�sub�_ws_trailing_re)r5 �leading�trailingr r r �stripws� s
rl c C sf t �d��| �}|rdd� |ddd� D �|ddd�<