Merge lp:~shimizukawa/pyreadline/python3 into lp:pyreadline

Proposed by Shimizukawa
Status: Merged
Merged at revision: 107
Proposed branch: lp:~shimizukawa/pyreadline/python3
Merge into: lp:pyreadline
Diff against target: 411 lines (+96/-58)
14 files modified
.bzrignore (+3/-0)
doc/ChangeLog (+3/-0)
doc/source/introduction.rst (+1/-1)
eggsetup.py (+1/-1)
pyreadline/console/console.py (+8/-5)
pyreadline/lineeditor/history.py (+2/-4)
pyreadline/lineeditor/lineobj.py (+3/-3)
pyreadline/modes/basemode.py (+2/-2)
pyreadline/release.py (+33/-32)
pyreadline/rlmain.py (+2/-2)
pyreadline/test/test_emacs.py (+2/-2)
pyreadline/test/test_vi.py (+3/-3)
pyreadline/unicode_helper.py (+12/-1)
setup.py (+21/-2)
To merge this branch: bzr merge lp:~shimizukawa/pyreadline/python3
Reviewer Review Type Date Requested Status
B. Striegel (community) Approve
pyreadline Pending
Review via email: mp+57057@code.launchpad.net

Description of the change

Now pyreadline become python3 ready.

pyreadline's code-base is still python2, but setup.py convert code into python3 with using distribute and 2to3 library.

To post a comment you must log in.
lp:~shimizukawa/pyreadline/python3 updated
119. By shimizukawa

fixed: bytes iteration generate int literal instead of bytes literal

Revision history for this message
B. Striegel (b-striegel) wrote :

With Python 3.2.1 on Windows XP, successfully used this branch to enable readline for both the built-in Python interactive shell and for IPython3. This is exactly what I was looking for. :)

One weird thing that may or may not be related to pyreadline: while the built-in Python interactive shell exhibits no issues, using IPython3 with this library causes the "In [x]" prompt to double up after each command, and then a print a third time as soon as you begin typing a new command. Example:

-------

In [1]:
In [1]:
In [1]: a = [1,2,3]

In [2]:
In [2]:
In [2]: a
Out[2]: [1, 2, 3]

In [3]:
In [3]:
In [3]: print('hello')
hello

In [4]:
In [4]:

-------

I realize that IPython itself only barely supports Py3k (and even required a few manual hacks to get it to run at all on XP), but it did not exhibit this behavior before installing pyreadline. I also haven't had this problem using IPython3 on CentOS with the usual readline library.

review: Approve
Revision history for this message
Shimizukawa (shimizukawa) wrote :

> One weird thing that may or may not be related to pyreadline: while the built-
> in Python interactive shell exhibits no issues, using IPython3 with this
> library causes the "In [x]" prompt to double up after each command, and then a
> print a third time as soon as you begin typing a new command. Example:
>
> -------
>
> In [1]:
> In [1]:
> In [1]: a = [1,2,3]

I'm trying IPython3 got from https://github.com/ipython/ipython-py3k/commit/17bd8dfb1da9940799c3c3e0e19af098f4f93a45 and it works for me on Windows7+Python-3.2 (but I found another bug..)

