%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/share/ibus-table/engine/__pycache__/
Upload File :
Create Path :
Current File : //usr/share/ibus-table/engine/__pycache__/tabcreatedb.cpython-312.pyc

�

��Xe�K����dZddlmZddlmZddlmZddlmZddlmZddlZddlZddl	Z	ddl
Z
ddlZejjejjejje���ddlZdZd	ed
efd�ZGd�d
e�Zd
efd�Ze�Zej4r�ej6sed�ej:d�ejj=ej6�r%ejj?ej6�s'edej6z�ej:d�ej6sKej@r?ejjCej@�jEd�ddze_ej6sed�ej:d�Gd�d�Z#dd�Z$e%dk(re$�yy)z;
Program to create sqlite databases from the table sources
�)�Tuple)�List)�Iterable)�Dict)�AnyNz 	
"$&<>,+=#!()'|{}[]?~`;%\�keyname�returnc�(�td�|D��S)a
    Keynames must be ascii, and must not contain any invalid characters

    >>> gconf_valid_keyname('nyannyan')
    True

    >>> gconf_valid_keyname('nyan nyan')
    False

    >>> gconf_valid_keyname('nyannyan[')
    False

    >>> gconf_valid_keyname('nyan	nyan')
    False
    c3�LK�|]}|tvxst|�dkD���y�w)�N)�_INVALID_KEYNAME_CHARS�ord)�.0�chars  �+/usr/share/ibus-table/engine/tabcreatedb.py�	<genexpr>z&gconf_valid_keyname.<locals>.<genexpr>:s.����(���1�1�D�S��Y��_�D�(�s�"$)�any)rs r�gconf_valid_keynamer*s#�� �(�&�(�(�(�(�c�8��eZdZdZdeddf�fd�Zdefd�Z�xZS)�InvalidTableNamez4
    Raised when an invalid table name is given
    �namer	Nc�0��t�|��||_y�N)�super�__init__�
table_name)�selfr�	__class__s  �rrzInvalidTableName.__init__As���
������rc�:�d|jzdtzzdzS)NzValue of NAME attribute (%s) zcannot contain any of %r zand must be all ascii)rr
)rs r�__str__zInvalidTableName.__str__Es*��/�$�/�/�A�-�0F�F�G�)�*�	+r)�__name__�
__module__�__qualname__�__doc__�strrr!�
__classcell__)rs@rrr=s'�����S��T��+��+rrc��tj�}|jdddddd��|jdd	dd
dd��|jdd
dddd��|jdddddd��|jdddddd��|jdddddd��|jd d!d"d#d$d%��|jd&d'd"d(d$d)��|j�S)*z Parse the command line argumentsz-nz--name�storer�u#Specifies the file name for the binary database for the IME. The default is “%(default)s”. If the file name of the database is not specified, the file name of the source file before the first “.” will be appended with “.db” and that will be used as the file name of the database.)�action�dest�default�helpz-sz--source�sourceuZSpecifies the file which contains the source of the IME. The default is “%(default)s”.z-ez--extra�extrauZSpecifies the file name for the extra words for the IME. The default is “%(default)s”.z-pz--pinyin�pinyinz//usr/share/ibus-table/data/pinyin_table.txt.bz2uLSpecifies the source file for the  pinyin. The default is “%(default)s”.z-gz--suggestion�
suggestionz)/usr/share/ibus-table/data/phrase.txt.bz2uYSpecifies the source file for the suggestion candidate. The default is “%(default)s”.z-oz--no-create-index�store_false�indexTu�Do not create an index for a database (Only for distribution purposes, a normal user should not use this flag!). The default is “%(default)s”.z-iz--create-index-only�
store_true�
only_indexFu�Only create an index for an existing database. Specifying the file name of the binary database with the -n or --name option is required when this option is used.The default is “%(default)s”.z-dz--debug�debugu=Print extra debug messages. The default is “%(default)s”.)�argparse�ArgumentParser�add_argument�
parse_args)�parsers rr;r;Jsa��
�
$�
$�
&�F�
����h��
��7��	9�����j��
��2��4�����i��
��2��4�����j��
�A�2��4�����n��
�;�2��4�����!��
��2��4�����#��
��2��	4�����i��
��2��4�����rzM
Please specify the file name of the database you want to create an index on!�z'
The database file '%s' does not exist.�.z.dbzC
You need to specify the file which contains the source of the IME!c�^�eZdZUdZeed<eed<eed<eed<dededefd�Zdedefd	�Z	y
)�Sectionz[Helper class for parsing the sections of the tables marked
    with BEGIN_* and END_*.
    �patt�start�end�
in_sectionc�t�||_|j�|_|j�|_d|_y)NF)rA�striprBrCrD)rrArBrCs    rrzSection.__init__�s*����	��[�[�]��
��9�9�;�����r�liner	c���|jrB|j|j�k(rd|_y|jj	|�ryy|j
|j�k(rd|_y)zp
        Returns True if the line is inside the section and matches
        the pattern of the section.
        FT)rDrCrFrA�matchrB)rrGs  rrIz
