-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BF(PY2): CommandError - make __str__ return bytes via assure_bytes, _…
…_unicode__ to return str Should be reverted in master where there is no PY2 compatibility
- Loading branch information
1 parent
19ee052
commit 6bce96d
Showing
1 changed file
with
12 additions
and
3 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 |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
import re | ||
from os import linesep | ||
|
||
from six import PY2 | ||
|
||
class CommandError(RuntimeError): | ||
"""Thrown if a command call fails. | ||
|
@@ -25,16 +26,24 @@ def __init__(self, cmd="", msg="", code=None, stdout="", stderr=""): | |
self.stdout = stdout | ||
self.stderr = stderr | ||
|
||
def __str__(self): | ||
from datalad.utils import assure_unicode | ||
def _str(self): | ||
from ..utils import assure_unicode | ||
to_str = "%s: " % self.__class__.__name__ | ||
if self.cmd: | ||
to_str += "command '%s'" % (self.cmd,) | ||
if self.code: | ||
to_str += " failed with exitcode %d" % self.code | ||
to_str += "\n%s" % assure_unicode(self.msg) | ||
to_str += "\n" + assure_unicode(self.msg) | ||
return to_str | ||
|
||
if PY2: | ||
def __str__(self): | ||
from ..utils import assure_bytes | ||
return assure_bytes(self._str()) | ||
__unicode__ = _str | ||
else: | ||
__str__ = _str | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
yarikoptic
Author
Member
|
||
|
||
|
||
class MissingExternalDependency(RuntimeError): | ||
"""External dependency is missing error""" | ||
|
FWIW this seems to deal with the same thing that
@six.python_2_unicode_compatible
would handle. (Ideally any of our classes that define__str__
would use that so that it'd work properly on py2.)