Mini Shell

Direktori : /usr/lib/python3.6/site-packages/enchant/__pycache__/
Upload File :
Current File : //usr/lib/python3.6/site-packages/enchant/__pycache__/utils.cpython-36.opt-1.pyc

3

��]0�#@s\dZddlZddlZddlZddlTyddlZWnek
rHdZYnXyeZWn,ek
r~e	Z	e	Ze
Z
e	e
fZeZYnXe	Z	eZe	Z
eZe
Zdd�Zdd�ZGdd	�d	e	�ZGd
d�de�Zddd�ZyeZWnek
r�dd�ZYnXyeZWnek
�reZYnXdd�Zd dd�Zd!dd�Zdge_dd�Zdd�Zdddge_dS)"a�

enchant.utils:    Misc utilities for the enchant package
========================================================

This module provides miscellaneous utilities for use with the
enchant spellchecking package.  Currently available functionality
includes:

    * string/unicode compatibility wrappers
    * functions for dealing with locale/language settings
    * ability to list supporting data files (win32 only)
    * functions for bundling supporting data files from a build

�N)�*cCs|jd�jd�S)uMake a unicode string from a raw string.

    This function takes a string containing unicode escape characters,
    and returns the corresponding unicode string.  Useful for writing
    unicode string literals in your python source while being upwards-
    compatible with Python 3.  For example, instead of doing this:

      s = u"helloⅉ"  # syntax error in Python 3

    Or this:

      s = "helloⅉ"   # not what you want in Python 2.x

    You can do this:

      s = raw_unicode(r"helloⅉ")  # works everywhere!

    �utf8zunicode-escape)�encode�decode)�raw�r�/usr/lib/python3.6/utils.py�raw_unicodeXsr	cCstj|�dS)z�Make a bytes object out of a raw string.

    This is analogous to raw_unicode, but processes byte escape characters
    to produce a bytes object.
    r)�codecs�
escape_decode)rrrr�	raw_bytesnsrc@s(eZdZdZdd�Zdd�Zdd�ZdS)	�
EnchantStra�String subclass for interfacing with enchant C library.

    This class encapsulates the logic for interfacing between python native
    string/unicode objects and the underlying enchant library, which expects
    all strings to be UTF-8 character arrays.  It is a subclass of the
    default string class 'str' - on Python 2.x that makes it an ascii string,
    on Python 3.x it is a unicode object.

    Initialise it with a string or unicode object, and use the encode() method
    to obtain an object suitable for passing to the underlying C library.
    When strings are read back into python, use decode(s) to translate them
    back into the appropriate python-level string type.

    This allows us to following the common Python 2.x idiom of returning
    unicode when unicode is passed in, and byte strings otherwise.  It also
    lets the interface be upwards-compatible with Python 3, in which string
    objects are unicode by default.
    cCsNt|�tkr$d}ttk	r8|jd�}nd}ttk	r8td��tj||�}||_|S)z�EnchantStr data constructor.

        This method records whether the initial string was unicode, then
        simply passes it along to the default string constructor.
        Tzutf-8Fz#Don't pass bytestrings to pyenchant)�type�unicode�strr�bytes�Error�__new__�_was_unicode)�cls�valueZwas_unicode�selfrrrr�szEnchantStr.__new__cCsttkrtj|d�S|SdS)z?Encode this string into a form usable by the enchant C library.zutf-8N)rrr)rrrrr�szEnchantStr.encodecCs>|jr6ttkr*t|t�r |j�}|jd�S|jd�Sn|SdS)z2Decode a string returned by the enchant C library.zutf-8N)rrr�
isinstancerr)rrrrrr�s

zEnchantStr.decodeN)�__name__�
__module__�__qualname__�__doc__rrrrrrrr
wsr
c@seZdZed�Zdd�ZdS)	�UTF16EnchantStr���csTttkr�}nt�ddd�}dj�fdd�|D��}ttkrFt|d�S|jd�SdS)z?Encode this string into a form usable by the enchant C library.r�replace)�errors�c3s$|]}t|�dkr|n�jVqdS)rrNi)�ord�REPLACEMENT_CHAR)�.0�c)rrr�	<genexpr>�sz)UTF16EnchantStr.encode.<locals>.<genexpr>N)rr�joinrr)rZ
unicode_charsZutf16_safe_stringr)rrr�s

