diff --git a/file-5.30-python-utf8.patch b/file-5.30-python-utf8.patch new file mode 100644 index 0000000..70af7cd --- /dev/null +++ b/file-5.30-python-utf8.patch @@ -0,0 +1,147 @@ +From 379acb2065d904acf3a9814adfd93cda71a6ca21 Mon Sep 17 00:00:00 2001 +From: Christos Zoulas +Date: Tue, 4 Apr 2017 20:48:40 +0000 +Subject: [PATCH] retain python 2 compatibility, factoring out the conversion + functions. + +Upstream-commit: 8a942980f3f705226300f43f4b49a557c0918660 +Signed-off-by: Kamil Dudka +--- + python/magic.py | 68 ++++++++++++++++++++++++++++++++------------------------- + 1 file changed, 38 insertions(+), 30 deletions(-) + +diff --git a/python/magic.py b/python/magic.py +index b0f7a17..662569e 100644 +--- a/python/magic.py ++++ b/python/magic.py +@@ -117,30 +117,43 @@ class Magic(object): + """ + _close(self._magic_t) + ++ @staticmethod ++ def __tostr(s): ++ if s is None: ++ return None ++ if isinstance(s, str): ++ return s ++ try: # keep Python 2 compatibility ++ return str(s, 'utf-8') ++ except TypeError: ++ return str(s) ++ ++ @staticmethod ++ def __tobytes(b): ++ if b is None: ++ return None ++ if isinstance(b, bytes): ++ return b ++ try: # keep Python 2 compatibility ++ return bytes(b, 'utf-8') ++ except TypeError: ++ return bytes(b) ++ + def file(self, filename): + """ + Returns a textual description of the contents of the argument passed + as a filename or None if an error occurred and the MAGIC_ERROR flag +- is set. A call to errno() will return the numeric error code. ++ is set. A call to errno() will return the numeric error code. + """ +- if isinstance(filename, bytes): +- bi = filename +- else: +- try: # keep Python 2 compatibility +- bi = bytes(filename, 'utf-8') +- except TypeError: +- bi = bytes(filename) +- r = _file(self._magic_t, bi) +- if isinstance(r, str): +- return r +- else: +- return str(r, 'utf-8') ++ return Magic.__tostr(_file(self._magic_t, Magic.__tobytes(filename))) + + def descriptor(self, fd): + """ +- Like the file method, but the argument is a file descriptor. ++ Returns a textual description of the contents of the argument passed ++ as a file descriptor or None if an error occurred and the MAGIC_ERROR ++ flag is set. A call to errno() will return the numeric error code. + """ +- return _descriptor(self._magic_t, fd) ++ return Magic.__tostr(_descriptor(self._magic_t, fd)) + + def buffer(self, buf): + """ +@@ -148,22 +161,14 @@ class Magic(object): + as a buffer or None if an error occurred and the MAGIC_ERROR flag + is set. A call to errno() will return the numeric error code. + """ +- r = _buffer(self._magic_t, buf, len(buf)) +- if isinstance(r, str): +- return r +- else: +- return str(r, 'utf-8') ++ return Magic.__tostr(_buffer(self._magic_t, buf, len(buf))) + + def error(self): + """ + Returns a textual explanation of the last error or None + if there was no error. + """ +- e = _error(self._magic_t) +- if isinstance(e, str): +- return e +- else: +- return str(e, 'utf-8') ++ return Magic.__tostr(_error(self._magic_t)) + + def setflags(self, flags): + """ +@@ -184,35 +189,38 @@ class Magic(object): + + Returns 0 on success and -1 on failure. + """ +- return _load(self._magic_t, filename) ++ return _load(self._magic_t, Magic.__tobytes(filename)) + + def compile(self, dbs): + """ + Compile entries in the colon separated list of database files + passed as argument or the default database file if no argument. +- Returns 0 on success and -1 on failure. + The compiled files created are named from the basename(1) of each file + argument with ".mgc" appended to it. ++ ++ Returns 0 on success and -1 on failure. + """ +- return _compile(self._magic_t, dbs) ++ return _compile(self._magic_t, Magic.__tobytes(dbs)) + + def check(self, dbs): + """ + Check the validity of entries in the colon separated list of + database files passed as argument or the default database file + if no argument. ++ + Returns 0 on success and -1 on failure. + """ +- return _check(self._magic_t, dbs) ++ return _check(self._magic_t, Magic.__tobytes(dbs)) + + def list(self, dbs): + """ + Check the validity of entries in the colon separated list of + database files passed as argument or the default database file + if no argument. ++ + Returns 0 on success and -1 on failure. + """ +- return _list(self._magic_t, dbs) ++ return _list(self._magic_t, Magic.__tobytes(dbs)) + + def errno(self): + """ +-- +2.10.2 + diff --git a/file.spec b/file.spec index cc3a0ed..296de9a 100644 --- a/file.spec +++ b/file.spec @@ -3,7 +3,7 @@ Summary: A utility for determining file types Name: file Version: 5.30 -Release: 5%{?dist} +Release: 6%{?dist} License: BSD Group: Applications/File Source0: ftp://ftp.astron.com/pub/file/file-%{version}.tar.gz @@ -20,6 +20,7 @@ Patch5: file-5.04-man-return-code.patch Patch18: file-5.30-fix-debug-info-reversed-logic.patch Patch19: file-5.30-keep-not-stripped-last.patch Patch20: file-5.30-bump-perl-to-exceed-c.patch +Patch21: file-5.30-python-utf8.patch URL: http://www.darwinsys.com/file/ Requires: file-libs = %{version}-%{release} @@ -188,9 +189,12 @@ cd %{py3dir} %endif %changelog +* Tue Apr 05 2017 Kamil Dudka - 5.30-6 +- fix utf-8 conversion in Python 2 bindings (#1433364) + * Thu Feb 23 2017 Kamil Dudka - 5.30-5 - make the package build on EPEL-6 and EPEL-7 -- drup undocumented override of the __libtoolize RPM macro +- drop undocumented override of the __libtoolize RPM macro - drop undocumented non-upstream file-5.24-varied.patch - drop undocumented non-upstream file-5.22-awk-perl.patch - drop non-upstream file-5.19-cafebabe.patch no longer needed (#1134580)