From a1abbaaf1136684293bf5ade4379f0eda58afaa1 Mon Sep 17 00:00:00 2001 From: hankcs Date: Mon, 19 Mar 2018 12:16:02 -0500 Subject: [PATCH] =?UTF-8?q?=E5=85=BC=E5=AE=B9Python2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyhanlp/static/__init__.py | 17 ++++++++++------- pyhanlp/util.py | 7 ------- setup.py | 2 +- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/pyhanlp/static/__init__.py b/pyhanlp/static/__init__.py index 47ee1b0..4cab587 100644 --- a/pyhanlp/static/__init__.py +++ b/pyhanlp/static/__init__.py @@ -1,8 +1,8 @@ # -*- coding:utf-8 -*- # Author:hankcs # Date: 2018-03-18 20:05 -from __future__ import print_function from __future__ import division +from __future__ import print_function import os import sys @@ -23,7 +23,10 @@ import re import zipfile from shutil import copyfile -from ..util import urllib +if PY == 3: + import urllib.request as urllib +else: + import urllib import time @@ -99,7 +102,7 @@ def hanlp_installed_data_version(): global HANLP_DATA_VERSION HANLP_DATA_VERSION = f.readlines()[0].strip() return HANLP_DATA_VERSION - except FileNotFoundError: + except: return None @@ -117,10 +120,10 @@ def hanlp_installed_data_path(): def download(url, path): - opener = urllib.build_opener() - opener.addheaders = [('User-agent', - 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.162 Safari/537.36')] - urllib.install_opener(opener) + # opener = urllib.build_opener() + # opener.addheaders = [('User-agent', + # 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.162 Safari/537.36')] + # urllib.install_opener(opener) print('Downloading {} to {}'.format(url, path)) tmp_path = '{}.downloading'.format(path) try: diff --git a/pyhanlp/util.py b/pyhanlp/util.py index feea1e4..de1eee9 100755 --- a/pyhanlp/util.py +++ b/pyhanlp/util.py @@ -48,13 +48,6 @@ except ImportError: import pickle as _pickle -if PY == 3: - import urllib.request as urllib - import urllib.parse as urlparse -else: - import urllib - import urlparse - try: from smart_open import smart_open except ImportError: diff --git a/setup.py b/setup.py index 39b405c..b588d6c 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ setup( name='pyhanlp', - version='0.1.4', + version='0.1.5', description='Python wrapper for HanLP: Han Language Processing', long_description=long_description, url='https://github.com/hankcs/pyhanlp',