Copyright © 2016 JoungKyun.Kim All rights reserved.
Notice
이 프로젝트는 GitHUB로 이동을 했습니다. 10초 후에 GitHUB 프로젝트 페이지로 이동 합니다.
Abstract
이 모듈은 PYPI의 python-chardet을 대체하기 위한 python 언어셋 탐지 모듈 입니다. 동일한 패키지 이름을 가지고 있기 때문에 착오 하지 마시기 바랍니다.
이 프로젝트는 순수한 python 코드로 작성된 python-chardet의 성능 향상을 위하여 C언어로 만들어 졌습니다. 또한, puthon-chardet과 동일한 Mozilla Universal Charset Detection 알고리즘을 사용하기 위하여 libchardet library를 사용 합니다.
Mozilla Universal Charset Detection 알고리즘은 Netscape, Mozilla, Firefox 등의 브라우저에서 언어셋을 탐지하기 위하여 사용하는 알고리즘 입니다.
이 모듈은 python-chardet을 대체하기 위하여 만들어졌기 때문에, python-chardet과 동일한 Namespace를 사용합니다. 이는 python-chardet과 같이 사용을 할 수 없음을 의미합니다.
또한, 2.0.0 부터는 python-chardet과 동일한 API를 지원하므로, 코드 변경 없이 모듈만 변경하는 것으로 성능 향상을 얻을 수 있습니다.
Repository http://svn.oops.org/wsvn/Python.chardet/trunk/
Required
libchardet library
Python 2.6 이상
Python 3.0 지원: 1.0.2 이상
Download
chardet-2.0.0.tar.bz2 Python 3 지원 - 2016.05.11
mod_chardet-1.0.2.tar.bz2 Python 3 지원 - 2016.05.07
mod_chardet-1.0.1.tar.bz2 - 2011.04.27
mod_chardet-1.0.0.tar.bz2 - 2010.08.09
package 자동화를 위하여 wget을 사용할 경우, wget의 기본 User-Agent를 사용하지 마십시오. "-U" 옵션을 사용하여 다른 User Agent를 지정 하십시오.
Samples
소스 코드의 tests 디렉토리에 있는 스크립트들을 참조 하십시오.
* 2.0.0 부터는 python-chardet의 API를 사용할 수 있기 때문에 python-chardet의 API 사용법을 참고 하실 수 있습니다.
* 1.x old style api
1.x를 사용하다가 2.x로 migration을 할 경우에는 코드 변경 없이 모듈 호출만 chardet 대신에 chardet_c로 변경 하시면 됩니다. 1.x의 API를 호환하기 위하여 chardet_c 모듈을 같이 지원 합니다.
#!/usr/bin/python # -*- coding: utf-8 -*- # for compatible python 3 from __future__ import print_function import os # for compatible python 3 try: import urllib from urllib.request import urlopen from urllib.error import HTTPError except ImportError: import urllib2 from urllib2 import urlopen, HTTPError import chardet_c print ("Python chardet c binding module version: %s" % (chardet.__version__)) print () url = r'https://raw.githubusercontent.com/BYVoid/uchardet/master/test/ar/windows-1256.txt' print ('** %s => ' % os.path.basename (url), end='') try : rawdata = urlopen (url).read () r = chardet_c.detector (rawdata) print (r) except HTTPError as e : print (e)
* 1.x old style api with handle
When use old style API, be careful importing with chardet_c instead of chardet
#!/usr/bin/python # -*- coding: utf-8 -*- # for compatible python 3 from __future__ import print_function import os # for compatible python 3 try: import urllib from urllib.request import urlopen from urllib.error import HTTPError except ImportError: import urllib2 from urllib2 import urlopen, HTTPError import chardet_c urlread = lambda url: urlopen (url).read () url = r'https://raw.githubusercontent.com/BYVoid/uchardet/master/test/ar/windows-1256.txt' print ('** %s => ' % os.path.basename (url), end='') ch = chardet_c.init (); try : det = chardet_c.detect (ch, urlread (url), err) if ( det == None ) : print ("Error: %s" % err) print ("encoding: %-15s, confidence: %.2f" % (det.encoding, det.confidence)) except HTTPError as e : print (e) chardet_c.destroy (ch);
Copyright & License
Copyright (c) 2016 JoungKyun.Kim <http://oops.org> All rights reserved. This program is under MPL 1.1 or LGPL 2.1