Ë  üîî¹ ãó¼—dZdZdZdZdZdZdZddlZGd „d e«Z e «Z e ja gd ¢Z dd „Zdd „Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zy)z_ smartypants module ================== :func:`smartypants` is the core of smartypants module. z Yu-Jie Linzlivibetter@gmail.comz2.0.0z BSD Licensez/https://bitbucket.org/livibetter/smartypants.pyzPython with the SmartyPantséNcó—eZdZdZdZ dZ dezZ eezZdZ dezZ dezZ ee ze zZ dZ d Z d Z d Z d Z eezezZd Z eezeze zZ eeze ze zZ eeze ze zZ ed„«Zej0d„«Zy)Ú_AttrzC class for instantiation of module attribute :attr:`Attr`. éééééé é@é€éiircó—tS)z7Default value of attributes, same value as :attr:`set1`©Údefault_smartypants_attr)Úselfs ú0/usr/lib/python3.12/site-packages/smartypants.pyÚdefaultz _Attr.default†s €ô(Ð'ócó—|ay©Nr)rÚattrs rrz _Attr.defaultŒs €ð$(Ñ rN)Ú__name__Ú __module__Ú __qualname__Ú__doc__ÚqÚbÚBÚmask_bÚdÚDÚiÚmask_dÚeÚwÚuÚhÚsÚmask_oÚset0Úset1Úset2Úset3ÚpropertyrÚsetter©rrrrs2„ñð €Aðð €Aðð �‰ €Aðð �‰U€Fà€Aðð �‰ €Aðð �‰ €Aðð �‰U�Q‰Y€Fà€Aðð €Að ð €Aðð €Aðð €Aðð �‰U�Q‰Y€Fà €DØ1Ø ˆq‰5�1‰9�q‰=€DØAØ ˆq‰5�1‰9�q‰=€Dðð ˆq‰5�1‰9�q‰=€Dðð ñ(óð(ð  ‡^�^ñ(óñ(rr)ÚpreÚsampÚcodeÚttÚkbdÚscriptÚstyleÚmathcó®—|€t}t|ttf«rdj |«}t j d|zt j«S)zÕ Convert a list of skipped tags into regular expression The default *tags* are :attr:`tags_to_skip`. >>> f = _tags_to_skip_regex >>> print(f(['foo', 'bar']).pattern) <(/)?(foo|bar)[^>]*> Ú|z<(/)?(%s)[^>]*>)Ú tags_to_skipÚ isinstanceÚlistÚtupleÚjoinÚreÚcompileÚI)Útagss rÚ_tags_to_skip_regexrD¤sD€ð €|܈ä�$œœu˜ Ô&Ø�x‰x˜‹~ˆä �:‰:Ð'¨$Ñ.´·±Ó 5Ð5rcó"—g}|€tj}|tjz}|tjz}|tjz}|tj z}|tj z}|tjz}t|«} g} d} d} t«} | D�]X}|ddk(rÆ| j|d«| j|d«}|sŒ7|jd«s1|j|jd«j««d} Œyt|«dkDr9|d }|jd«j«|k(r|j«n t|«dk(sŒÏd} ŒÒ|d}|d d}| �sgt!|«}|rt#j$d d |«}|rZ|tj&k(r t)|«}|tj*k(r t-|«}|tj.k(r t1|«}|r t3|«}|tj4k(r t7|«}|tj8k(r t;|«}|rM|d k(rt#jd | «rd}n/d}n,|d k(rt#jd | «rd}nd}n t=|«}|rM|tj>k(rdn+|tj@k(rdn|tjBk(rdnd}tE||«}|} | j|«�Œ[djG| «S)zµ SmartyPants function >>> print(smartypants('"foo" -- bar')) “foo” — bar >>> print(smartypants('"foo" -- bar', Attr.d)) "foo" — bar NFÚrÚtagrrTéÿÿÿÿz"Ú"Ú'z\Sú’ú‘ú”ú“é)$ÚAttrrrrr#r$r)r%Ú _tokenizerDÚappendÚmatchÚgroupÚlowerÚlenÚpopÚprocess_escapesr@Úsubr Úconvert_dashesr!Úconvert_dashes_oldschoolr"Ú!convert_dashes_oldschool_invertedÚconvert_ellipsesrÚconvert_backticksrÚconvert_single_backticksÚconvert_quotesr&r'r(Úconvert_entitiesr?)ÚtextrÚskipped_tag_stackÚ do_quotesÚ do_backticksÚ do_dashesÚ do_ellipsesÚ do_entitiesÚ convert_quotÚtokensÚresultÚin_preÚprev_token_last_charÚtags_to_skip_regexÚ cur_tokenÚ skip_matchÚ_tagÚtÚ last_charÚmodes rÚ smartypantsru·sÅ€ðÐà €|Ü�|‰|ˆà”t—v‘v‘ €IØœ$Ÿ+™+Ñ%€LØ”t—{‘{Ñ"€IØœŸ™‘-€KØœŸ™Ñ$€KØœ$Ÿ&™&‘=€Lä �t‹_€FØ €FØ €FàÐô-Ó.Ðäˆ Ø �Q‰<˜5Ò ð �M‰M˜) A™,Ô 'Ø+×1Ñ1°)¸A±,Ó?ˆJÚØ!×'Ñ'¨Ô*Ø%×,Ñ,¨Z×-=Ñ-=¸aÓ-@×-FÑ-FÓ-HÔIØ!‘FäÐ,Ó-°Ò1Ø0°Ñ4˜Ø%×+Ñ+¨AÓ.×4Ñ4Ó6¸$Ò>Ø-×1Ñ1Õ3à ôÐ,Ó-°Ó2Ø!&™à˜!‘ ˆAà˜"˜#˜ˆIÚÜ# AÓ&�áÜŸ™˜x¨¨aÓ0�AáØ ¤D§F¡FÒ*Ü*¨1Ó-˜Ø ¤D§F¡FÒ*Ü4°QÓ7˜Ø ¤D§F¡FÒ*Ü=¸aÓ@˜áÜ(¨Ó+�Að ¤4§6¡6Ò)Ü)¨!Ó,�Aà¤4§6¡6Ò)Ü0°Ó3�AáØ˜C’xäŸ8™8 DÐ*>Ô?Ø )™Aà )™AؘcšäŸ8™8 DÐ*>Ô?Ø )™Aà )™Aô+¨1Ó-˜áØ!,´·±Ò!6™AØ!,´·±Ò!6™AØ!,´·±Ò!6™AØðô)¨¨DÓ1�Aà#,Ð Ø �M‰M˜!Ö ðWðZ �7‰7�6‹?Ðrcó—d}tjd|›d�d|«}tjd|›d�d|«}tjdd|«}tjd d |«}tjd d|«}d }d }tjd|›d�tj«}|jd|«}tjd|›d�tj«}|jd|«}tjd|›d�tj«}|jd|«}tjdd|«}tjd|›d�tj«}|jd|«}tjd|›d�tj«}|jd|«}tjd|›d�tj«}|jd|«}tjdd|«}|S) zŸ Convert quotes in *text* into HTML curly quote entities. >>> print(convert_quotes('"Isn\'t this fun?"')) “Isn’t this fun?” z)[!"#\$\%'()*+,-.\/:;<=>?\@\[\\\]\^_`{|}~]z^'(?=z\\B)rKz^"(?=rMz"'(?=\w)z“‘z'"(?=\w)z‘“z \b'(?=\d{2}s)z[^\ \t\r\n\[\{\(\-]z–|—zü ( \s | # a whitespace char, or   | # a non-breaking space entity, or -- | # dashes, or &[mn]dash; | # named dash entities zÎ | # or decimal entities &\#x201[34]; # or hex ) ' # the quote (?=\w) # followed by a word character z \1‘z (z:) ' (?!\s | s\b | \d) z \1’z3) ' (\s | s\b) z \1’\2rJrLzÎ | # or decimal entities &\#x201[34]; # or hex ) " # the quote (?=\w) # followed by a word character z \1“z #(zi)? # character that indicates the quote should be closing " (?=\s) zU) # character that indicates the quote should be closing " z \1”rIrN)r@rYrAÚVERBOSE)rbÚ punct_classÚ close_classÚ dec_dashesÚopening_single_quotes_regexÚclosing_single_quotes_regexÚopening_double_quotes_regexÚclosing_double_quotes_regexs rr`r`*sô€ðC€Kô �6Š6ª Ð5°yÀ$Ó G€DÜ �6Š6ª Ð5°yÀ$Ó G€Dô �6‰6�/Ð#3°TÓ :€DÜ �6‰6�/Ð#3°TÓ :€Dô �6‰6Ð&¨ °4Ó 8€Dà(€KØ"€Jô#%§*¢*òð . ô"$§¡ó #-Ðð '× *Ñ *¨<¸Ó >€Dä"$§*¢*òð .!ô#%§*¡*ó #.Ðð '× *Ñ *¨<¸Ó >€Dä"$§*¢*òð .!ô#%§*¡*ó #.Ðð '× *Ñ *¨>¸4Ó @€Dô �6‰6�#�y $Ó '€Dô#%§*¢*òð . ô"$§¡ó #-Ðð '× *Ñ *¨<¸Ó >€Dô#%§*¢*òð .!ô#%§*¡*ó #.Ðð '× *Ñ *¨9°dÓ ;€Dä"$§*¢*òð.!ô#%§*¡*ó#.Ðð '× *Ñ *¨<¸Ó >€Dô �6‰6�#�y $Ó '€Dà €Krcób—tjdd|«}tjdd|«}|S)zÀ Convert ````backticks''``-style double quotes in *text* into HTML curly quote entities. >>> print(convert_backticks("``Isn't this fun?''")) “Isn't this fun?” z``rNz''rM©r@rY©rbs rr^r^ˆs-€ô �6‰6�$˜  4Ó (€DÜ �6‰6�$˜  4Ó (€DØ €Krcób—tjdd|«}tjdd|«}|S)zÉ Convert ```backticks'``-style single quotes in *text* into HTML curly quote entities. >>> print(convert_single_backticks("`Isn't this fun?'")) ‘Isn’t this fun?’ Ú`rLrJrKr€r�s rr_r_–s-€ô �6‰6�#�y $Ó '€DÜ �6‰6�#�y $Ó '€DØ €Krcó4—tjdd|«}|S)zÓ Convert ``--`` in *text* into em-dash HTML entities. >>> quote = 'Nothing endures but change. -- Heraclitus' >>> print(convert_dashes(quote)) Nothing endures but change. — Heraclitus ú--ú—r€r�s rrZrZ¤s€ô �6‰6�$˜  4Ó (€DØ €Krcób—tjdd|«}tjdd|«}|S)a3 Convert ``--`` and ``---`` in *text* into en-dash and em-dash HTML entities, respectively. >>> quote = 'Life itself is the proper binge. --- Julia Child (1912--2004)' >>> print(convert_dashes_oldschool(quote)) Life itself is the proper binge. — Julia Child (1912–2004) ú---r†r…ú–r€r�s rr[r[±s-€ô �6‰6�%˜ DÓ )€DÜ �6‰6�$˜  4Ó (€DØ €Krcób—tjdd|«}tjdd|«}|S)uß Convert ``--`` and ``---`` in *text* into em-dash and en-dash HTML entities, respectively. Two reasons why: * First, unlike the en- and em-dash syntax supported by :func:`convert_dashes_oldschool`, it's compatible with existing entries written before SmartyPants 1.1, back when ``--`` was only used for em-dashes. * Second, em-dashes are more common than en-dashes, and so it sort of makes sense that the shortcut should be shorter to type. (Thanks to Aaron Swartz for the idea.) >>> quote = 'Dare to be naïve. -- Buckminster Fuller (1895---1983)' >>> print(convert_dashes_oldschool_inverted(quote)) Dare to be naïve. — Buckminster Fuller (1895–1983) rˆr‰r…r†r€r�s rr\r\Às-€ô( �6‰6�%˜ DÓ )€DÜ �6‰6�$˜  4Ó (€DØ €Krcób—tjdd|«}tjdd|«}|S)z{ Convert ``...`` in *text* into ellipsis HTML entities >>> print(convert_ellipses('Huh...?')) Huh…? z\.\.\.ú…z\. \. \.r€r�s rr]r]Ùs-€ô �6‰6�- ¨DÓ 1€DÜ �6‰6�/ 9¨dÓ 3€DØ €Krcót—ddddddddœ}|j«D]\}}|j|||«}Œ|S) uŽ Convert numeric character references to, if *mode* is - *0*: Unicode characters - *1*: HTML named entities - *2*: ASCII equivalents >>> print(convert_entities('‘', 0)) ‘ >>> print(convert_entities('‘SmartyPants’', 1)) ‘SmartyPants’ >>> print(convert_entities('“Hello — world.”', 2)) "Hello -- world." )u–z–Ú-)u—z—r…)u‘z‘rJ)u’z’rJ)u“z“rI)uâ€�z”rI)u…z…z...)r‰r†rLrKrNrMrŒ)ÚitemsÚreplace)rbrtÚCTBLÚkÚvs rraraæsQ€ð"+Ø+Ø*Ø*Ø*Ø*Ø-ñ €Dð— ‘ – ‰ˆˆ1Ø�|‰|˜A˜q ™wÓ'‰ðð €Krcó—tjdd|«}tjdd|«}tjdd|«}tjdd|«}tjd d |«}tjd d |«}|S) aq Processe the following backslash escape sequences in *text*. This is useful if you want to force a "dumb" quote or other character to appear. +--------+-----------+-----------+ | Escape | Value | Character | +========+===========+===========+ | ``\\`` | ``\`` | ``\`` | +--------+-----------+-----------+ | ``\"`` | ``"`` | ``"`` | +--------+-----------+-----------+ | ``\'`` | ``'`` | ``'`` | +--------+-----------+-----------+ | ``\.`` | ``.`` | ``.`` | +--------+-----------+-----------+ | ``\-`` | ``-`` | ``-`` | +--------+-----------+-----------+ | ``\``` | ````` | ``\``` | +--------+-----------+-----------+ >>> print(process_escapes(r'\\')) \ >>> print(smartypants(r'"smarty" \"pants\"')) “smarty” "pants" z\\\\z\z\\"z"z\\'z'z\\\.z.z\\-z-z\\`z`r€r�s rrXrXsu€ô6 �6‰6�'˜7 DÓ )€DÜ �6‰6�&˜' 4Ó (€DÜ �6‰6�&˜' 4Ó (€DÜ �6‰6�'˜7 DÓ )€DÜ �6‰6�&˜' 4Ó (€DÜ �6‰6�&˜' 4Ó (€Dà €Krcóh—g}tjdtj«}|j|«}d}|rÒ|j d«r"|j d|j d«g«|j d«}d}|j d«r5d|d d jd «j«jd «vrd}|j ||g«|j«}|j||j««}|rŒÒ|t|«kr|j d||d g«|S) aÝ Reference to an array of the tokens comprising the input string. Each token is either a tag (possibly with nested, tags contained therein, such as ````, or a run of text between tags. Each element of the array is a two-element array; the first is either 'tag' or 'text'; the second is the actual value. Based on the _tokenize() subroutine from `Brad Choate's MTRegex plugin`__. __ http://www.bradchoate.com/past/mtregex.php z([^<]*)(