Ë
    ‹±šfý]  ã                   ó  — d dl mZmZmZ d dlZd dlZd dlZd dlZd dlZd dl	m
Z
 d dlmZ d dlZ ej                  e«      Z G d„ de«      Z G d„ de«      Z G d„ d	e«      Z G d
„ de«      Z G d„ de«      Z G d„ de«      Zy)é    )ÚdivisionÚprint_functionÚunicode_literalsN)Úunicode_strc                   óT   — e Zd ZdZdd„Zd„ Zd„ Zd„ Zd„ Zd„ Z	d	„ Z
d
„ Zd„ Zd„ Zd„ Zy)ÚSpellCheckeréd   Nc                 ó.   — || _         d | _        i | _        y ©N)Ú_language_dbÚ_backendÚ_cached_queries)ÚselfÚlanguage_dbs     ú6/usr/lib/python3/dist-packages/Onboard/SpellChecker.pyÚ__init__zSpellChecker.__init__(   s   € Ø'ˆÔØˆŒØ!ˆÕó    c                 óT  — |€.| j                   r| j                   j                  «        d| _         nh|dk(  rt        }nt        }| j                   rt	        | j                   «      |k(  s2| j                   r| j                   j                  «         |«       | _         | j                  «        y)z' Switch spell check backend on the fly Nr   )r   ÚstopÚhunspellÚ
aspell_cmdÚtypeÚinvalidate_query_cache)r   ÚbackendÚ_classs      r   Úset_backendzSpellChecker.set_backend-   sz   € àˆ?Ø�}Š}Ø—‘×"Ñ"Ô$Ø ˆD�Mà˜!Š|Ü!‘ä#�à—=’=Ü˜Ÿ™Ó&¨&Ò0Ø—=’=Ø—M‘M×&Ñ&Ô(Ù &£�”à×#Ñ#Õ%r   c                 ó„  — d}| j                  |«      }| j                  r�|| j                  j                  «       k(  ss| j                  j                  «        |r| j                  j	                  |«       d}n9t
        j                  dj                  t        | j                  «      |¬«      «       | j                  «        |S )NFTz0No matching dictionaries for '{backend}' {dicts}©r   Údicts)
