1- from __future__ import absolute_import , unicode_literals
2-
31import os
4- import sys
52
63try :
7- import opencc_clib
4+ import opencc_clib
85except ImportError :
96 from opencc .clib import opencc_clib
107
11- __all__ = ['OpenCC ' , 'CONFIGS ' , '__version__' ]
8+ __all__ = ['CONFIGS ' , 'OpenCC ' , '__version__' ]
129
1310__version__ = opencc_clib .__version__
1411_this_dir = os .path .dirname (os .path .abspath (__file__ ))
1512_opencc_share_dir = os .path .join (_this_dir , 'clib' , 'share' , 'opencc' )
16- _opencc_rootdir = os .path .abspath (os .path .join (_this_dir , '..' , '..' ))
13+ _opencc_rootdir = os .path .abspath (os .path .join (_this_dir , '..' , '..' ))
1714_opencc_configdir = os .path .join (_opencc_rootdir , 'data' , 'config' )
1815
19- if sys .version_info .major == 2 :
20- text_type = unicode # noqa
21- else :
22- text_type = str
23-
2416if os .path .isdir (_opencc_share_dir ):
2517 CONFIGS = [f for f in os .listdir (_opencc_share_dir ) if f .endswith ('.json' )]
2618elif os .path .isdir (_opencc_configdir ):
@@ -36,7 +28,7 @@ def _append_path_to_env(name: str, path: str) -> None:
3628 if value == '' :
3729 value = path
3830 else :
39- value += ':' + path
31+ value += f': { path } '
4032 os .environ [name ] = value
4133
4234
@@ -49,10 +41,9 @@ def __init__(self, config: str = 't2s') -> None:
4941 config_under_share_dir = os .path .join (_opencc_share_dir , config )
5042 if os .path .isfile (config_under_share_dir ):
5143 config = config_under_share_dir
52- super (OpenCC , self ).__init__ (config )
44+ super ().__init__ (config )
5345 self .config = config
5446
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 ))
47+ def convert (self , text : str ):
48+ byte_text = text .encode ('utf-8' )
49+ return super ().convert (byte_text , len (byte_text ))
0 commit comments