zUTF16EnchantStr.encodeNii��)rrr�chrr%rrrrrr�sr� �
cCs2|dkrtj}|j|jtt|���|j|�dS)z�Compatibility wrapper from print statement/function.

    This function is a simple Python2/Python3 compatibility wrapper
    for printing to stdout.
    N)�sys�stdout�writer)�mapr)�values�sep�end�filerrr�printf�sr5cCs|j�S)z0Compatibility wrapper for advancing an iterator.)�next)�iterrrrr6�sr6cCs�t|�t|�krt||�S|s&t|�Stt|�d�}xvt|�D]j\}}|dg}xRt|�D]F\}}||dd}||d}	||||k}
|jt||	|
��q\W|}q@W|dS)zbCalculate the Levenshtein distance between two strings.

    This is straight from Wikipedia.
    ����)�len�levenshtein�xrange�	enumerate�append�min)�s1�s2Zprevious_row�iZc1Zcurrent_row�jZc2Z
insertionsZ	deletionsZ
substitutionsrrrr;�s

r;cs>�dkrt���fdd�|D�}|j�dd�|d|�D�S)aTrim a list of suggestions to a maximum length.

    If the list of suggested words is too long, you can use this function
    to trim it down to a maximum length.  It tries to keep the "best"
    suggestions based on similarity to the original word.

    If the optional "calcdist" argument is provided, it must be a callable
    taking two words and returning the distance between them.  It will be
    used to determine which words to retain in the list.  The default is
    a simple Levenshtein distance.
    Ncsg|]}��|�|f�qSrr)r&�s)�calcdist�wordrr�
<listcomp>sz$trim_suggestions.<locals>.<listcomp>cSsg|]\}}|�qSrr)r&�lrDrrrrGs)r;�sort)rFZsuggs�maxlenrEZ	decoratedr)rErFr�trim_suggestionss
rKcCsVy<ddl}|j�d}|dkr:|j�d}|dkr:td��|Stk
rPYnX|S)apDetermine the user's default language, if possible.

    This function uses the 'locale' module to try to determine
    the user's preferred language.  The return value is as
    follows:

        * if a locale is available for the LC_MESSAGES category,
          that language is used
        * if a default locale is available, that language is used
        * if the keyword argument <default> is given, it is used
        * if nothing else works, None is returned

    Note that determining the user's language is in general only
    possible if they have set the necessary environment variables
    on their system.
    rNzNo default language available)�localeZ	getlocaleZgetdefaultlocaler�	Exception)�defaultrL�tagrrr�get_default_languagesrPZLCcCs�tjjtjjt��}tjj||�}tjj|�r2|Sttd�r�tj	}t
|t�sZt|tj��}tjj|�}tjj||�}tjj|�r�|SnJddl
}y|jd|�}Wntk
r�YnXtjj|�}tjj|�r�|Std|f��dS)z�Get the absolute path to the named resource file.

    This serves widely the same purpose as pkg_resources.resource_filename(),
    but tries to avoid loading pkg_resources unless we're actually in
    an egg.
    �frozenrNZenchantzCould not locate resource '%s')�os�path�dirname�abspath�__file__r)�exists�hasattrr-�
executablerr�getfilesystemencoding�
pkg_resourcesZresource_filename�KeyErrorr)ZresnamerSZexe_path�exe_dirr[rrr�get_resource_filename3s*

r^cCs
ytd�}Wntk
r(td�}YnXtjj|�}d|gfg}xPtj|�D]B}|jd�rNx2dD]*}|j|�rb|d	d
jtjj	||��qbWqNWd}xl|D]d}g}tjj	|tjj
|��}x6tj|�D](}	tjj	||	�}
tjj|
�r�|j|
�q�W|j||f�q�W|S)a�Get list of supporting data files, for use with setup.py

    This function returns a list of the supporting data files available
    to the running version of PyEnchant.  This is in the format expected
    by the data_files argument of the distutils setup function.  It's
    very useful, for example, for including the data files in an executable
    produced by py2exe.

    Only really tested on the win32 platform (it's the only platform for
    which we ship our own supporting data files)
    zlibenchant.dllzlibenchant-1.dllr#z.dll�iconv�intl�libglib�
libgmodulerr8�share/enchant/myspell�share/enchant/ispell�lib/enchant)r_r`rarb)rcrdre)r^rrRrSrT�listdir�endswith�
startswithr>r)�normpath�isfile)Z
libEnchantZmainDirZ	dataFilesZdll�prefixZdataDirsZdataDir�filesZfullDir�fnZfullFnrrr�win32_data_filesSs*



$
rn�pyZexe)r+r,N)N)N)rr
rRr-Zenchant.errorsrL�ImportErrorr�	NameErrorrrZ
basestringr*Zunichrr	rr
rr5r6r<�ranger;rKrPZ_DOC_ERRORSr^rnrrrr�<module>,sR

	<



 $