Ú_find_matching_dictsr   Úget_active_dict_idsr   ÚstartÚ_loggerÚinfoÚformatr   r   )r   Údict_idsÚsuccessÚidss       r   Úset_dict_idszSpellChecker.set_dict_idsA   sœ   € ØˆØ×'Ñ'¨Ó1ˆØ�=Š=Ø�d—m‘m×7Ñ7Ó9Ò9Ø�M‰M×ÑÔ ÙØ—‘×#Ñ# CÔ(Ø‘ä—‘ÐOß$™f¬T°$·-±-Ó-@Ø+3ð %ó 5ô6ð 	×#Ñ#Ô%Øˆr   c                 ób   — g }|D ]'  }| j                  |«      }|sŒ|j                  |«       Œ) |S r   )Ú_find_matching_dictÚappend)r   r&   ÚresultsÚdict_idÚids        r   r    z!SpellChecker._find_matching_dictsQ   s<   € ØˆØò 	#ˆGØ×)Ñ)¨'Ó2ˆBÚØ—‘˜rÕ"ð	#ð ˆr   c                 ó  — | j                  «       }d}||v r|}|S |j                  dd«      }||v r|}|S | j                  rI| j                  j                  |«      \  }}||v r|}|S | j                  j	                  |«      }|r||v r|}|S )z�
        Try to match up the given dict_id with the available dictionaries.
        Look for alternatives if there is no direct match.
        Ú Ú_ú-)Úget_supported_dict_idsÚreplacer   Úsplit_lang_idÚget_main_lang_id)r   r.   Úavailable_dict_idsÚresultÚalt_idÚ	lang_codeÚcountry_codeÚlang_ids           r   r+   z SpellChecker._find_matching_dictY   s¼   € ð
 "×8Ñ8Ó:ÐàˆàÐ(Ñ(ØˆFð" ˆð —_‘_ S¨#Ó.ˆFØÐ+Ñ+Ø�ð ˆð ×"Ò"à*.×*;Ñ*;×*IÑ*IÈ'Ó*RÑ'�	˜<ØÐ 2Ñ2Ø&�Fð ˆð	 #×/Ñ/×@Ñ@ÀÓK�GÙ 7Ð.@Ñ#@Ø!(˜àˆr   c                 óŽ   — d}g }| j                   r2| j                  |«      }|D ]  }|d   d   |kD  r ||fS |d   }|d   }Œ ||fS )zÞ
        Return spelling suggestions for word.
        Multiple result sets may be returned, as the spell
        checkers may return more than one result for certain tokens,
        e.g. before and after hyphens.
        Nr   é   ©r   Úquery_cached)r   ÚwordÚcaret_offsetÚspanÚsuggestionsr-   r9   s          r   Úfind_correctionszSpellChecker.find_correctionsv   sw   € ð ˆØˆØ�=Š=Ø×'Ñ'¨Ó-ˆGð "ò !�Ø˜!‘9˜Q‘< ,Ò.Øð �[Ð Ð ð % Q™i�Ø˜a‘y‘ð	!ð �[Ð Ð r   c                 ór   — g }| j                   r#| j                  |«      }|D �cg c]  }|d   ‘Œ	 }}|S c c}w )zó
        Return misspelled spans (begin- to end-index) inside word.
        Multiple result sets may be returned, as the spell
        checkers may return more than one result for certain tokens,
        e.g. before and after hyphens.
        r   r@   )r   rB   Úspansr-   r9   s        r   Úfind_incorrect_spansz!SpellChecker.find_incorrect_spansŒ   sC   € ð ˆØ�=Š=Ø×'Ñ'¨Ó-ˆGð .5Ö5 6�V˜A“YÐ5ˆEÐ5Øˆùò 6s   ¤4c                 óÊ  — | j                   j                  |«      }|€«t        | j                   «      }|| j                  k\  rc|dz  }t        j                  dj                  ||«      «       t        | j                   j                  «       d„ ¬«      }t        ||d «      | _         | j                  |«      }d|g}|| j                   |<   t        j                  «       |d<   |d   S )	zF
        Return cached query or ask the backend if necessary.
        Né   z,shrinking query cache from {} to {} entries.c                 ó   — | d   d   S )Nr?   r   © )Úxs    r   ú<lambda>z+SpellChecker.query_cached.<locals>.<lambda>¬   s   € °°1±°a±€ r   )Úkeyg        r   r?   )r   ÚgetÚlenÚMAX_QUERY_CACHE_SIZEr#   Údebugr%   ÚsortedÚitemsÚdictÚqueryÚtime)r   rB   rX   ÚsizeÚnew_sizeÚqueriesr-   s          r   rA   zSpellChecker.query_cachedœ   sÖ   € ð ×$Ñ$×(Ñ(¨Ó.ˆØˆ=ä�t×+Ñ+Ó,ˆDØ�t×0Ñ0Ò0Ø 1™9�ä—‘ÐLß%™v d¨HÓ5ô7ô ! ×!5Ñ!5×!;Ñ!;Ó!=Ù'8ô:�ä'+¨G°H°IÐ,>Ó'?�Ô$ð —j‘j Ó&ˆGØ˜'�NˆEØ).ˆD× Ñ  Ñ&ä—9‘9“;ˆˆa‰à�Q‰xˆr   c                 ó8   — | j                   j                  |«      S r   )r   rX   )r   rB   s     r   rX   zSpellChecker.query¸   s   € Ø�}‰}×"Ñ" 4Ó(Ð(r   c                 ó   — i | _         y r   )r   ©r   s    r   r   z#SpellChecker.invalidate_query_cache»   s
   € Ø!ˆÕr   c                 ó6   — | j                   j                  «       S r   )r   r4   r_   s    r   r4   z#SpellChecker.get_supported_dict_ids¾   s   € Ø�}‰}×3Ñ3Ó5Ð5r   r   )Ú__name__Ú
