home *** CD-ROM | disk | FTP | other *** search
/ Freelog 116 / FreelogNo116-JuilletSeptembre2013.iso / Bureautique / gImageReader / gimagereader_0.9-1_win32.exe / bin / enchant / _enchant.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2011-03-24  |  9KB  |  349 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.7)
  3.  
  4. '''
  5.  
  6.     enchant._enchant:  ctypes-based wrapper for enchant C library
  7.  
  8.     This module implements the low-level interface to the underlying
  9.     C library for enchant.  The interface is based on ctypes and tries 
  10.     to do as little as possible while making the higher-level components
  11.     easier to write.
  12.  
  13.     The following conveniences are provided that differ from the underlying
  14.     C API:
  15.  
  16.         * the "enchant" prefix has been removed from all functions, since
  17.           python has a proper module system
  18.         * callback functions do not take a user_data argument, since
  19.           python has proper closures that can manage this internally
  20.         * string lengths are not passed into functions such as dict_check,
  21.           since python strings know how long they are
  22.  
  23. '''
  24. import sys
  25. import os
  26. import os.path as os
  27. from ctypes import *
  28. from ctypes.util import find_library
  29. from enchant import utils
  30. from enchant.errors import *
  31. from enchant.utils import unicode
  32. e = None
  33.  
  34. def _e_path_possibilities():
  35.     '''Generator yielding possible locations of the enchant library.'''
  36.     yield os.environ.get('PYENCHANT_LIBRARY_PATH')
  37.     yield find_library('enchant')
  38.     yield find_library('libenchant')
  39.     yield find_library('libenchant-1')
  40.     if sys.platform == 'darwin':
  41.         yield '/opt/local/lib/libenchant.dylib'
  42.  
  43. if sys.platform == 'win32':
  44.     e_path = None
  45.     
  46.     try:
  47.         e_path = utils.get_resource_filename('libenchant.dll')
  48.     except (Error, ImportError):
  49.         
  50.         try:
  51.             e_path = utils.get_resource_filename('libenchant-1.dll')
  52.         except (Error, ImportError):
  53.             pass
  54.         
  55.  
  56.  
  57.     if e_path is not None:
  58.         if not isinstance(e_path, unicode):
  59.             e_path = unicode(e_path, sys.getfilesystemencoding())
  60.         LoadLibraryEx = windll.kernel32.LoadLibraryExW
  61.         LOAD_WITH_ALTERED_SEARCH_PATH = 8
  62.         e_handle = LoadLibraryEx(e_path, None, LOAD_WITH_ALTERED_SEARCH_PATH)
  63.         if not e_handle:
  64.             raise WinError()
  65.         e = CDLL(e_path, handle = e_handle)
  66.     
  67. if e is None and sys.platform == 'darwin':
  68.     
  69.     try:
  70.         e_path = utils.get_resource_filename('lib/libenchant.1.dylib')
  71.     except (Error, ImportError):
  72.         pass
  73.  
  74.     e = CDLL(e_path)
  75.     
  76.     try:
  77.         e_dir = os.path.dirname(os.path.dirname(e_path))
  78.         prefix_dir = POINTER(c_char_p).in_dll(e, 'enchant_prefix_dir_p')
  79.         prefix_dir.contents = c_char_p(e_dir)
  80.     except AttributeError:
  81.         e = None
  82.     
  83.  
  84. if e is None:
  85.     for e_path in _e_path_possibilities():
  86.         if e_path is not None:
  87.             
  88.             try:
  89.                 e = cdll.LoadLibrary(e_path)
  90.             except OSError:
  91.                 pass
  92.  
  93.             break
  94.             continue
  95. if e is None:
  96.     raise ImportError('enchant C library not found')
  97. t_broker_desc_func = CFUNCTYPE(None, c_char_p, c_char_p, c_char_p, c_void_p)
  98. t_dict_desc_func = CFUNCTYPE(None, c_char_p, c_char_p, c_char_p, c_char_p, c_void_p)
  99. t_broker = c_void_p
  100. t_dict = c_void_p
  101. broker_init = e.enchant_broker_init
  102. broker_init.argtypes = []
  103. broker_init.restype = t_broker
  104. broker_free = e.enchant_broker_free
  105. broker_free.argtypes = [
  106.     t_broker]
  107. broker_free.restype = None
  108. broker_request_dict = e.enchant_broker_request_dict
  109. broker_request_dict.argtypes = [
  110.     t_broker,
  111.     c_char_p]
  112. broker_request_dict.restype = t_dict
  113. broker_request_pwl_dict = e.enchant_broker_request_pwl_dict
  114. broker_request_pwl_dict.argtypes = [
  115.     t_broker,
  116.     c_char_p]
  117. broker_request_pwl_dict.restype = t_dict
  118. broker_free_dict = e.enchant_broker_free_dict
  119. broker_free_dict.argtypes = [
  120.     t_broker,
  121.     t_dict]
  122. broker_free_dict.restype = None
  123. broker_dict_exists = e.enchant_broker_dict_exists
  124. broker_dict_exists.argtypes = [
  125.     t_broker,
  126.     c_char_p]
  127. broker_free_dict.restype = c_int
  128. broker_set_ordering = e.enchant_broker_set_ordering
  129. broker_set_ordering.argtypes = [
  130.     t_broker,
  131.     c_char_p,
  132.     c_char_p]
  133. broker_set_ordering.restype = None
  134. broker_get_error = e.enchant_broker_get_error
  135. broker_get_error.argtypes = [
  136.     t_broker]
  137. broker_get_error.restype = c_char_p
  138. broker_describe1 = e.enchant_broker_describe
  139. broker_describe1.argtypes = [
  140.     t_broker,
  141.     t_broker_desc_func,
  142.     c_void_p]
  143. broker_describe1.restype = None
  144.  
  145. def broker_describe(broker, cbfunc):
  146.     
  147.     def cbfunc1(*args):
  148.         cbfunc(*args[:-1])
  149.  
  150.     broker_describe1(broker, t_broker_desc_func(cbfunc1), None)
  151.  
  152. broker_list_dicts1 = e.enchant_broker_list_dicts
  153. broker_list_dicts1.argtypes = [
  154.     t_broker,
  155.     t_dict_desc_func,
  156.     c_void_p]
  157. broker_list_dicts1.restype = None
  158.  
  159. def broker_list_dicts(broker, cbfunc):
  160.     
  161.     def cbfunc1(*args):
  162.         cbfunc(*args[:-1])
  163.  
  164.     broker_list_dicts1(broker, t_dict_desc_func(cbfunc1), None)
  165.  
  166.  
  167. try:
  168.     broker_get_param = e.enchant_broker_get_param
  169. except AttributeError:
  170.     
  171.     def broker_get_param(broker, param_name):
  172.         return e.enchant_broker_get_param(param_name)
  173.  
  174.  
  175. broker_get_param.argtypes = [
  176.     t_broker,
  177.     c_char_p]
  178. broker_get_param.restype = c_char_p
  179.  
  180. try:
  181.     broker_set_param = e.enchant_broker_set_param
  182. except AttributeError:
  183.     
  184.     def broker_set_param(broker, param_name):
  185.         return e.enchant_broker_set_param(param_name)
  186.  
  187.  
  188. broker_set_param.argtypes = [
  189.     t_broker,
  190.     c_char_p,
  191.     c_char_p]
  192. broker_set_param.restype = None
  193.  
  194. try:
  195.     get_version = e.enchant_get_version
  196. except AttributeError:
  197.     
  198.     def get_version():
  199.         return e.enchant_get_version()
  200.  
  201.  
  202. get_version.argtypes = []
  203. get_version.restype = c_char_p
  204. dict_check1 = e.enchant_dict_check
  205. dict_check1.argtypes = [
  206.     t_dict,
  207.     c_char_p,
  208.     c_size_t]
  209. dict_check1.restype = c_int
  210.  
  211. def dict_check(dict, word):
  212.     return dict_check1(dict, word, len(word))
  213.  
  214. dict_suggest1 = e.enchant_dict_suggest
  215. dict_suggest1.argtypes = [
  216.     t_dict,
  217.     c_char_p,
  218.     c_size_t,
  219.     POINTER(c_size_t)]
  220. dict_suggest1.restype = POINTER(c_char_p)
  221.  
  222. def dict_suggest(dict, word):
  223.     numSuggsP = pointer(c_size_t(0))
  224.     suggs_c = dict_suggest1(dict, word, len(word), numSuggsP)
  225.     suggs = []
  226.     n = 0
  227.     while n < numSuggsP.contents.value:
  228.         suggs.append(suggs_c[n])
  229.         n = n + 1
  230.     if numSuggsP.contents.value > 0:
  231.         dict_free_string_list(dict, suggs_c)
  232.     return suggs
  233.  
  234. dict_add1 = e.enchant_dict_add
  235. dict_add1.argtypes = [
  236.     t_dict,
  237.     c_char_p,
  238.     c_size_t]
  239. dict_add1.restype = None
  240.  
  241. def dict_add(dict, word):
  242.     return dict_add1(dict, word, len(word))
  243.  
  244. dict_add_to_pwl1 = e.enchant_dict_add
  245. dict_add_to_pwl1.argtypes = [
  246.     t_dict,
  247.     c_char_p,
  248.     c_size_t]
  249. dict_add_to_pwl1.restype = None
  250.  
  251. def dict_add_to_pwl(dict, word):
  252.     return dict_add_to_pwl1(dict, word, len(word))
  253.  
  254. dict_add_to_session1 = e.enchant_dict_add_to_session
  255. dict_add_to_session1.argtypes = [
  256.     t_dict,
  257.     c_char_p,
  258.     c_size_t]
  259. dict_add_to_session1.restype = None
  260.  
  261. def dict_add_to_session(dict, word):
  262.     return dict_add_to_session1(dict, word, len(word))
  263.  
  264. dict_remove1 = e.enchant_dict_remove
  265. dict_remove1.argtypes = [
  266.     t_dict,
  267.     c_char_p,
  268.     c_size_t]
  269. dict_remove1.restype = None
  270.  
  271. def dict_remove(dict, word):
  272.     return dict_remove1(dict, word, len(word))
  273.  
  274. dict_remove_from_session1 = e.enchant_dict_remove_from_session
  275. dict_remove_from_session1.argtypes = [
  276.     t_dict,
  277.     c_char_p,
  278.     c_size_t]
  279. dict_remove_from_session1.restype = c_int
  280.  
  281. def dict_remove_from_session(dict, word):
  282.     return dict_remove_from_session1(dict, word, len(word))
  283.  
  284. dict_is_added1 = e.enchant_dict_is_added
  285. dict_is_added1.argtypes = [
  286.     t_dict,
  287.     c_char_p,
  288.     c_size_t]
  289. dict_is_added1.restype = c_int
  290.  
  291. def dict_is_added(dict, word):
  292.     return dict_is_added1(dict, word, len(word))
  293.  
  294. dict_is_removed1 = e.enchant_dict_is_removed
  295. dict_is_removed1.argtypes = [
  296.     t_dict,
  297.     c_char_p,
  298.     c_size_t]
  299. dict_is_removed1.restype = c_int
  300.  
  301. def dict_is_removed(dict, word):
  302.     return dict_is_removed1(dict, word, len(word))
  303.  
  304. dict_is_in_session1 = e.enchant_dict_is_in_session
  305. dict_is_in_session1.argtypes = [
  306.     t_dict,
  307.     c_char_p,
  308.     c_size_t]
  309. dict_is_in_session1.restype = c_int
  310.  
  311. def dict_is_in_session(dict, word):
  312.     return dict_is_in_session1(dict, word, len(word))
  313.  
  314. dict_store_replacement1 = e.enchant_dict_store_replacement
  315. dict_store_replacement1.argtypes = [
  316.     t_dict,
  317.     c_char_p,
  318.     c_size_t,
  319.     c_char_p,
  320.     c_size_t]
  321. dict_store_replacement1.restype = None
  322.  
  323. def dict_store_replacement(dict, mis, cor):
  324.     return dict_store_replacement1(dict, mis, len(mis), cor, len(cor))
  325.  
  326. dict_free_string_list = e.enchant_dict_free_string_list
  327. dict_free_string_list.argtypes = [
  328.     t_dict,
  329.     POINTER(c_char_p)]
  330. dict_free_string_list.restype = None
  331. dict_get_error = e.enchant_dict_get_error
  332. dict_get_error.argtypes = [
  333.     t_dict]
  334. dict_get_error.restype = c_char_p
  335. dict_describe1 = e.enchant_dict_describe
  336. dict_describe1.argtypes = [
  337.     t_dict,
  338.     t_dict_desc_func,
  339.     c_void_p]
  340. dict_describe1.restype = None
  341.  
  342. def dict_describe(dict, cbfunc):
  343.     
  344.     def cbfunc1(*args):
  345.         cbfunc(*args[:-1])
  346.  
  347.     dict_describe1(dict, t_dict_desc_func(cbfunc1), None)
  348.  
  349.