Mini Shell
3
��]0 � # @ s\ d Z ddlZddlZddlZddlT yddlZW n ek
rH dZY nX yeZW n, ek
r~ e Z e Ze
Z
e e
fZeZY nX e Z eZe Z
eZe
Zdd� Zdd� ZG dd � d e �ZG d
d� de�Zddd�ZyeZW n ek
r� dd� ZY nX yeZW n ek
�r eZY nX dd� 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)�*c C s | j d�jd�S )u Make 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_unicodeX s r c C s t j| �d S )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)r r r r � raw_bytesn s r c @ s( e Zd ZdZdd� 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.
c C sN t |�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�selfr r r r � s zEnchantStr.__new__c C s t tkrt j| d�S | S dS )z?Encode this string into a form usable by the enchant C library.zutf-8N)r r r )r r r r r � s zEnchantStr.encodec C s>