__module__Ú__qualname__rS   r   r   r)   r    r+   rF   rI   rA   rX   r   r4   rM   r   r   r   r   %   s?   „ ØÐó"ò
&ò(ò òò:!ò,ò ò8)ò"ó6r   r   c                   ó>   — e Zd ZdZd
d„Zd
d„Zd„ Zd„ Zd„ Zd„ Z	d	„ Z
y)Ú	SCBackendz2 Abstract base class of all spellchecker backends Nc                 ó    — d | _         d | _        y r   )Ú_active_dictsÚ_p©r   r&   s     r   r   zSCBackend.__init__Å   s   € Ø!ˆÔØˆ�r   c                 óp   — || _         t        j                  dj                  t	        | «      |¬«      «       y )Nzstarting '{backend}' {dicts}r   )rg   r#   r$   r%   r   ri   s     r   r"   zSCBackend.startÉ   s,   € Ø%ˆÔÜ�‰Ð3ß‘f¤T¨$£Z°x�fÓ@õ	Br   c                 ó�   — | j                  «       r6t        j                  dj                  t	        | «      ¬«      «       d | _        y y )Nzstopping '{backend}')r   )Ú
is_runningr#   r$   r%   r   rg   r_   s    r   r   zSCBackend.stopÎ   s8   € Ø�?‰?ÔÜ�L‰LÐ/ß ™&¬¨d«˜&Ó4ô6à!%ˆDÕð r   c                 ó   — t        «       S r   ©ÚNotImplementedErrorr_   s    r   rl   zSCBackend.is_runningÔ   s   € Ü"Ó$Ð$r   c                 ó  — g }| j                   r!| j                   j                  «       �d| _         | j                   �rÃt        |«      t        d«      k(  rd|z   dz   }|j                  d«      }nd|z   dz   }| j                   j                  j                  |«       | j                   j                  j                  «        	 | j                   j                  j                  «       j                  d«      }|j                  «       }|s	 |S |dd d	k(  rƒ|j                  d
«      }|d   j                  «       }t        |d   «      dz
  }|t        |d   «      z   }|||d   g}	|d   j                  «       j                  d«      }
|j                  |	|
g«       |dd dk(  rc|j                  d
«      }|d   j                  «       }t        |d   «      dz
  }|t        |d   «      z   }|||d   g}	g }
|j                  |	|
g«       �Œ@|S ©z×
        Query for spelling suggestions.
        Text may contain one or more words. Each word generates its own
        list of suggestions. The spell checker backend decides about
        word boundaries.
        Nr1   ú^ú
úUTF-8ó   ^ó   
r?   ú&ú:r   é   z, ú#rK   ©rh   Úpollr   ÚencodeÚstdinÚwriteÚflushÚstdoutÚreadlineÚdecodeÚstripÚsplitÚintrR   r,   ©r   Útextr-   ÚlineÚsÚsectionsÚaÚbeginÚendrD   rE   s              r   rX   zSCBackend.query×   óá  € ð ˆð �7Š7˜4Ÿ7™7Ÿ<™<›>Ð1ØˆDŒGà�7‹7ô �D‹zœT "›XÒ%Ø˜T‘z DÑ(�Ø—{‘{ 7Ó+‘à˜d‘{ UÑ*�à�G‰G�M‰M×Ñ Ô%Ø�G‰G�M‰M×ÑÔ!ØØ—G‘G—N‘N×+Ñ+Ó-×4Ñ4°WÓ=�Ø—G‘G“I�ÙØð$ ˆð# �R�a�5˜C’<Ø Ÿw™w s›|�HØ  ™×)Ñ)Ó+�AÜ  !¡›I¨™M�EØ!¤C¨¨!©£IÑ-�CØ! 3¨¨!©Ð-�DØ"*¨1¡+×"3Ñ"3Ó"5×";Ñ";¸DÓ"A�KØ—N‘N D¨+Ð#6Ô7Ø�R�a�5˜C’<Ø Ÿw™w s›|�HØ  ™×)Ñ)Ó+�AÜ  !¡›I¨™M�EØ!¤C¨¨!©£IÑ-�CØ! 3¨¨!©Ð-�DØ"$�KØ—N‘N D¨+Ð#6Ô7ñ) ð, ˆr   c                 ó   — t        «       ‚©ú6
        Return raw supported dictionary ids.
        rn   r_   s    r   r4   z SCBackend.get_supported_dict_ids  ó   € ô "Ó#Ð#r   c                 ó   — | j                   S ©z/
        Return active dictionary ids.
        ©rg   r_   s    r   r!   zSCBackend.get_active_dict_ids  ó   € ð ×!Ñ!Ð!r   r   )ra   rb   rc   Ú__doc__r   r"   r   rl   rX   r4   r!   rM   r   r   re   re   Â   s*   „ Ù<óóBò
