Permalink
Browse files

better handling of repr and str

  • Loading branch information...
1 parent 2150c8f commit 464b48a9200dafb3c43d5c50891fb61f41fff468 @amoffat committed Sep 16, 2012
Showing with 9 additions and 4 deletions.
  1. +9 −4 sh.py
View
@@ -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)
@@ -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())
@@ -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()

0 comments on commit 464b48a

Please sign in to comment.