Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use hashlib.md5 and skip monkeypatching ZipFile for 3.7+ #19

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 10 additions & 16 deletions xen-bugtool
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import traceback
import urllib
import xml
import zipfile
from hashlib import md5 as md5_new
from select import select
from signal import SIGHUP, SIGTERM, SIGUSR1
from subprocess import PIPE, Popen
Expand All @@ -64,25 +65,18 @@ from xml.etree.ElementTree import Element

import defusedxml.sax

try:
import hashlib
def md5_new():
return hashlib.md5()
except:
import md5
def md5_new():
return md5.new()

# Fixed in 3.7: https://github.com/python/cpython/pull/12628
# Monkey-patch zipfile's __del__ function to be less stupid
# Specifically, it calls close which further writes to the file, which
# fails with ENOSPC if the root filesystem is full
zipfile_del = zipfile.ZipFile.__del__
def exceptionless_del(*argl, **kwargs):
try:
zipfile_del(*argl, **kwargs)
except:
pass
zipfile.ZipFile.__del__ = exceptionless_del
if sys.version < "3.7":
zipfile_del = zipfile.ZipFile.__del__ # type: ignore[attr-defined] # mypy,pyright
def exceptionless_del(*argl, **kwargs):
try:
zipfile_del(*argl, **kwargs)
except OSError:
pass
zipfile.ZipFile.__del__ = exceptionless_del # type: ignore[attr-defined] # mypy,pyright

def xapi_local_session():
import XenAPI # Import on first use.
Expand Down