!7 清除python2残留并修复python3 Bug
From: @xiyuanwang Reviewed-by: @small_leek Signed-off-by: @small_leek
This commit is contained in:
commit
eff65e0eb8
70
0004-Work-around-short-read-race.patch
Normal file
70
0004-Work-around-short-read-race.patch
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
From 2db224de33b69718add29fa06904043b231efa44 Mon Sep 17 00:00:00 2001
|
||||||
|
From: wangxiyuan <wangxiyuan1007@gmail.com>
|
||||||
|
Date: Mon, 22 Feb 2021 16:14:11 +0800
|
||||||
|
Subject: [PATCH] Work around 'short read' race
|
||||||
|
|
||||||
|
Backport python3 fix
|
||||||
|
---
|
||||||
|
python/subunit/v2.py | 35 +++++++++++++++++++++--------------
|
||||||
|
1 file changed, 21 insertions(+), 14 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/python/subunit/v2.py b/python/subunit/v2.py
|
||||||
|
index be2049d..e44dc05 100644
|
||||||
|
--- a/python/subunit/v2.py
|
||||||
|
+++ b/python/subunit/v2.py
|
||||||
|
@@ -71,6 +71,22 @@ def has_nul(buffer_or_bytes):
|
||||||
|
else:
|
||||||
|
return NUL_ELEMENT in buffer_or_bytes
|
||||||
|
|
||||||
|
+def read_exactly(stream, size):
|
||||||
|
+ """Read exactly size bytes from stream.
|
||||||
|
+ :param stream: A file like object to read bytes from. Must support
|
||||||
|
+ read(<count>) and return bytes.
|
||||||
|
+ :param size: The number of bytes to retrieve.
|
||||||
|
+ """
|
||||||
|
+ data = b''
|
||||||
|
+ remaining = size
|
||||||
|
+ while remaining:
|
||||||
|
+ read = stream.read(remaining)
|
||||||
|
+ if len(read) == 0:
|
||||||
|
+ raise ParseError('Short read - got %d bytes, wanted %d bytes' % (
|
||||||
|
+ len(data), size))
|
||||||
|
+ data += read
|
||||||
|
+ remaining -= len(read)
|
||||||
|
+ return data
|
||||||
|
|
||||||
|
class ParseError(Exception):
|
||||||
|
"""Used to pass error messages within the parser."""
|
||||||
|
@@ -404,19 +420,11 @@ class ByteStreamToStreamResult(object):
|
||||||
|
|
||||||
|
def _parse(self, packet, result):
|
||||||
|
# 2 bytes flags, at most 3 bytes length.
|
||||||
|
- packet.append(self.source.read(5))
|
||||||
|
- if len(packet[-1]) != 5:
|
||||||
|
- raise ParseError(
|
||||||
|
- 'Short read - got %d bytes, wanted 5' % len(packet[-1]))
|
||||||
|
- flag_bytes = packet[-1][:2]
|
||||||
|
- flags = struct.unpack(FMT_16, flag_bytes)[0]
|
||||||
|
- length, consumed = self._parse_varint(
|
||||||
|
- packet[-1], 2, max_3_bytes=True)
|
||||||
|
- remainder = self.source.read(length - 6)
|
||||||
|
- if len(remainder) != length - 6:
|
||||||
|
- raise ParseError(
|
||||||
|
- 'Short read - got %d bytes, wanted %d bytes' % (
|
||||||
|
- len(remainder), length - 6))
|
||||||
|
+ header = read_exactly(self.source, 5)
|
||||||
|
+ packet.append(header)
|
||||||
|
+ flags = struct.unpack(FMT_16, header[:2])[0]
|
||||||
|
+ length, consumed = self._parse_varint(header, 2, max_3_bytes=True)
|
||||||
|
+ remainder = read_exactly(self.source, length - 6)
|
||||||
|
if consumed != 3:
|
||||||
|
# Avoid having to parse torn values
|
||||||
|
packet[-1] += remainder
|
||||||
|
@@ -515,4 +523,3 @@ class ByteStreamToStreamResult(object):
|
||||||
|
return utf8, length+pos
|
||||||
|
except UnicodeDecodeError:
|
||||||
|
raise ParseError('UTF8 string at offset %d is not UTF8' % (pos-2,))
|
||||||
|
-
|
||||||
|
--
|
||||||
|
2.23.0.windows.1
|
||||||
|
|
||||||
13
subunit.spec
13
subunit.spec
@ -1,6 +1,6 @@
|
|||||||
Name: subunit
|
Name: subunit
|
||||||
Version: 1.3.0
|
Version: 1.3.0
|
||||||
Release: 14
|
Release: 15
|
||||||
Summary: C bindings for subunit
|
Summary: C bindings for subunit
|
||||||
License: ASL 2.0 or BSD
|
License: ASL 2.0 or BSD
|
||||||
URL: https://launchpad.net/subunit
|
URL: https://launchpad.net/subunit
|
||||||
@ -10,6 +10,7 @@ Patch1: %{name}-decode-binary-to-unicode.patch
|
|||||||
Patch2: 0001-Migrate-Gtk-interface-to-GObject-introspection.patch
|
Patch2: 0001-Migrate-Gtk-interface-to-GObject-introspection.patch
|
||||||
Patch3: 0002-Fix-file-open-for-python3.patch
|
Patch3: 0002-Fix-file-open-for-python3.patch
|
||||||
Patch4: 0003-port-to-python-iso8601-0.1.12.patch
|
Patch4: 0003-port-to-python-iso8601-0.1.12.patch
|
||||||
|
Patch5: 0004-Work-around-short-read-race.patch
|
||||||
BuildRequires: check-devel cppunit-devel gcc-c++ libtool perl-generators
|
BuildRequires: check-devel cppunit-devel gcc-c++ libtool perl-generators
|
||||||
BuildRequires: perl(ExtUtils::MakeMaker) pkgconfig
|
BuildRequires: perl(ExtUtils::MakeMaker) pkgconfig
|
||||||
BuildRequires: python3-devel python3-docutils python3-extras python3-fixtures python3-iso8601
|
BuildRequires: python3-devel python3-docutils python3-extras python3-fixtures python3-iso8601
|
||||||
@ -84,8 +85,8 @@ Summary: Test code for the python 3 subunit bindings
|
|||||||
BuildArch: noarch
|
BuildArch: noarch
|
||||||
Requires: python3-%{name} = %{version}-%{release} %{name}-filters = %{version}-%{release}
|
Requires: python3-%{name} = %{version}-%{release} %{name}-filters = %{version}-%{release}
|
||||||
%{?python_provide:%python_provide python3-%{name}-test}
|
%{?python_provide:%python_provide python3-%{name}-test}
|
||||||
Obsoletes: python2-%{name}-test < 1.3.0-9
|
Obsoletes: python3-%{name}-test < 1.3.0-9
|
||||||
Provides: python2-%{name}-test = %{version}-%{release}
|
Provides: python3-%{name}-test = %{version}-%{release}
|
||||||
%description -n python3-%{name}-test
|
%description -n python3-%{name}-test
|
||||||
%{summary}.
|
%{summary}.
|
||||||
|
|
||||||
@ -111,6 +112,7 @@ test cases.
|
|||||||
%patch2 -p1
|
%patch2 -p1
|
||||||
%patch3 -p1
|
%patch3 -p1
|
||||||
%patch4 -p1
|
%patch4 -p1
|
||||||
|
%patch5 -p1
|
||||||
fixtimestamp() {
|
fixtimestamp() {
|
||||||
touch -r $1.orig $1
|
touch -r $1.orig $1
|
||||||
rm $1.orig
|
rm $1.orig
|
||||||
@ -174,7 +176,7 @@ for fil in iso8601.cpython-37.opt-1.pyc iso8601.cpython-37.pyc; do
|
|||||||
%{buildroot}%{python3_sitelib}/subunit/__pycache__/$fil
|
%{buildroot}%{python3_sitelib}/subunit/__pycache__/$fil
|
||||||
done
|
done
|
||||||
popd
|
popd
|
||||||
%make_install pkgpython_PYTHON='' INSTALL="%{_bindir}/install -p"
|
%make_install INSTALL="%{_bindir}/install -p"
|
||||||
mkdir -p %{buildroot}%{_sysconfdir}/profile.d
|
mkdir -p %{buildroot}%{_sysconfdir}/profile.d
|
||||||
cp -p shell/share/%{name}.sh %{buildroot}%{_sysconfdir}/profile.d
|
cp -p shell/share/%{name}.sh %{buildroot}%{_sysconfdir}/profile.d
|
||||||
rm -f %{buildroot}%{_libdir}/*.la
|
rm -f %{buildroot}%{_libdir}/*.la
|
||||||
@ -249,6 +251,9 @@ popd
|
|||||||
%exclude %{_bindir}/%{name}-diff
|
%exclude %{_bindir}/%{name}-diff
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Mon Feb 22 2021 wangxiyuan <wangxiyuan1007@gmail.com> - 1.3.0-15
|
||||||
|
- CleanUp python2 residual content and backport a python3 known issue.
|
||||||
|
|
||||||
* Wed Feb 03 2021 maminjie <maminjie1@huawei.com> - 1.3.0-14
|
* Wed Feb 03 2021 maminjie <maminjie1@huawei.com> - 1.3.0-14
|
||||||
- Port to python-iso8601 0.1.12
|
- Port to python-iso8601 0.1.12
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user