Next, I'll try with Windows XP.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file '.bzrignore'
--- .bzrignore 2008-06-22 12:30:47 +0000
+++ .bzrignore 2011-04-23 08:41:27 +0000
@@ -1,1 +1,4 @@
1build1build
2dist
3pyreadline.egg-info/
4__pycache__/
25
=== modified file 'doc/ChangeLog'
--- doc/ChangeLog 2008-08-25 17:12:51 +0000
+++ doc/ChangeLog 2011-04-23 08:41:27 +0000
@@ -1,3 +1,6 @@
12011-04-10 Takayuki SHIMIZUKAWA <shimizukawa -at- gmail.com>
2 * Python3 ready.
3
12008-08-25 Jörgen Stenarson <jorgen.stenarson -at- bostream.nu>42008-08-25 Jörgen Stenarson <jorgen.stenarson -at- bostream.nu>
2 * Merging tab insert patch from Vivian De Smedt. Removed comments5 * Merging tab insert patch from Vivian De Smedt. Removed comments
3 with vds initials.6 with vds initials.
47
=== modified file 'doc/source/introduction.rst'
--- doc/source/introduction.rst 2011-04-14 19:00:46 +0000
+++ doc/source/introduction.rst 2011-04-23 08:41:27 +0000
@@ -11,7 +11,7 @@
11interfaces in GUIs. The use of pyreadline for anything but the windows 11interfaces in GUIs. The use of pyreadline for anything but the windows
12console is still under development.12console is still under development.
1313
14The pyreadline module does not yet support Python 3.x this will be targeted for the 2.0 version.14The pyreadline module support also Python 3.x.
1515
16Version 1.7 will be the last release with compatibility with 2.4 and 2.5. The next16Version 1.7 will be the last release with compatibility with 2.4 and 2.5. The next
17major release will target 2.6, 2.7 and 3.x. The 1.7 series will only receive bugfixes17major release will target 2.6, 2.7 and 3.x. The 1.7 series will only receive bugfixes
1818
=== modified file 'eggsetup.py'
--- eggsetup.py 2006-03-12 14:52:00 +0000
+++ eggsetup.py 2011-04-23 08:41:27 +0000
@@ -8,7 +8,7 @@
8#*****************************************************************************8#*****************************************************************************
9import glob9import glob
10from setuptools import setup,find_packages10from setuptools import setup,find_packages
11execfile('pyreadline/release.py')11exec(compile(open('pyreadline/release.py').read(), 'pyreadline/release.py', 'exec'))
1212
13setup(name=name,13setup(name=name,
14 version = version,14 version = version,
1515
=== modified file 'pyreadline/console/console.py'
--- pyreadline/console/console.py 2009-10-06 17:36:27 +0000
+++ pyreadline/console/console.py 2011-04-23 08:41:27 +0000
@@ -30,6 +30,9 @@
30except ImportError:30except ImportError:
31 raise ImportError(u"You need ctypes to run this code")31 raise ImportError(u"You need ctypes to run this code")
3232
33if sys.version_info < (2, 6):
34 bytes = str
35
33def nolog(string):36def nolog(string):
34 pass37 pass
35 38
@@ -286,7 +289,7 @@
286289
287 # This pattern should match all characters that change the cursor position differently290 # This pattern should match all characters that change the cursor position differently
288 # than a normal character.291 # than a normal character.
289 motion_char_re = re.compile(u'([\n\r\t\010\007])')292 motion_char_re = re.compile('([\n\r\t\010\007])'.encode('ascii'))
290293
291 def write_scrolling(self, text, attr=None):294 def write_scrolling(self, text, attr=None):
292 u'''write text at current cursor position while watching for scrolling.295 u'''write text at current cursor position while watching for scrolling.
@@ -306,7 +309,7 @@
306 w, h = self.size()309 w, h = self.size()
307 scroll = 0 # the result310 scroll = 0 # the result
308 # split the string into ordinary characters and funny characters311 # split the string into ordinary characters and funny characters
309 chunks = self.motion_char_re.split(text)312 chunks = self.motion_char_re.split(ensure_str(text))
310 for chunk in chunks:313 for chunk in chunks:
311 n = self.write_color(chunk, attr)314 n = self.write_color(chunk, attr)
312 if len(chunk) == 1: # the funny characters will be alone315 if len(chunk) == 1: # the funny characters will be alone
@@ -690,7 +693,7 @@
690 # call the Python hook693 # call the Python hook
691 res = ensure_str(readline_hook(prompt))694 res = ensure_str(readline_hook(prompt))
692 # make sure it returned the right sort of thing695 # make sure it returned the right sort of thing
693 if res and not isinstance(res, str):696 if res and not isinstance(res, bytes):
694 raise TypeError, u'readline must return a string.'697 raise TypeError, u'readline must return a string.'
695 except KeyboardInterrupt:698 except KeyboardInterrupt:
696 # GNU readline returns 0 on keyboard interrupt699 # GNU readline returns 0 on keyboard interrupt
@@ -714,7 +717,7 @@
714 # call the Python hook717 # call the Python hook
715 res = ensure_str(readline_hook(prompt))718 res = ensure_str(readline_hook(prompt))
716 # make sure it returned the right sort of thing719 # make sure it returned the right sort of thing
717 if res and not isinstance(res, str):720 if res and not isinstance(res, bytes):
718 raise TypeError, u'readline must return a string.'721 raise TypeError, u'readline must return a string.'
719 except KeyboardInterrupt:722 except KeyboardInterrupt:
720 # GNU readline returns 0 on keyboard interrupt723 # GNU readline returns 0 on keyboard interrupt
@@ -738,7 +741,7 @@
738 readline_hook = hook741 readline_hook = hook
739 # get the address of PyOS_ReadlineFunctionPointer so we can update it742 # get the address of PyOS_ReadlineFunctionPointer so we can update it
740 PyOS_RFP = c_int.from_address(Console.GetProcAddress(sys.dllhandle,743 PyOS_RFP = c_int.from_address(Console.GetProcAddress(sys.dllhandle,
741 "PyOS_ReadlineFunctionPointer"))744 "PyOS_ReadlineFunctionPointer".encode('ascii')))
742 # save a reference to the generated C-callable so it doesn't go away745 # save a reference to the generated C-callable so it doesn't go away
743 if sys.version < '2.3':746 if sys.version < '2.3':
744 readline_ref = HOOKFUNC22(hook_wrapper)747 readline_ref = HOOKFUNC22(hook_wrapper)
745748
=== modified file 'pyreadline/lineeditor/history.py'
--- pyreadline/lineeditor/history.py 2011-04-14 18:36:47 +0000
+++ pyreadline/lineeditor/history.py 2011-04-23 08:41:27 +0000
@@ -15,9 +15,7 @@
1515
16import lineobj16import lineobj
1717
18import exceptions18class EscapeHistory(Exception):
19
20class EscapeHistory(exceptions.Exception):
21 pass19 pass
2220
23from pyreadline.logger import log21from pyreadline.logger import log
@@ -93,7 +91,7 @@
93 fp = open(filename, u'wb')91 fp = open(filename, u'wb')
94 for line in self.history[-self.history_length:]:92 for line in self.history[-self.history_length:]:
95 fp.write(ensure_str(line.get_line_text()))93 fp.write(ensure_str(line.get_line_text()))
96 fp.write(u'\n')94 fp.write('\n'.encode('ascii'))
97 fp.close()95 fp.close()
9896
9997
10098
=== modified file 'pyreadline/lineeditor/lineobj.py'
--- pyreadline/lineeditor/lineobj.py 2008-11-12 21:56:56 +0000
+++ pyreadline/lineeditor/lineobj.py 2011-04-23 08:41:27 +0000
@@ -10,7 +10,7 @@
10import wordmatcher10import wordmatcher
11import pyreadline.clipboard as clipboard11import pyreadline.clipboard as clipboard
12from pyreadline.logger import log12from pyreadline.logger import log
13from pyreadline.unicode_helper import ensure_unicode13from pyreadline.unicode_helper import ensure_unicode, biter
1414
15kill_ring_to_clipboard = False #set to true to copy every addition to kill ring to clipboard15kill_ring_to_clipboard = False #set to true to copy every addition to kill ring to clipboard
1616
@@ -272,12 +272,12 @@
272 def _insert_text(self, text, argument=1):272 def _insert_text(self, text, argument=1):
273 text = text * argument273 text = text * argument
274 if self.overwrite:274 if self.overwrite:
275 for c in text:275 for c in biter(text):
276 #if self.point:276 #if self.point:
277 self.line_buffer[self.point] = c277 self.line_buffer[self.point] = c
278 self.point += 1278 self.point += 1
279 else: 279 else:
280 for c in text:280 for c in biter(text):
281 self.line_buffer.insert(self.point, c)281 self.line_buffer.insert(self.point, c)
282 self.point += 1282 self.point += 1
283 283
284284
=== modified file 'pyreadline/modes/basemode.py'
--- pyreadline/modes/basemode.py 2011-04-14 16:52:22 +0000
+++ pyreadline/modes/basemode.py 2011-04-23 08:41:27 +0000
@@ -195,7 +195,7 @@
195 i = 0195 i = 0
196 while 1:196 while 1:
197 try:197 try:
198 r = ensure_unicode(self.completer(text, i))198 r = self.completer(ensure_unicode(text), i)
199 except IndexError:199 except IndexError:
200 break200 break
201 i += 1201 i += 1
@@ -215,7 +215,7 @@
215 break215 break
216 text = ensure_str(u''.join(buf[self.begidx:self.endidx]))216 text = ensure_str(u''.join(buf[self.begidx:self.endidx]))
217 log(u'file complete text="%s"' % ensure_unicode(text))217 log(u'file complete text="%s"' % ensure_unicode(text))
218 completions = map(ensure_unicode, glob.glob(os.path.expanduser(text) + '*'))218 completions = map(ensure_unicode, glob.glob(os.path.expanduser(text) + '*'.encode('ascii')))
219 if self.mark_directories == u'on':219 if self.mark_directories == u'on':
220 mc = []220 mc = []
221 for f in completions:221 for f in completions:
222222
=== modified file 'pyreadline/release.py'
--- pyreadline/release.py 2011-04-14 19:00:46 +0000
+++ pyreadline/release.py 2011-04-23 08:41:27 +0000
@@ -1,5 +1,5 @@
1# -*- coding: utf-8 -*-1# -*- coding: utf-8 -*-
2u"""Release data for the pyreadline project.2"""Release data for the pyreadline project.
33
4$Id$"""4$Id$"""
55
@@ -13,23 +13,23 @@
1313
14# Name of the package for release purposes. This is the name which labels14# Name of the package for release purposes. This is the name which labels
15# the tarballs and RPMs made by distutils, so it's best to lowercase it.15# the tarballs and RPMs made by distutils, so it's best to lowercase it.
16name = u'pyreadline'16name = 'pyreadline'
1717
18# For versions with substrings (like 0.6.16.svn), use an extra . to separate18# For versions with substrings (like 0.6.16.svn), use an extra . to separate
19# the new substring. We have to avoid using either dashes or underscores,19# the new substring. We have to avoid using either dashes or underscores,
20# because bdist_rpm does not accept dashes (an RPM) convention, and20# because bdist_rpm does not accept dashes (an RPM) convention, and
21# bdist_deb does not accept underscores (a Debian convention).21# bdist_deb does not accept underscores (a Debian convention).
2222
23branch = u''23branch = ''
2424
25version = u'1.7'25version = '1.7'
2626
27revision = u'$Revision$'27revision = '$Revision$'
2828
29description = u"A python implmementation of GNU readline."29description = "A python implmementation of GNU readline."
3030
31long_description = \31long_description = \
32u"""32"""
33The pyreadline package is a python implementation of GNU readline functionality33The pyreadline package is a python implementation of GNU readline functionality
34it is based on the ctypes based UNC readline package by Gary Bishop. 34it is based on the ctypes based UNC readline package by Gary Bishop.
35It is not complete. It has been tested for use with windows 2000 and windows xp.35It is not complete. It has been tested for use with windows 2000 and windows xp.
@@ -55,31 +55,32 @@
55.. _repository:55.. _repository:
56 """56 """
5757
58license = u'BSD'58license = 'BSD'
5959
60authors = {u'Jorgen' : (u'Jorgen Stenarson',u'jorgen.stenarson@bostream.nu'),60authors = {'Jorgen' : ('Jorgen Stenarson','jorgen.stenarson@bostream.nu'),
61 u'Gary': (u'Gary Bishop', ''), 61 'Gary': ('Gary Bishop', ''),
62 u'Jack': (u'Jack Trainor', ''), 62 'Jack': ('Jack Trainor', ''),
63 }63 }
6464
65url = u'http://ipython.scipy.org/moin/PyReadline/Intro'65url = 'http://ipython.scipy.org/moin/PyReadline/Intro'
6666
67download_url = u'https://launchpad.net/pyreadline/+download'67download_url = 'https://launchpad.net/pyreadline/+download'
6868
69platforms = [u'Windows XP/2000/NT',69platforms = ['Windows XP/2000/NT',
70 u'Windows 95/98/ME']70 'Windows 95/98/ME']
7171
72keywords = [u'readline',72keywords = ['readline',
73 u'pyreadline']73 'pyreadline']
7474
75classifiers = [u'Development Status :: 5 - Production/Stable',75classifiers = ['Development Status :: 5 - Production/Stable',
76 u'Environment :: Console',76 'Environment :: Console',
77 u'Operating System :: Microsoft :: Windows',77 'Operating System :: Microsoft :: Windows',
78 u'License :: OSI Approved :: BSD License',78 'License :: OSI Approved :: BSD License',
79 u'Programming Language :: Python :: 2.4',79 'Programming Language :: Python :: 2.4',
80 u'Programming Language :: Python :: 2.5',80 'Programming Language :: Python :: 2.5',
81 u'Programming Language :: Python :: 2.6',81 'Programming Language :: Python :: 2.6',
82 u'Programming Language :: Python :: 2.7',82 'Programming Language :: Python :: 2.7',
83 'Programming Language :: Python :: 3.2',
83 ]84 ]
84 85
85 86
8687
=== modified file 'pyreadline/rlmain.py'
--- pyreadline/rlmain.py 2011-02-25 19:22:11 +0000
+++ pyreadline/rlmain.py 2011-04-23 08:41:27 +0000
@@ -282,9 +282,9 @@
282 self.mode = modes[name]282 self.mode = modes[name]
283283
284 def bind_key(key, name):284 def bind_key(key, name):
285 import new285 import types
286 if callable(name):286 if callable(name):
287 modes[mode]._bind_key(key, new.instancemethod(name, modes[mode], modes[mode].__class__))287 modes[mode]._bind_key(key, types.MethodType(name, modes[mode]))
288 elif hasattr(modes[mode], name):288 elif hasattr(modes[mode], name):
289 modes[mode]._bind_key(key, getattr(modes[mode], name))289 modes[mode]._bind_key(key, getattr(modes[mode], name))
290 else:290 else:
291291
=== modified file 'pyreadline/test/test_emacs.py'
--- pyreadline/test/test_emacs.py 2010-07-20 16:30:15 +0000
+++ pyreadline/test/test_emacs.py 2011-04-23 08:41:27 +0000
@@ -9,12 +9,12 @@
99
10import sys, unittest10import sys, unittest
11import pdb11import pdb
12sys.path.append (u'../..')12sys.path.insert(0, u'../..')
13from pyreadline.modes.emacs import *13from pyreadline.modes.emacs import *
14from pyreadline import keysyms14from pyreadline import keysyms
15from pyreadline.lineeditor import lineobj15from pyreadline.lineeditor import lineobj
1616
17from common import *17from pyreadline.test.common import *
18from pyreadline.logger import log18from pyreadline.logger import log
19import pyreadline.logger as logger19import pyreadline.logger as logger
20logger.sock_silent=True20logger.sock_silent=True
2121
=== modified file 'pyreadline/test/test_vi.py'
--- pyreadline/test/test_vi.py 2010-07-20 17:12:13 +0000
+++ pyreadline/test/test_vi.py 2011-04-23 08:41:27 +0000
@@ -7,15 +7,15 @@
7#*****************************************************************************7#*****************************************************************************
88
9import sys, unittest,pdb9import sys, unittest,pdb
10sys.path.append (u'../..')10sys.path.insert(0, u'../..')
11from pyreadline.modes.vi import *11from pyreadline.modes.vi import *
12from pyreadline import keysyms12from pyreadline import keysyms
13from pyreadline.lineeditor import lineobj13from pyreadline.lineeditor import lineobj
14from pyreadline.logger import log14from pyreadline.logger import log
15import pyreadline.logger as logger15import pyreadline.logger as logger
16from common import *16from pyreadline.test.common import *
1717
18from common import *18from pyreadline.test.common import *
19#----------------------------------------------------------------------19#----------------------------------------------------------------------
2020
21class ViModeTest (ViMode):21class ViModeTest (ViMode):
2222
=== modified file 'pyreadline/unicode_helper.py'
--- pyreadline/unicode_helper.py 2010-07-15 16:23:16 +0000
+++ pyreadline/unicode_helper.py 2011-04-23 08:41:27 +0000
@@ -17,9 +17,14 @@
17if pyreadline_codepage is None: 17if pyreadline_codepage is None:
18 pyreadline_codepage = u"ascii"18 pyreadline_codepage = u"ascii"
1919
20if sys.version_info < (2, 6):
21 bytes = str
22
23PY3 = (sys.version_info >= (3, 0))
24
20def ensure_unicode(text):25def ensure_unicode(text):
21 u"""helper to ensure that text passed to WriteConsoleW is unicode"""26 u"""helper to ensure that text passed to WriteConsoleW is unicode"""
22 if isinstance(text, str):27 if isinstance(text, bytes):
23 try:28 try:
24 return text.decode(pyreadline_codepage, u"replace")29 return text.decode(pyreadline_codepage, u"replace")
25 except (LookupError, TypeError):30 except (LookupError, TypeError):
@@ -34,3 +39,9 @@
34 except (LookupError, TypeError):39 except (LookupError, TypeError):
35 return text.encode(u"ascii", u"replace")40 return text.encode(u"ascii", u"replace")
36 return text41 return text
42
43def biter(text):
44 if PY3 and isinstance(text, bytes):
45 return (s.to_bytes(1, 'big') for s in text)
46 else:
47 return iter(text)
3748
=== modified file 'setup.py'
--- setup.py 2010-07-19 17:09:00 +0000
+++ setup.py 2011-04-23 08:41:27 +0000
@@ -9,6 +9,7 @@
9#*****************************************************************************9#*****************************************************************************
1010
11import os11import os
12import sys
12import glob13import glob
1314
14# BEFORE importing distutils, remove MANIFEST. distutils doesn't properly15# BEFORE importing distutils, remove MANIFEST. distutils doesn't properly
@@ -16,8 +17,25 @@
16if os.path.exists('MANIFEST'): os.remove('MANIFEST')17if os.path.exists('MANIFEST'): os.remove('MANIFEST')
17#18#
1819
19from distutils.core import setup20extra = {}
20execfile('pyreadline/release.py')21_distribute = False
22
23try:
24 import setuptools
25 setup = setuptools.setup
26 _distribute = getattr(setuptools, '_distribute', False)
27except ImportError:
28 from distutils.core import setup
29
30if sys.version_info >= (3, 0):
31 if _distribute == False:
32 raise RuntimeError('You must installed `distribute` to setup pyreadline with Python3')
33
34 extra.update(
35 use_2to3=True
36 )
37
38exec(compile(open('pyreadline/release.py').read(), 'pyreadline/release.py', 'exec'))
2139
22try:40try:
23 import sphinx41 import sphinx
@@ -50,5 +68,6 @@
50 package_data = {'pyreadline':['configuration/*']},68 package_data = {'pyreadline':['configuration/*']},
51 data_files = [],69 data_files = [],
52 cmdclass = cmd_class,70 cmdclass = cmd_class,
71 **extra
53 )72 )
5473

Subscribers

People subscribed via source and target branches

to all changes:
to status/vote changes: