
    >wg$                         d dl Z d dlmZ ddlmZ ddlmZ ddlmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZ  e j*                  de j,                  e j.                  z        Z G d d	e      Z e       Zej8                  Zy)
    N)repeat   )	LIGATURES)auto_config)UNSHAPEDISOLATEDTATWEELZWJLETTERS_ARABICLETTERS_ARABIC_V2LETTERS_KURDISHFINALINITIALMEDIAL&connects_with_letters_before_and_afterconnects_with_letter_beforeconnects_with_letter_afteru2   [ؐ-ًؚ-ٰٟۖ-ۜ۟-۪ۨ-ۭࣔ-࣡ࣔ-࣭ࣣ-ࣿ]c                   @     e Zd ZdZd fd	Zed        Zd Zd Z xZ	S )ArabicReshapera  
    A class for Arabic reshaper, it allows for fine-tune configuration over the
    API.

    If no configuration is passed to the constructor, the class will check for
    an environment variable :envvar:`PYTHON_ARABIC_RESHAPER_CONFIGURATION_FILE`
    , if the variable is available, the class will load the file pointed to by
    the variable, and will read it as an ini file.
    If the variable doesn't exist, the class will load with the default
    configuration file :file:`default-config.ini`

    Check these links for information on the configuration files format:

    * Python 3: https://docs.python.org/3/library/configparser.html

    See the default configuration file :file:`default-config.ini` for details
    on how to configure your reshaper.
    c                    t         t        |           t        ||      | _        | j                  j                  d      | _        | j                  dk(  rt        | _        y | j                  dk(  rt        | _        y t        | _        y )NlanguageArabicV2Kurdish)superr   __init__r   configurationgetr   r   lettersr   r   )selfr   configuration_file	__class__s      V/var/www/horilla/myenv/lib/python3.12/site-packages/arabic_reshaper/arabic_reshaper.pyr   zArabicReshaper.__init__:   se    nd,.(8JK**..z:==J&,DL]]i'*DL)DL    c                 |   t        | d      sg }i }d}d}d}t        D ]S  }|\  }}| j                  j                  |      s$||   ||<   |j	                  dj                  ||                |dz  }U || _        t        j                  dj                  |      t        j                        | _        | j                  S )N__ligatures_rer   r   z({})|)hasattrr   r   
getbooleanappendformat!_re_group_index_to_ligature_formsrecompilejoinUNICODE_ArabicReshaper__ligatures_re)	r   patterns re_group_index_to_ligature_formsindexFORMSMATCHligature_recordligaturereplacements	            r"   _ligatures_rezArabicReshaper._ligatures_reG   s    t-.H/1,EEE#, (7%+))44X>:Ee:L07k%.@ AB
 1 2 #%**SXXh-?"LD"""r#   c                 P    t        | d      s| j                  S | j                  |   S )Nr+   )r'   r9   r+   )r   group_indexs     r"   '_get_ligature_forms_from_re_group_indexz6ArabicReshaper._get_ligature_forms_from_re_group_index\   s*    t@A%%%55kBBr#   c                 h	   |syg }d}d}d}| j                   j                  d      }| j                   j                  d      }| j                   j                  d      }| j                   j                  d      }	| j                   j                  d	      }
i }|
rt        nt        }|D ]  }t        j                  |      rP|st        |      dz
  }|	r|dz  }||vrg ||<   |	r||   j                  d|       nn||   j                  |       nX|t        k(  r|rnK|t        k(  r|sn>|| j                  vr|j                  ||f       n|s|j                  ||f       n|d   }||   |k(  r|j                  ||f       nt        || j                        s|j                  ||f       nt        ||   | j                        s|j                  ||f       n||   t        k(  r-t        ||   | j                        s|j                  ||f       nS||   |k(  r&||   t         f|d<   |j                  |t        f       n%||   t"        f|d<   |j                  |t        f       |st        |      dkD  s|d
   |   t        k(  s|j%                  t        |      dz
          |r!|r|d   |   t        k(  r|j%                          | j                   j                  d      rt        j'                  d|      }|r|j)                  t        d      }t+        j,                  | j.                  |      D ]  }t1        d t3        |j5                               D        d      }| j7                  |      }|j9                         \  }}||   |   }||dz
     |   }d }||t         fv r||t        fv rt        }nt         }n||t        fv rt        }nt"        }||   s||   |f||<   t;        d|f|dz
  |z
        ||dz   |  g }|sd|v r|j=                  |d          t3        |      D ]v  \  }}||   rP||   |k(  s||   t        k(  r|j                  ||          n'|j                  | j                  ||      ||             |r^||v sc|j=                  ||          x dj?                  |      S )N r   r   delete_harakatdelete_tatweelsupport_zwjshift_harakat_position use_unshaped_instead_of_isolated   support_ligaturesc              3   ,   K   | ]  \  }}|s	|  y w)N ).0igroups      r"   	<genexpr>z)ArabicReshaper.reshape.<locals>.<genexpr>   s      $"!U5A$s   
) r   r(   r   r   
HARAKAT_REmatchleninsertr)   r	   r
   r   r   r   r   r   r   r   popsubreplacer,   finditerr9   next	enumerategroupsr<   spanr   extendr.   )r   textoutputLETTERFORMNOT_SUPPORTEDr@   rA   rB   rC   rD   positions_harakatisolated_formletterpositionprevious_letterrO   r;   formsaba_formb_formligature_formresultrK   os                              r"   reshapezArabicReshaper.reshapea   s   ++667GH++667GH((33MB!%!3!3!>!>$"
 ,0+=+=+H+H.,
(  = "BJ 	  3	,F'%"6{QH- A'8868)(3-)(3::1fE)(3::6B7"~3{t||+v}56v}56"(*"4(M9MM6="9:4VT\\JMM6="9:3'/?MM6="9:%d+u4<)&14<< MM6="9:$T*m;'/"F2J MM65/2
 (/"F2J MM65/2 s6{Q6":f3E3L

3v;?+g3	,j 6fRj&8C&?JJL(()<=>>"d+D ||GR0T%7%7> "G" $&/&?$ DD zz|14At, $ mW55-!77(0(/-!77(-(.]+"=1=Aq	 &M':AEAI Fqs1E"GH "(9"9MM+B/0f% 		8DAqyT7m+qw(/BMM!F),MM$,,qy"9!D'"BC!))MM"3A"67		8 wwvr#   )NN)
__name__
__module____qualname____doc__r   propertyr9   r<   rm   __classcell__)r!   s   @r"   r   r   &   s-    &* # #(C
Kr#   r   )r,   	itertoolsr   	ligaturesr   reshaper_configr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r-   r/   XrN   objectr   default_reshaperrm   rI   r#   r"   <module>rz      sy    
    (O O O O
 RZZ
 JJ
"FV FR "# 

"
"r#   