Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Return str rather than bytes for the description strings on python3.
Assumes utf-8 encoding from magic return values, which I hope is always the case.
- Loading branch information
Showing
2 changed files
with
13 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -72,7 +72,7 @@ def from_buffer(self, buf): | |
| """ | ||
| with self.lock: | ||
| try: | ||
| return magic_buffer(self.cookie, buf) | ||
| return maybe_decode(magic_buffer(self.cookie, buf)) | ||
| except MagicException as e: | ||
| return self._handle509Bug(e) | ||
|
|
||
|
|
@@ -82,7 +82,7 @@ def from_file(self, filename): | |
| pass | ||
| with self.lock: | ||
| try: | ||
| return magic_file(self.cookie, filename) | ||
| return maybe_decode(magic_file(self.cookie, filename)) | ||
| except MagicException as e: | ||
| return self._handle509Bug(e) | ||
|
|
||
|
|
@@ -189,6 +189,14 @@ def errorcheck_negative_one(result, func, args): | |
| return result | ||
|
|
||
|
|
||
| # return str on python3. Don't want to unconditionally | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
pquentin
|
||
| # decode because that results in unicode on python2 | ||
| def maybe_decode(s): | ||
| if str == bytes: | ||
| return s | ||
| else: | ||
| return s.decode('utf-8') | ||
|
|
||
| def coerce_filename(filename): | ||
| if filename is None: | ||
| return None | ||
|
|
||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hi, in python3
>>> str == bytes Falsebut in python2.7
>>> str == bytes TrueSo probably you need to return s.decode('utf-8') when the relation is true.