&ò%ò/òb$ó"r   re   c                   ó¸   ‡ — e Zd ZdZdd„Zdˆ fd„	Zˆ fd„Zd„ Z ej                  dej                  ej                  z  «      Zd„ Zd„ Zd	„ Zed
„ «       Zd„ Zˆ xZS )r   a   
    Hunspell backend using the C API.

    Doctests:
    # known word
    >>> sp = hunspell(["en_US"])
    >>> sp.query("test")
    []

    # unknown word
    >>> sp = hunspell(["en_US"])
    >>> sp.query("jdaskljasd")  # doctest: +ELLIPSIS
    [[...
    c                 óf   — d | _         t        j                  | |«       |r| j                  |«       y y r   )Ú_osk_hunspellre   r   r"   ri   s     r   r   zhunspell.__init__$  s.   € Ø!ˆÔÜ×Ñ˜4 Ô*ÙØ�J‰J�xÕ ð r   c                 óÜ  •— t         t        | �  |«       |r˜| j                  |d   «      \  }}t        j                  dj                  ||«      «       |rY	 t        j                  ||«      | _	        t        j                  dj                  | j                  j                  «       «      «       y y y # t        $ r2}t        j                  dt        |«      z   «       d | _	        Y d }~y d }~ww xY w)Nr   zusing hunspell files '{}', '{}'zdictionary encoding '{}'z#failed to create hunspell backend: )Úsuperr   r"   Ú_search_dict_filesr#   r$   r%   ÚoskÚHunspellr›   Úget_encodingÚ	ExceptionÚerrorr   )r   r&   ÚdicÚaffÚeÚ	__class__s        €r   r"   zhunspell.start*  sÎ   ø€ ÜŒh˜Ñ# HÔ-áØ×.Ñ.¨x¸©{Ó;‰HˆC�Ü�L‰LÐ:ß#™V C¨Ó-ô/áð.Ü),¯©°c¸3Ó)?�DÔ&Ü—L‘LÐ!;ß"(¡&¨×);Ñ);×)HÑ)HÓ)JÓ"KõMð ð	 øô !ò .Ü—M‘MÐ"GÜ"-¨a£.ñ#1ô 2à)-�D×&Ñ&ûð.ús   ÁAB0 Â0	C+Â9(C&Ã&C+c                 óh   •— t         t        | �  «        | j                  «       rd | _        d | _        y y r   )r�   r   r   rl   r›   rg   ©r   r§   s    €r   r   zhunspell.stop;  s/   ø€ ÜŒh˜Ñ"Ô$Ø�?‰?ÔØ!%ˆDÔØ!%ˆDÕð r   c                 ó   — | j                   d uS r   )r›   r_   s    r   rl   zhunspell.is_runningA  s   € Ø×%Ñ%¨Ð-Ð-r   z[^-_\s]+c                 óÀ  — g }| j                   r­| j                  j                  |«      }|D ]�  }|j                  «       }|j	                  «       }|j                  «       }|||g}	 | j                   j                  |«      dk(  r7t        | j                   j                  |«      «      }	|j                  ||	g«       Œ� |S # t        $ r |j                  |g g«       Y Œ°w xY w)u  
        Query for spelling suggestions.
        Text may contain one or more words. Each word generates its own
        list of suggestions. Word boundaries are chosen to match the
        behavior of the hunspell command line tool, i.e. split at '-','_'
        and whitespace.

        Doctests:
        # one prediction token, two words for the spell checker
        >>> sp = hunspell(["en_US"])
        >>> q = sp.query("conter_trop")
        >>> q  # doctest: +ELLIPSIS
        [[[0, 6, 'conter'], [...
        >>> len(q)
        2

        # dashes
        >>> sp = hunspell(["en_US"])
        >>> sp.query("ubuntu-system")  # doctest: +ELLIPSIS
        [[[0, 6, 'ubuntu'], ['Ubuntu', 'Kubuntu', 'urbanite', 'urbanity']]]

        # unrecognized word returns error span with zero choices (# mark)
        >>> q = sp.query("á¼„Î½Î±Ï�Ï‡Î¿Ï‚")
        >>> q  # doctest:
        [[[0, 7, 'á¼„Î½Î±Ï�Ï‡Î¿Ï‚'], []]]
        >>> len(q)
        1

        # dictionaries come in various encodings, spot-check German
        >>> sp = hunspell(["de_DE"])
        >>> sp.query("FrÃ¼hstÃ¼ck")
        []
        >>> sp.query("FrÃ¼stÃ¼ck")   # doctest: +ELLIPSIS
        [[[0, 8, 'FrÃ¼stÃ¼ck'], ['FrÃ¼hstÃ¼ck', ...

        # dictionaries come in various encodings, spot-check Spanish
        >>> sp = hunspell(["es_ES"])
        >>> sp.query("situaciÃ³n")
        []
        >>> sp.query("situciÃ³n")   # doctest: +ELLIPSIS
        [[[0, 8, 'situciÃ³n'], ['situaciÃ³n', ...

        # dictionaries come in various encodings, spot-check Portuguese
        >>> sp = hunspell(["pt_PT"])
        >>> sp.query("questÃ£o")
        []
        >>> sp.query("quetÃ£o")   # doctest: +ELLIPSIS
        [[[0, 6, 'quetÃ£o'], ['questÃ£o', ...

        # dictionaries come in various encodings, spot-check French
        >>> sp = hunspell(["fr_FR"])
        >>> sp.query("garÃ§on")
        []
        >>> sp.query("garÃ§oon")   # doctest: +ELLIPSIS
        [[[0, 7, 'garÃ§oon'], ['garÃ§on', ...

        # dictionaries come in various encodings, spot-check Italian
        >>> sp = hunspell(["it_IT"])
        >>> sp.query("parlerÃ²")
        []
        >>> sp.query("parllerÃ²")   # doctest: +ELLIPSIS
        [[[0, 8, 'parllerÃ²'], ['parlerÃ²', ...

        # dictionaries come in various encodings, spot-check Russian
        >>> sp = hunspell(["ru_RU"])
        >>> sp.query("ÐžÐ‘Ð•Ð”Ð•Ð�Ð�Ð«Ð™") # dinner
        []
        >>> sp.query("ÐžÐ‘Ð•Ð”Ð•Ð�Ð«Ð™")   # doctest: +ELLIPSIS
        [[[0, 8, 'ÐžÐ‘Ð•Ð”Ð•Ð�Ð«Ð™'], ['ÐžÐ‘Ð•Ð”Ð•Ð�Ð�Ð«Ð™', ...

        # dictionaries come in various encodings, spot-check Greek
        >>> sp = hunspell(["el_GR"])
        >>> sp.query("Î©ÎºÎµÎ±Î½Î¿Ï�")
        []
        >>> sp.query("Î©ÎºÎµÎ±Î±Î½Î¿Ï�")   # doctest: +ELLIPSIS
        [[[0, 8, 'Î©ÎºÎµÎ±Î±Î½Î¿Ï�'], ['Î©ÎºÎµÎ±Î½Î¿Ï�', ...

        r   )r›   Ú
SPLITWORDSÚfinditerÚgroupr"   rŽ   ÚspellÚlistÚsuggestr,   ÚUnicodeEncodeError)
r   rˆ   r-   ÚmatchesÚmatchrB   r�   rŽ   rD   rE   s
             r   rX   zhunspell.queryF  sØ   € ð^ ˆà×ÒØ—o‘o×.Ñ.¨tÓ4ˆGØ ò /�Ø—{‘{“}�ØŸ™›�ØŸ	™	›�Ø˜s DÐ)�ð/Ø×)Ñ)×/Ñ/°Ó5¸Ò:Ü&*¨4×+=Ñ+=×+EÑ+EÀdÓ+KÓ&L˜ØŸ™¨¨kÐ':Ô;øð/ð  ˆøô *ò /ð —N‘N D¨" :Ö.ð	/ús   Á%AB>Â>CÃCc                 óî  — g }g }| j                  «       }|D ]d  }t        j                  j                  |dt        j                  j                  z   dz   «      }|j                  t        j                  |«      «       Œf |D ]r  }t        j                  j                  t        j                  j                  |«      «      \  }}|j                  «       j                  d«      rŒb|j                  |«       Œt |S )aO  
        Return raw supported dictionary ids.
        They may not all be valid language ids, e.g. en-GB
        instead of en_GB for myspell dicts.

        Doctests:
        # Just check it does anything at all
        >>> sp = hunspell(["en_US"])
        >>> sp.get_supported_dict_ids()   # doctest: +ELLIPSIS
        ['...
        Ú*r¤   Úhyph)Ú_get_dict_pathsÚosÚpathÚjoinÚextsepÚextendÚglobÚsplitextÚbasenameÚlowerÚ
startswithr,   )r   r&   Ú	filenamesÚpathsrº   Úfnr=   Ú_exts           r   r4   zhunspell.get_supported_dict_ids«  sÈ   € ð ˆð ˆ	Ø×$Ñ$Ó&ˆØò 	,ˆDÜ—‘—‘˜d C¬"¯'©'¯.©.Ñ$8¸5Ñ$@ÓAˆBØ×ÑœTŸY™Y r›]Õ+ð	,ð
 ò 	)ˆBÜŸG™G×,Ñ,¬R¯W©W×-=Ñ-=¸bÓ-AÓB‰MˆG�TØ—=‘=“?×-Ñ-¨fÕ5Ø—‘ Õ(ð	)ð
 ˆr   c                 óv   — | j                  «       }| j                  ||d«      }| j                  ||d«      }||fS )z9 Locate dictionary and affix files for the given dict_id r¥   r¤   )r¸   Ú_find_file_in_paths)r   r.   rÄ   r¥   r¤   s        r   rž   zhunspell._search_dict_filesÈ  sA   € à×$Ñ$Ó&ˆØ×&Ñ& u¨g°uÓ=ˆØ×&Ñ& u¨g°uÓ=ˆØ�Cˆxˆr   c                 óÔ   — | D ]c  }t         j                  j                  ||t         j                  j                  z   |z   «      }t         j                  j	                  |«      sŒa|c S  y)z+ Search for a file name in multiple paths. N)r¹   rº   r»   r¼   Úexists)rÄ   ÚnameÚ	extensionrº   Úfiles        r   rÈ   zhunspell._find_file_in_pathsÏ  sS   € ð ò 	ˆDÜ—7‘7—<‘<  d¬R¯W©W¯^©^Ñ&;¸iÑ&GÓHˆDÜ�w‰w�~‰~˜dÕ#Ø’ð	ð r   c                 óœ  — g }t         j                  j                  }g d¢}g d¢}g d¢}|j                  d«       t        j                  d«      }|r |j                  |j                  |«      «       |j                  |«       t        j                  d«      }|r"|j                  |«       |j                  |«       |j                  |«       |S )z‘
        Return all paths where dictionaries may be located.
        Path logic taken from the source of the hunspell command line tool.
        )z/usr/share/hunspellz/usr/share/myspellz/usr/share/myspell/dictsz/Library/Spelling)z.openoffice.org/3/user/wordbookz.openoffice.org2/user/wordbookz .openoffice.org2.0/user/wordbookzLibrary/Spelling)
z+/opt/openoffice.org/basis3.0/share/dict/oooz//usr/lib/openoffice.org/basis3.0/share/dict/ooozP/opt/openoffice.org2.4/share/dict/ooo,/usr/lib/openoffice.org2.4/share/dict/ooo,z%/opt/openoffice.org2.3/share/dict/oooz)/usr/lib/openoffice.org2.3/share/dict/oooz%/opt/openoffice.org2.2/share/dict/oooz)/usr/lib/openoffice.org2.2/share/dict/ooozO/opt/openoffice.org2.1/share/dict/ooo,/usr/lib/openoffice.org2.1/share/dict/oooz%/opt/openoffice.org2.0/share/dict/oooz)/usr/lib/openoffice.org2.0/share/dict/oooú.ÚDICPATHÚHOME)r¹   rº   Úpathsepr,   Úgetenvr½   r…   )r   rÄ   rÒ   ÚLIBDIRSÚUSEROOODIRSÚOOODIRSÚdicpathÚhomes           r   r¸   zhunspell._get_dict_pathsØ  s¥   € ð
 ˆä—'‘'—/‘/ˆò!ˆò
 ˆò
9ˆð 	�‰�SÔä—)‘)˜IÓ&ˆÙØ�L‰L˜Ÿ™ wÓ/Ô0à�‰�WÔä�y‰y˜Ó ˆÙØ�L‰L˜ÔØ�L‰L˜Ô%à�‰�WÔàˆr   r   )ra   rb   rc   r˜   r   r"   r   rl   ÚreÚcompileÚUNICODEÚDOTALLr¬   rX   r4   rž   ÚstaticmethodrÈ   r¸   Ú__classcell__©r§   s   @r   r   r     sg   ø„ ñó!õ.ô"&ò.ð �—‘˜K¨¯©°B·I±IÑ)=Ó>€JòcòJò:ð ñó ðö.r   r   c                   óF   ‡ — e Zd ZdZdˆ fd„	Zˆ fd„Zd„ Zd„ Zd„ Zd„ Z	ˆ xZ
S )	ÚSCBackend_cmdz. Abstract base class of command line backends c                 ó:   •— t         t        | �  |«       d | _        y r   )r�   rá   r   rh   )r   r&   r§   s     €r   r   zSCBackend_cmd.__init__  s   ø€ ÜŒm˜TÑ+¨HÔ5Øˆ�r   c                 óÌ   •— t         t        | �  t        «       | j	                  «       r<| j
                  j                  «        | j
                  j                  «        d | _        y y r   )r�   rá   r   r&   rl   rh   Ú	terminateÚwaitr©   s    €r   r   zSCBackend_cmd.stop  sE   ø€ ÜŒm˜TÑ+¬HÔ5Ø�?‰?ÔØ�G‰G×ÑÔØ�G‰G�L‰LŒNØˆD�Gð r   c                 ó   — | j                   d uS r   )rh   r_   s    r   rl   zSCBackend_cmd.is_running  s   € Ø—7‘7˜d�?Ð"r   c                 ó  — g }| j                   r!| j                   j                  «       �d| _         | j                   �rÃt        |«      t        d«      k(  rd|z   dz   }|j                  d«      }nd|z   dz   }| j                   j                  j                  |«       | j                   j                  j                  «        	 | j                   j                  j                  «       j                  d«      }|j                  «       }|s	 |S |dd d	k(  rƒ|j                  d