Section.match�sa��
�?�?��x�x�4�:�:�<�'�"'����������&����Z�Z�4�:�:�<�
'�"�D�O�rN)
r"r#r$r%r�__annotations__r&�boolrrI�rrr@r@�sK����I��J�	�H��� �S� �� �3� �
�#�
�$�
rr@c	��&�dtddfd�}tjs$	tjtj
�|d�tjtj
dd���&d	ttdtttttttffd
�}d	ttdttfd�}d	ttdttfd�}d	ttdttfd
�}d	ttdtttttffd�}d	ttdttttffd�}d	ttdttttttffd�}d	ttdttttffd�}d	ttdttttffd�}	d	ttdttttttff�&fd�}
d	ttdtttffd�}tjrB|d�|d��&j�|d��&jd�|d�y|dtjz�t!j"d�}|j%tj�}
|
r5t'j(tjdd��j+�}n*t)tjdd��j+�}|j-d d!�}|j/d!�}|d"�||�\}}}|d#�t1|	|��}|j3||��|d$��&j5|��&j7d�|d%�||�}|d&��&j9|��&j:j=d'�j?�d(k(r)|d)�||�}|d*��&jA|��&j:j=d+�j?�d(k(r�|d,tjBz�|j%tjB�}|r't'j(tjBdd��}nt)tjBdd��}|d-�||�}|d.�||�}|d/��&jE|��&j:j=d0�j?�d(k(r�|d1tjFz�|j%tjF�}|r't'j(tjFdd��}nt)tjFdd��}|d2�||�}|d3�||�}|d4��&jI|�|d��&j��&j:j=d'�j?�d(k(�r�tjJ�r�|d5��&jd�|d6tjJz�|j%tjJ�}|r't'j(tjJdd��}nt)tjJd�}|d7�||�}|d8�|
|�}|d9tM|�z�i} |D] }!| jO|!d:�d;|!d<��|!i��"|d=tM| �z�i}"|D] }#|"jO|#d:�d;|#d<��|#i��"|d>tM|"�z�|"D]}$|$| vs�|"jQ|$��|d?tM|"�z�t1|"jS��}%|d@��&j9|%�|d��&j�tjTr|d��&jd�n|dA��&jWd�|d�y#t$rY��AwxYw)BzMain program�messager	Nc�<�tjrt|�yyr)�_ARGSr7�print)rNs r�debug_printzmain.<locals>.debug_print�s���;�;��'�N�rzProcessing Databaser*T)�filename�user_db�create_database�fc�*�g}g}g}g}tjd�}tjd�}tjd�}tjd�}tjd�}	t|dd�}
t|dd	�}t|d
d�}t|	dd
�}
|D]`}|j|�r�|j|�r�'||f||f|
|f|
|ffD])\}}|j|�s�|j	|��`�b|s�i}|D]�}|j|�}|s�t|j
d��dk(s�5|j
d�|vr]t|j
d��t||j
d��kDs��|j
d�||j
d�<��|j
d�||j
d�<��|D]}|j	|�d||����|j�||z
}|||fS)N�^###.*�^[ \t]*$z
[^\t]*=[^\t]*z$([^\t]+)\t([^\t]+)\t([0-9]+)(\t.*)?$z *[^\s]+ *\t *[^\s]+ *$�BEGIN_DEFINITION�END_DEFINITION�BEGIN_TABLE�	END_TABLE�BEGIN_TABLE_EXTRA�END_TABLE_EXTRA�BEGIN_GOUCI�	END_GOUCIr=��	)�re�compiler@rI�append�len�group�sort)rV�_attri�_table�_table_extra�_gouci�patt_com�
patt_blank�	patt_conf�
patt_table�
patt_gouci�sec_conf�	sec_table�sec_table_extra�	sec_goucirG�_sec�_list�
gouci_dict�res�keys                    r�parse_sourcezmain.<locals>.parse_source�s������"$�����:�:�i�(���Z�Z��,�
��J�J�/�0�	��Z�Z� G�H�
��Z�Z� :�;�
���)�+;�=����
�{�4�	�!��+�->�@����
�{�4�	��		�D��N�N�4�(�:�3C�3C�D�3I�"�F�+�(�,�7�"�F�+�!�6�*�	$,��K�D�%�
�z�z�$�'����T�*���		��(*,�J��
@�� �&�&�t�,���3�s�y�y��|�,��1��y�y��|�z�1��s�y�y��|�,�s�:�c�i�i��l�3K�/L�L�7:�y�y��|�J�s�y�y��|�4�36�9�9�Q�<�
�3�9�9�Q�<�0�
@�"�
@���
�
��j��o�>�?�
@��K�K�M��,������'�'rc���g}tjd�}tjd�}tjd�}tjd�}|D]�}|j|�r�|j|�r�'|j|�}|s�;|j|j	d��}|D]9}	|j|j	d��d|	�d|j	d�����;��|ddS)	N�^#.*rYz(.*)\t(.*)\t(.*)z[a-z]+[1-5]r=rbrc�)rdrerI�findallrhrf)
rV�_pinyinsrnro�patt_py�patt_yinrGrz�yins�yins
          r�parse_pinyinzmain.<locals>.parse_pinyins��� ���:�:�g�&���Z�Z��,�
��*�*�0�1���:�:�n�-���	E�D��N�N�4�(�:�3C�3C�D�3I��m�m�D�)���#�+�+�C�I�I�a�L�9�D�#�E�� ���#&�9�9�Q�<��c�i�i��l�)D�E�E�	E���{�rc�|�g}tjd�}tjd�}tjd�}|D]r}|j|�r�|j|�r�'|j|�}|s�;|jd�}|jd�}|j	|�d|����t|ddS)Nr~rYz(.*)\s+(.*)rbr=� )rdrerIrhrf)	rV�_suggestionsrnro�patt_sgrGrz�phrase�freqs	         r�parse_suggestionzmain.<locals>.parse_suggestion,s���"$���:�:�g�&���Z�Z��,�
��*�*�^�,���	B�D��N�N�4�(�:�3C�3C�D�3I��m�m�D�)��� �Y�Y�q�\�F��9�9�Q�<�D� �'�'�6�4�(@�A�
	B��A��rc�$�g}tjd�}tjd�}tjd�}|D]I}|j|�r�|j|�r�'|j|�s�9|j|��K|S)NrXrYz
(.*)\t(.*))rdrerIrf)rV�_extrarnro�
patt_extrarGs      r�parse_extrazmain.<locals>.parse_extra;sz�����:�:�i�(���Z�Z��,�
��Z�Z�
�.�
��	(�D��N�N�4�(�:�3C�3C�D�3I��#�#�D�)��M�M�$�'�	(�
�
rc3�~K�|D]4}|j�j�\}}}||t|�f���6y�wr�rF�split�int)rV�pinyin_line�_zi�_pinyin�_freqs     r�
pinyin_parserzmain.<locals>.pinyin_parserHsD�����	-�K�"-�"3�"3�"5�";�";�"=��C��%��C��U��,�,�	-�s�;=c3�zK�|D]2}|j�j�\}}|t|�f���4y�wrr�)rV�suggestion_line�_phraser�s    r�suggestion_parserzmain.<locals>.suggestion_parserMs?���� �	(�O�,�2�2�4�:�:�<�N�G�U��C��J�'�'�	(�s�9;c��g}|D]?}|jd�dd\}}}|dk(rd}|j||t|�df��A|S)Nrcr�NOSYMBOLr*r)r�rfr�)rV�phrase_listrG�xingmar�r�s      r�
phrase_parserzmain.<locals>.phrase_parserRsb��79���	?�D�#'�:�:�d�#3�B�Q�#7� �F�F�D���#���������D�	�1�=�>�		?�
�rc3�hK�|D])}|j�j�\}}||f���+y�wr)rFr�)rVrG�zi�gcms    r�goucima_parserzmain.<locals>.goucima_parser[s6�����	�D��j�j�l�(�(�*�G�B���s�)�O�	�s�02c3�*K�|D]Y}	|j�jd�\}}|j�j�}|j�}||f���[y#t$r%|j�jd�\}}Y�dwxYw�w)N�=z==)rFr��	Exception�lower)rVrG�attr�vals    r�attribute_parserzmain.<locals>.attribute_parser`s������	�D�
5� �J�J�L�.�.�s�3�	��c��:�:�<�%�%�'�D��)�)�+�C���+��	���
5� �J�J�L�.�.�t�4�	��c�
5�s'�B�"A"�7B�"+B�
B�B�Bc����g}|D]c}|j�j�\}}�j|�}|r|j||t	|�df��Vtd|z��e|S)Nru+No tabkeys found for “%s”, not adding.
)rFr��parse_phraserfr�rQ)rV�
extra_listrGr�r��_tabkey�dbs      �r�extra_parserzmain.<locals>.extra_parserjss���68�
��	N�D��:�:�<�-�-�/�L�F�D��o�o�f�-�G���!�!�7�F�C��I�q�"A�B��D�f�L�M�
	N��rc��i}d}|D]r}tjd|�rd}�|s�tjd|�rn>tjd|�}|s�P|jd�||jd�<�tdt	|�fS)	u�
        Returns something like

        ("char_prompts", "{'a': '日', 'b': '日', 'c': '金', ...}")

        i.e. the attribute name "char_prompts" and as its value
        the string representation of a Python dictionary.
        Fz^BEGIN_CHAR_PROMPTS_DEFINITIONTz^END_CHAR_PROMPTS_DEFINITIONz(^(?P<char>[^\s]+)[\s]+(?P<prompt>[^\s]+)�promptr�char_prompts)rdrI�searchrh�repr)rVr�rBrGrIs     r�get_char_promptszmain.<locals>.get_char_promptsus���(*�����	J�D��x�x�9�4�@�������x�x�7��>���I�I�;�T�C�E��49�K�K��4I��U�[�[��0�1�	J���\� 2�3�3rzOnly create IndexeszOptimizing database zCreate Indexes �mainzDone! :Dz	Load sources "%s"z.*\.bz2�rtzUTF-8)�mode�encoding�rz
�
z	Parsing table source file z	  get attribute of IME :)z	  add attributes into DB z	  get phrases of IME :)z	  add phrases into DB �user_can_define_phrase�truez	  get goucima of IME :)z	  add goucima into DB �pinyin_modez	Load pinyin source "%s"z	Parsing pinyin source file z	Preapring pinyin entriesz	  add pinyin into DB �suggestion_modez	Load suggestion source "%s"z 	Parsing suggestion source file z	Preapring suggestion entriesz%	  add suggestion candidates into DB z!	Preparing for adding extra wordsz	Load extra words source "%s"z!	Parsing extra words source file z	Preparing extra words linesz'	  we have %d extra phrases from sourcerrcrbz!	  the len of orig_phrases is: %dz"	  the len of extra_phrases is: %dz!	  %d extra phrases will be addedz	Adding extra words into DB zlWe do not create an index on the database, you should only activate this function for distribution purposes.),r&rPr6�os�unlinkrr��tabsqlitedb�TabSqliteDbrrrr��optimize_database�create_indexesr/rdrerI�bz2�open�read�replacer��listrf�
update_ime�
create_tables�add_phrases�ime_properties�getr��add_goucimar1�
add_pinyinr2�add_suggestionr0rg�update�pop�valuesr4�drop_indexes)'rRr|r�r�r�r�r�r�r�r�r�r��patt_s�_bz2s�
source_strr/�attri�table�gouci�
attributes�phrases�goucima�_bz2p�pinyin_s�pyliner1�suggestion_s�sgline�suggestions�extra_s�	extraline�
extrawords�orig_phrasesr��
extra_phrases�	extraword�extra_phrase�new_phrasesr�s'                                      @rr�r��s`����S��T�����	��I�I�e�j�j�!��%�&�	�	 �	 �%�*�*�)+�15�
7�B�B(���}�B(�!&�t�C�y�$�s�)�T�#�Y�'F�!G�B(�H���
��$�s�)��"
�H�S�M�
�d�3�i�
��x��}���c���-��#��-�8�E�#�s�C�-�4H�+I�-�
(�X�c�]�(�x��c�3�h��/H�(�
��#���4��c�3��S�6H�0I�+J���(�3�-��H�U�3��8�_�,E��
�H�S�M��h�u�S�#�X��.G��	���
�	�$�u�S�#�s�C�5G�/H�*I�	�4�H�S�M�4�e�C��H�o�4�2
����)�*��*�+�
�����%�&�
���&�!��J����%����4�5�
�Z�Z�
�
#�F��L�L����&�E���X�X��L�L�t�g�7�7;�t�v�	��%�,�,�S�7�C�H�H�J�
��#�#�F�D�1�J�
�
�
�d�
#�F��.�/�&�v�.��E�5�%��-�.��&�u�-�.�J����&�v�.�/��-�.��M�M�*�����V���+�,��E�"�G��*�+��N�N�7��	�����5�6�<�<�>�'�I��/�0� ��'���.�/�
���w��	�����]�+�1�1�3�w�>��1�E�L�L�@�A����U�\�\�*����x�x����4�'�J�H��E�L�L�s�W�E�H��3�4��h�'���0�1��v�&���-�.�
�
�
�f��	�����.�/�5�5�7�7�B��5��8H�8H�H�I����U�-�-�.����8�8�� � �t�g�?�L� �� � �s�W�>�L��7�8�!�,�/���4�5�'��/���<�=�
���+�&��&�'�����
�����6�7�=�=�?�7�J�����8�9�
���&�!��4�u�{�{�B�C����U�[�[�)����h�h�u�{�{���H�G��5�;�;��,�G��8�9���(�	��3�4�!�)�,�
��>��*�o�&�	'����	M�F����V�A�Y��q�	�!B�F� K�L�	M��8�3�|�;L�L�M��
�#�	F�I�� � �&�q�\�9�Q�<�8�)�D�
F�	F�	�9�C�
�<N�N�O�)�	0�L��|�+��!�!�,�/�	0�	�8�3�}�;M�M�N��=�/�/�1�2���3�4�
���{�#��*�+�
�����{�{��%�&�
���&�!��1�	2�	������
���y	�	��	�s�#a7�7	b�b�__main__)r	N)&r%�typingrrrrrr��sysr�rdr8�pathrf�dirname�abspath�__file__r�r
r&rKrr�rr;rPr6rrQ�exit�exists�isfiler/�basenamer�r@r�r"rLrr�<module>r�s���.������	�
�
�	������������������ 9�:�;��<��(��(��(�&+�y�+�C�C�C�J	�������:�:�
�0�	1�������
�7�7�>�>�%�*�*�%�R�W�W�^�^�E�J�J�-G�
�8�5�:�:�E�F��������z�z�e�l�l����!�!�%�,�,�/�5�5�c�:�1�=��E�E�J��z�z�	�,�-��C�H�H�Q�K���DF�P
�z���F�r

Zerion Mini Shell 1.0