summaryrefslogtreecommitdiff
path: root/pexpect/screen.py
diff options
context:
space:
mode:
authorDavid O'Shea <doshea@doshea-centos-x86-64.adl.quantum.com>2014-08-01 17:10:58 +0930
committerDavid O'Shea <doshea@doshea-centos-x86-64.adl.quantum.com>2014-08-01 17:27:13 +0930
commita4b8165da2a7f356e3a12b091727e33e6fcc0d2c (patch)
treeb023c3562763c8d6ab94b339509acd1e08d46d61 /pexpect/screen.py
parent05711ea5004a9d9bf8164fc75e90a6a7c79b5c18 (diff)
downloadpexpect-git-a4b8165da2a7f356e3a12b091727e33e6fcc0d2c.tar.gz
Don't define __bytes__(), and don't define __unicode__() on Python 3.
The previous attempt to add unicode support tried to make Python 2 and 3 behave in the same way apart from __str__(). This commit makes the modules, and the tests, provide only __str__() on Python 3 and both __str__() and __unicode__() on Python 2.
Diffstat (limited to 'pexpect/screen.py')
-rw-r--r--pexpect/screen.py37
1 files changed, 16 insertions, 21 deletions
diff --git a/pexpect/screen.py b/pexpect/screen.py
index 6cd2452..f1f37c1 100644
--- a/pexpect/screen.py
+++ b/pexpect/screen.py
@@ -71,7 +71,7 @@ class screen:
input characters, when passed 'bytes' (which in Python 2 is equivalent to
'str'), convert them from the encoding specified in the 'encoding'
parameter to the constructor. Methods that return screen contents return
- unicode strings, with the exception of __str__() under Python 2 and __bytes__(). '''
+ unicode strings, with the exception of __str__() under Python 2 '''
def __init__ (self, r=24,c=80,encoding='latin-1',encoding_errors='replace'):
'''This initializes a blank screen of the given dimensions.'''
@@ -109,39 +109,34 @@ class screen:
else:
return unicode(s)
+ def _unicode (self):
+ '''This returns a printable representation of the screen in unicode
+ form (which, under Python 3.x, is the same as 'str'). The end of each
+ screen line is terminated by a newline.'''
+
+ return u'\n'.join ([ u''.join(c) for c in self.w ])
+
if PY3:
- def __str__(self):
- '''This returns a printable representation of the screen. The end of
- each screen line is terminated by a newline. '''
- return self.__unicode__()
+ __str__ = _unicode
else:
+ __unicode__ = _unicode
+
def __str__(self):
'''This returns a printable representation of the screen. The end of
each screen line is terminated by a newline. '''
- return self.__bytes__()
-
- def __unicode__ (self):
- '''This returns a printable representation of the screen. The end of
- each screen line is terminated by a newline. '''
-
- return u'\n'.join ([ u''.join(c) for c in self.w ])
-
- def __bytes__ (self):
- '''This returns a printable representation of the screen. The end of
- each screen line is terminated by a newline. '''
-
- return self._encode(self.__unicode__())
+ return self._encode(self._unicode())
def dump (self):
'''This returns a copy of the screen as a string. This is similar to
- __unicode__ except that lines are not terminated with line feeds. '''
+ __str__/__unicode__ except that lines are not terminated with line
+ feeds.'''
return u''.join ([ u''.join(c) for c in self.w ])
def pretty (self):
'''This returns a copy of the screen as a string with an ASCII text box
- around the screen border. This is similar to __unicode__ except that it
- adds a box. '''
+ around the screen border. This is similar to __str__/__unicode__ except
+ that it adds a box.'''
top_bot = u'+' + u'-'*self.cols + u'+\n'
return top_bot + u'\n'.join([u'|'+line+u'|' for line in unicode(self).split(u'\n')]) + u'\n' + top_bot