1- from __future__ import absolute_import , unicode_literals
2-
31import os
4- import sys
52
6- try :
7- import opencc_clib
8- except ImportError :
9- from opencc .clib import opencc_clib
3+ from opencc .clib import opencc_clib
104
11- __all__ = ['OpenCC ' , 'CONFIGS ' , '__version__' ]
5+ __all__ = ['CONFIGS ' , 'OpenCC ' , '__version__' ]
126
137__version__ = opencc_clib .__version__
148_this_dir = os .path .dirname (os .path .abspath (__file__ ))
159_opencc_share_dir = os .path .join (_this_dir , 'clib' , 'share' , 'opencc' )
16- _opencc_rootdir = os .path .abspath (os .path .join (_this_dir , '..' , '..' ))
10+ _opencc_rootdir = os .path .abspath (os .path .join (_this_dir , '..' , '..' ))
1711_opencc_configdir = os .path .join (_opencc_rootdir , 'data' , 'config' )
1812
19- if sys .version_info .major == 2 :
20- text_type = unicode # noqa
21- else :
22- text_type = str
23-
2413if os .path .isdir (_opencc_share_dir ):
2514 CONFIGS = [f for f in os .listdir (_opencc_share_dir ) if f .endswith ('.json' )]
2615elif os .path .isdir (_opencc_configdir ):
@@ -36,7 +25,7 @@ def _append_path_to_env(name: str, path: str) -> None:
3625 if value == '' :
3726 value = path
3827 else :
39- value += ':' + path
28+ value += f': { path } '
4029 os .environ [name ] = value
4130
4231
@@ -49,10 +38,9 @@ def __init__(self, config: str = 't2s') -> None:
4938 config_under_share_dir = os .path .join (_opencc_share_dir , config )
5039 if os .path .isfile (config_under_share_dir ):
5140 config = config_under_share_dir
52- super (OpenCC , self ).__init__ (config )
41+ super ().__init__ (config )
5342 self .config = config
5443
55- def convert (self , text ):
56- if isinstance (text , text_type ):
57- text = text .encode ('utf-8' )
58- return super (OpenCC , self ).convert (text , len (text ))
44+ def convert (self , text : str ):
45+ byte_text = text .encode ('utf-8' )
46+ return super ().convert (byte_text , len (byte_text ))
0 commit comments