«      }|d   j                  «       }t        |d   «      dz
  }|t        |d   «      z   }|||d   g}	|d   j                  «       j                  d«      }
|j                  |	|
g«       |dd dk(  rc|j                  d
«      }|d   j                  «       }t        |d   «      dz
  }|t        |d   «      z   }|||d   g}	g }
|j                  |	|
g«       �Œ@|S rq   r{   r‡   s              r   rX   zSCBackend_cmd.query  r�   r   c                 ó   — t        «       ‚r‘   rn   r_   s    r   r4   z$SCBackend_cmd.get_supported_dict_idsK  r“   r   c                 ó   — | j                   S r•   r–   r_   s    r   r!   z!SCBackend_cmd.get_active_dict_idsQ  r—   r   r   )ra   rb   rc   r˜   r   r   rl   rX   r4   r!   rÞ   rß   s   @r   rá   rá   	  s%   ø„ Ù8õôò#ò/òb$ö"r   rá   c                   ó2   ‡ — e Zd ZdZdd„Zdˆ fd„	Zd„ Zˆ xZS )Úhunspell_cmda  
    Hunspell backend, using the "hunspell" command.

    Doctests:
    # known word
    >>> sp = hunspell_cmd(["en_US"])
    >>> sp.query("test")
    []

    # unknown word
    >>> sp = hunspell_cmd(["en_US"])
    >>> sp.query("jdaskljasd")  # doctest: +ELLIPSIS
    [[...
    c                 óX   — t         j                  | |«       |r| j                  |«       y y r   ©re   r   r"   ri   s     r   r   zhunspell_cmd.__init__g  ó&   € Ü×Ñ˜4 Ô*ÙØ�J‰J�xÕ ð r   c           	      óº  •— t         t        | �  |«       g d¢}|r|ddj                  |«      gz  }	 t	        j
                  |t        j                  t        j                  d¬«      | _        | j                  j                  j                  «        y # t        $ r@}t        j                  t        ddj                  |«      |«      «       d | _        Y d }~y d }~ww xY w)N)r   ú-az-irt   z-dú,T©r~   r�   Ú	close_fdsúFailed to execute '{}', {}ú )r�   rë   r"   r»   Ú
subprocessÚPopenÚPIPErh   r�   r‚   ÚOSErrorr#   r£   Ú_format©r   r&   Úargsr¦   r§   s       €r   r"   zhunspell_cmd.startl  s®   ø€ ÜŒl˜DÑ'¨Ô1â0ˆÙØ�T˜3Ÿ8™8 HÓ-Ð.Ñ.ˆDð		Ü ×&Ñ& tÜ-7¯_©_Ü.8¯o©oØ15ô7ˆDŒGð �G‰G�N‰N×#Ñ#Õ%øÜò 	Ü�M‰Mœ'Ð">ØŸH™H T›N¨Aó/ô 0àˆD�G‰Gûð	úó   ²AB Â	CÂ6CÃCc           	      óx  — g }ddg}	 t        j                  |t         j                  t         j                  t         j                  d¬«      }|j                  d«      \  }}d}|j	                  d«      j                  d«      D ]n  }|rVd	|vr |S t        j                  j                  |«      }|j                  «       j                  d
«      s|j                  |«       |j                  d«      sŒmd}Œp 	 |S # t        $ r:}	t        j                  t        ddj!                  |«      |	«      «       Y d}	~	|S d}	~	ww xY w)z„
        Return raw supported dictionary ids.
        They may not all be valid language ids, e.g. en-GB for myspell dicts.
        r   z-DT)r~   r�   Ústderrró   r1   Frt   rs   ú/r·   zAVAILABLE DICTIONARIESrô   rõ   N)rö   r÷   rø   Úcommunicaterƒ   r…   r¹   rº   rÀ   rÁ   rÂ   r,   rù   r#   r£   rú   r»   )
