Skip to content

Commit

Permalink
Merge pull request #19 from xenserver-next/use-hashlib.md5-skip-Zipfi…
Browse files Browse the repository at this point in the history
…le-patch-for-3.7+

Use hashlib.md5 and skip monkeypatching ZipFile for 3.7+
  • Loading branch information
bernhardkaindl authored Nov 7, 2023
2 parents 93600d4 + 00ff7a9 commit 3496f35
Showing 1 changed file with 10 additions and 16 deletions.
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

0 comments on commit 3496f35

Please sign in to comment.