Skip to content

Commit

Permalink
兼容Python2
Browse files Browse the repository at this point in the history
  • Loading branch information
hankcs committed Mar 19, 2018
1 parent 22d4c9d commit a1abbaa
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
17 changes: 10 additions & 7 deletions pyhanlp/static/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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


Expand All @@ -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:
Expand Down
7 changes: 0 additions & 7 deletions pyhanlp/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit a1abbaa

Please sign in to comment.