Skip to content

Commit

Permalink
better handling of repr and str
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Moffat committed Sep 16, 2012
1 parent 2150c8f commit 464b48a
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions sh.py
Expand Up @@ -304,12 +304,12 @@ def __exit__(self, typ, value, traceback):

def __str__(self):
if IS_PY3: return self.__unicode__()
else: return unicode(self).encode(self.call_args["encoding"])
else: return unicode(self).decode(self.call_args["encoding"])

def __unicode__(self):
if self.process:
if self.stdout: return self.stdout.decode(self.call_args["encoding"])
else: return ""
return ""

def __eq__(self, other):
return unicode(self) == unicode(other)
Expand All @@ -325,7 +325,11 @@ def __getattr__(self, p):
return getattr(unicode(self), p)

def __repr__(self):
return str(self)
try: return str(self)
except UnicodeDecodeError:
if self.process:
if self.stdout: return repr(self.stdout)
return repr("")

def __long__(self):
return long(str(self).strip())
Expand Down Expand Up @@ -1242,8 +1246,9 @@ def change_buffering(self, new_type):
self.log.debug("acquiring buffering lock for changing buffering")
self._buffering_lock.acquire()
self.log.debug("got buffering lock for changing buffering")
try:
try:
if new_type == 0: self._use_up_buffer_first = True

self.type = new_type
finally:
self._buffering_lock.release()
Expand Down

0 comments on commit 464b48a

Please sign in to comment.