def run(self):
		try:
			size = -1
			read = self.size()

			request = Request(self.url)
			if read > 0:
				request.add_header('range', 'bytes=' + str(read) + '-')
			response = urlopen(request)
			headers = response.info()

			if read > 0 and 'Content-Range' in headers:
				ranges = headers['Content-Range']
				size = int(ranges.split('/')[-1].strip())
				self.open('ab')
			else:
				if 'Content-Length' in headers:
					size = int(headers['Content-Length'])
				self.open('wb')

			with self.file:
				bs = 1024 * 8
				lock = Lock()
				self.onstart.emit()
				while True:
					lock.acquire()
					block = response.read(bs)
					if not block or self.file.closed:
						break
					read += len(block)
					self.file.write(block)
					self.onprogress.emit(read, size)
					lock.release()
				self.file.close()
				self.onfinish.emit(read)

		except __HOLE__ as error:
			self.onerror.emit(error.code, error.msg)
		except URLError as error:
			self.onerror.emit(error.reason.errno, error.reason.strerror)
		except Exception as error:
			self.onerror.emit(-1, str(error))
dataset/ETHPy150Open Lanfei/hae/src/downloader.py/Downloader.run