From 85e0448d6d4994a21309a55be13a0a58e84ea761 Mon Sep 17 00:00:00 2001 From: Papoteur Date: Sat, 31 Oct 2015 19:53:25 +0100 Subject: Some updates in binrepo.py, about reading files. #mga17023 --- MgaRepo/binrepo.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'MgaRepo/binrepo.py') diff --git a/MgaRepo/binrepo.py b/MgaRepo/binrepo.py index f3aac47..f14de52 100644 --- a/MgaRepo/binrepo.py +++ b/MgaRepo/binrepo.py @@ -13,6 +13,7 @@ import hashlib import urllib.parse import threading import httplib2 + from io import StringIO SOURCES_FILE = "sha1.lst" @@ -34,7 +35,8 @@ def is_binary(path): st = os.stat(path) if st[stat.ST_SIZE] >= maxsize: return True - if open(path).read(0x10000).find('\0') >= 0: + fd = open(path, 'rb') + if b'\0' in bytes(fd.read(0x10000)): return True return False @@ -139,8 +141,8 @@ def parse_sources(path): def file_hash(path): sum = hashlib.sha1() - f = open(path) - while True: + with open(path, 'rb') as f: + while True: block = f.read(4096) if not block: break -- cgit v1.2.1