pull python-ox changes

This commit is contained in:
j 2014-10-04 21:08:57 +02:00
commit 7040fdd564
13 changed files with 75 additions and 57 deletions

View file

@ -5,7 +5,7 @@ from __future__ import with_statement, print_function
import os
import gzip
import re
from six import BytesIO
from six import BytesIO, PY3
import struct
from six.moves import urllib
@ -51,6 +51,8 @@ def open_url(url, data=None, headers=DEFAULT_HEADERS):
if isinstance(url, bytes):
url = url.decode('utf-8')
url = url.replace(' ', '%20')
if data and PY3 and not isinstance(data, bytes):
data = data.encode('utf-8')
req = urllib.request.Request(url, data, headers)
return urllib.request.urlopen(req)
@ -104,9 +106,8 @@ def save_url(url, filename, overwrite=False):
if not os.path.exists(dirname):
os.makedirs(dirname)
data = read_url(url)
f = open(filename, 'w')
f.write(data)
f.close()
with open(filename, 'wb') as f:
f.write(data)
def oshash(url):
def get_size(url):