r   r&   rü   ÚpÚoutÚerrÚin_dictsr‰   r=   r¦   s
             r   r4   z#hunspell_cmd.get_supported_dict_ids~  s"  € ð
 ˆØ˜DÐ!ˆð	0Ü× Ñ  Ü'1§¡Ü(2¯©Ü(2¯©Ø+/ô	1ˆAð
 —}‘} RÓ(‰HˆC�ð ˆHØŸ
™
 7Ó+×1Ñ1°$Ó7ò $�ÙØ $™;Øð ˆô !Ÿg™g×.Ñ.¨tÓ4�GØ"Ÿ=™=›?×5Ñ5°fÔ=Ø Ÿ™¨Ô0à—?‘?Ð#;Õ<Ø#‘Hñ$ð  ˆøô ò 	0Ü�M‰Mœ'Ð">ØŸH™H T›N¨Aó/÷ 0ð 0àˆûð	0ús%   ˆBC6 ÂA C6 Ã/C6 Ã6	D9Ã?/D4Ä4D9r   ©ra   rb   rc   r˜   r   r"   r4   rÞ   rß   s   @r   rë   rë   X  s   ø„ ñó!õ
ö$"r   rë   c                   ó2   ‡ — e Zd ZdZdd„Zdˆ fd„	Zd„ Zˆ xZS )r   zò
    Aspell backend.

    Doctests:
    # known word
    >>> sp = aspell_cmd(["en_US"])
    >>> sp.query("test")
    []

    # unknown word
    >>> sp = aspell_cmd(["en_US"])
    >>> sp.query("jdaskljasd")  # doctest: +ELLIPSIS
    [[...
    c                 óX   — t         j                  | |«       |r| j                  |«       y y r   rí   ri   s     r   r   zaspell_cmd.__init__²  rî   r   c           	      óº  •— t         t        | �  |«       ddg}|r|ddj                  |«      gz  }	 t	        j
                  |t        j                  t        j                  d¬«      | _        | j                  j                  j                  «        y # t        $ r@}t        j                  t        ddj                  |«      |«      «       d | _        Y d }~y d }~ww xY w)	NÚaspellrð   z-lrñ   Trò   rô   rõ   )r�   r   r"   r»   rö   r÷   rø   rh   r�   r‚   rù   r#   r£   rú   rû   s       €r   r"   zaspell_cmd.start·  s³   ø€ ÜŒj˜$Ñ% hÔ/à˜$ÐˆÙØ�T˜3Ÿ8™8 HÓ-Ð.Ñ.ˆDð		Ü ×&Ñ& tÜ-7¯_©_Ü.8¯o©oØ15ô7ˆDŒGð �G‰G�N‰N×#Ñ#Õ%øÜò 	Ü�M‰Mœ'Ð">ØŸH™H T›N¨Aó/ô 0àˆD�G‰Gûð	úrý   c           	      ó0  — g }g d¢}	 t        j                  |«      j                  d«      j                  d«      }|D �cg c]  }|sŒ|‘Œ	 c}S # t        $ r9}t
        j                  t        ddj                  |«      |«      «       Y d}~ŒPd}~ww xY wc c}w )r’   )r
  Údumpr   rt   rs   rô   rõ   N)	rö   Úcheck_outputrƒ   r…   rù   r#   r£   rú   r»   )r   r&   rü   r¦   r/   s        r   r4   z!aspell_cmd.get_supported_dict_idsÉ  sŠ   € ð ˆÚ*ˆð	0Ü!×.Ñ.¨tÓ4ß!'¡¨£·±°t³ð ð
 &Ö,�rª’Ò,Ð,øô ò 	0Ü�M‰Mœ'Ð">ØŸH™H T›N¨Aó/÷ 0ñ 0ûð	0üò -s"   ˆ3A ¿BÁBÁ	BÁ/BÂBr   r  rß   s   @r   r   r   £  s   ø„ ñó!õ
ö$-r   r   )Ú
__future__r   r   r   r¹   rö   rY   rÙ   r¾   ÚOnboard.utilsr   ÚOnboard.oskrŸ   ÚloggingÚ	getLoggerra   r#   Úobjectr   re   r   rá   rë   r   rM   r   r   ú<module>r     s�   ð÷* BÑ Aã 	Û Û Û 	Û å %å ã Ø
ˆ'×
Ñ
˜HÓ
%€ôZ6�6ô Z6ôzP"�ô P"ôfqˆyô qôhL"�Iô L"ô^H�=ô HôV2-�õ 2-r   