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
1=== modified file '.bzrignore'
2--- .bzrignore 2008-06-22 12:30:47 +0000
3+++ .bzrignore 2011-04-23 08:41:27 +0000
4@@ -1,1 +1,4 @@
5 build
6+dist
7+pyreadline.egg-info/
8+__pycache__/
9
10=== modified file 'doc/ChangeLog'
11--- doc/ChangeLog 2008-08-25 17:12:51 +0000
12+++ doc/ChangeLog 2011-04-23 08:41:27 +0000
13@@ -1,3 +1,6 @@
14+2011-04-10 Takayuki SHIMIZUKAWA <shimizukawa -at- gmail.com>
15+ * Python3 ready.
16+
17 2008-08-25 Jörgen Stenarson <jorgen.stenarson -at- bostream.nu>
18 * Merging tab insert patch from Vivian De Smedt. Removed comments
19 with vds initials.
20
21=== modified file 'doc/source/introduction.rst'
22--- doc/source/introduction.rst 2011-04-14 19:00:46 +0000
23+++ doc/source/introduction.rst 2011-04-23 08:41:27 +0000
24@@ -11,7 +11,7 @@
25 interfaces in GUIs. The use of pyreadline for anything but the windows
26 console is still under development.
27
28-The pyreadline module does not yet support Python 3.x this will be targeted for the 2.0 version.
29+The pyreadline module support also Python 3.x.
30
31 Version 1.7 will be the last release with compatibility with 2.4 and 2.5. The next
32 major release will target 2.6, 2.7 and 3.x. The 1.7 series will only receive bugfixes
33
34=== modified file 'eggsetup.py'
35--- eggsetup.py 2006-03-12 14:52:00 +0000
36+++ eggsetup.py 2011-04-23 08:41:27 +0000
37@@ -8,7 +8,7 @@
38 #*****************************************************************************
39 import glob
40 from setuptools import setup,find_packages
41-execfile('pyreadline/release.py')
42+exec(compile(open('pyreadline/release.py').read(), 'pyreadline/release.py', 'exec'))
43
44 setup(name=name,
45 version = version,
46
47=== modified file 'pyreadline/console/console.py'
48--- pyreadline/console/console.py 2009-10-06 17:36:27 +0000
49+++ pyreadline/console/console.py 2011-04-23 08:41:27 +0000
50@@ -30,6 +30,9 @@
51 except ImportError:
52 raise ImportError(u"You need ctypes to run this code")
53
54+if sys.version_info < (2, 6):
55+ bytes = str
56+
57 def nolog(string):
58 pass
59
60@@ -286,7 +289,7 @@
61
62 # This pattern should match all characters that change the cursor position differently
63 # than a normal character.
64- motion_char_re = re.compile(u'([\n\r\t\010\007])')
65+ motion_char_re = re.compile('([\n\r\t\010\007])'.encode('ascii'))
66
67 def write_scrolling(self, text, attr=None):
68 u'''write text at current cursor position while watching for scrolling.
69@@ -306,7 +309,7 @@
70 w, h = self.size()
71 scroll = 0 # the result
72 # split the string into ordinary characters and funny characters
73- chunks = self.motion_char_re.split(text)
74+ chunks = self.motion_char_re.split(ensure_str(text))
75 for chunk in chunks:
76 n = self.write_color(chunk, attr)
77 if len(chunk) == 1: # the funny characters will be alone
78@@ -690,7 +693,7 @@
79 # call the Python hook
80 res = ensure_str(readline_hook(prompt))
81 # make sure it returned the right sort of thing
82- if res and not isinstance(res, str):
83+ if res and not isinstance(res, bytes):
84 raise TypeError, u'readline must return a string.'
85 except KeyboardInterrupt:
86 # GNU readline returns 0 on keyboard interrupt
87@@ -714,7 +717,7 @@
88 # call the Python hook
89 res = ensure_str(readline_hook(prompt))
90 # make sure it returned the right sort of thing
91- if res and not isinstance(res, str):
92+ if res and not isinstance(res, bytes):
93 raise TypeError, u'readline must return a string.'
94 except KeyboardInterrupt:
95 # GNU readline returns 0 on keyboard interrupt
96@@ -738,7 +741,7 @@
97 readline_hook = hook
98 # get the address of PyOS_ReadlineFunctionPointer so we can update it
99 PyOS_RFP = c_int.from_address(Console.GetProcAddress(sys.dllhandle,
100- "PyOS_ReadlineFunctionPointer"))
101+ "PyOS_ReadlineFunctionPointer".encode('ascii')))
102 # save a reference to the generated C-callable so it doesn't go away
103 if sys.version < '2.3':
104 readline_ref = HOOKFUNC22(hook_wrapper)
105
106=== modified file 'pyreadline/lineeditor/history.py'
107--- pyreadline/lineeditor/history.py 2011-04-14 18:36:47 +0000
108+++ pyreadline/lineeditor/history.py 2011-04-23 08:41:27 +0000
109@@ -15,9 +15,7 @@
110
111 import lineobj
112
113-import exceptions
114-
115-class EscapeHistory(exceptions.Exception):
116+class EscapeHistory(Exception):
117 pass
118
119 from pyreadline.logger import log
120@@ -93,7 +91,7 @@
121 fp = open(filename, u'wb')
122 for line in self.history[-self.history_length:]:
123 fp.write(ensure_str(line.get_line_text()))
124- fp.write(u'\n')
125+ fp.write('\n'.encode('ascii'))
126 fp.close()
127
128
129
130=== modified file 'pyreadline/lineeditor/lineobj.py'
131--- pyreadline/lineeditor/lineobj.py 2008-11-12 21:56:56 +0000
132+++ pyreadline/lineeditor/lineobj.py 2011-04-23 08:41:27 +0000
133@@ -10,7 +10,7 @@
134 import wordmatcher
135 import pyreadline.clipboard as clipboard
136 from pyreadline.logger import log
137-from pyreadline.unicode_helper import ensure_unicode
138+from pyreadline.unicode_helper import ensure_unicode, biter
139
140 kill_ring_to_clipboard = False #set to true to copy every addition to kill ring to clipboard
141
142@@ -272,12 +272,12 @@
143 def _insert_text(self, text, argument=1):
144 text = text * argument
145 if self.overwrite:
146- for c in text:
147+ for c in biter(text):
148 #if self.point:
149 self.line_buffer[self.point] = c
150 self.point += 1
151 else:
152- for c in text:
153+ for c in biter(text):
154 self.line_buffer.insert(self.point, c)
155 self.point += 1
156
157
158=== modified file 'pyreadline/modes/basemode.py'
159--- pyreadline/modes/basemode.py 2011-04-14 16:52:22 +0000
160+++ pyreadline/modes/basemode.py 2011-04-23 08:41:27 +0000
161@@ -195,7 +195,7 @@
162 i = 0
163 while 1:
164 try:
165- r = ensure_unicode(self.completer(text, i))
166+ r = self.completer(ensure_unicode(text), i)
167 except IndexError:
168 break
169 i += 1
170@@ -215,7 +215,7 @@
171 break
172 text = ensure_str(u''.join(buf[self.begidx:self.endidx]))
173 log(u'file complete text="%s"' % ensure_unicode(text))
174- completions = map(ensure_unicode, glob.glob(os.path.expanduser(text) + '*'))
175+ completions = map(ensure_unicode, glob.glob(os.path.expanduser(text) + '*'.encode('ascii')))
176 if self.mark_directories == u'on':
177 mc = []
178 for f in completions:
179
180=== modified file 'pyreadline/release.py'
181--- pyreadline/release.py 2011-04-14 19:00:46 +0000
182+++ pyreadline/release.py 2011-04-23 08:41:27 +0000
183@@ -1,5 +1,5 @@
184 # -*- coding: utf-8 -*-
185-u"""Release data for the pyreadline project.
186+"""Release data for the pyreadline project.
187
188 $Id$"""
189
190@@ -13,23 +13,23 @@
191
192 # Name of the package for release purposes. This is the name which labels
193 # the tarballs and RPMs made by distutils, so it's best to lowercase it.
194-name = u'pyreadline'
195+name = 'pyreadline'
196
197 # For versions with substrings (like 0.6.16.svn), use an extra . to separate
198 # the new substring. We have to avoid using either dashes or underscores,
199 # because bdist_rpm does not accept dashes (an RPM) convention, and
200 # bdist_deb does not accept underscores (a Debian convention).
201
202-branch = u''
203-
204-version = u'1.7'
205-
206-revision = u'$Revision$'
207-
208-description = u"A python implmementation of GNU readline."
209+branch = ''
210+
211+version = '1.7'
212+
213+revision = '$Revision$'
214+
215+description = "A python implmementation of GNU readline."
216
217 long_description = \
218-u"""
219+"""
220 The pyreadline package is a python implementation of GNU readline functionality
221 it is based on the ctypes based UNC readline package by Gary Bishop.
222 It is not complete. It has been tested for use with windows 2000 and windows xp.
223@@ -55,31 +55,32 @@
224 .. _repository:
225 """
226
227-license = u'BSD'
228+license = 'BSD'
229
230-authors = {u'Jorgen' : (u'Jorgen Stenarson',u'jorgen.stenarson@bostream.nu'),
231- u'Gary': (u'Gary Bishop', ''),
232- u'Jack': (u'Jack Trainor', ''),
233+authors = {'Jorgen' : ('Jorgen Stenarson','jorgen.stenarson@bostream.nu'),
234+ 'Gary': ('Gary Bishop', ''),
235+ 'Jack': ('Jack Trainor', ''),
236 }
237
238-url = u'http://ipython.scipy.org/moin/PyReadline/Intro'
239-
240-download_url = u'https://launchpad.net/pyreadline/+download'
241-
242-platforms = [u'Windows XP/2000/NT',
243- u'Windows 95/98/ME']
244-
245-keywords = [u'readline',
246- u'pyreadline']
247-
248-classifiers = [u'Development Status :: 5 - Production/Stable',
249- u'Environment :: Console',
250- u'Operating System :: Microsoft :: Windows',
251- u'License :: OSI Approved :: BSD License',
252- u'Programming Language :: Python :: 2.4',
253- u'Programming Language :: Python :: 2.5',
254- u'Programming Language :: Python :: 2.6',
255- u'Programming Language :: Python :: 2.7',
256+url = 'http://ipython.scipy.org/moin/PyReadline/Intro'
257+
258+download_url = 'https://launchpad.net/pyreadline/+download'
259+
260+platforms = ['Windows XP/2000/NT',
261+ 'Windows 95/98/ME']
262+
263+keywords = ['readline',
264+ 'pyreadline']
265+
266+classifiers = ['Development Status :: 5 - Production/Stable',
267+ 'Environment :: Console',
268+ 'Operating System :: Microsoft :: Windows',
269+ 'License :: OSI Approved :: BSD License',
270+ 'Programming Language :: Python :: 2.4',
271+ 'Programming Language :: Python :: 2.5',
272+ 'Programming Language :: Python :: 2.6',
273+ 'Programming Language :: Python :: 2.7',
274+ 'Programming Language :: Python :: 3.2',
275 ]
276
277
278
279=== modified file 'pyreadline/rlmain.py'
280--- pyreadline/rlmain.py 2011-02-25 19:22:11 +0000
281+++ pyreadline/rlmain.py 2011-04-23 08:41:27 +0000
282@@ -282,9 +282,9 @@
283 self.mode = modes[name]
284
285 def bind_key(key, name):
286- import new
287+ import types
288 if callable(name):
289- modes[mode]._bind_key(key, new.instancemethod(name, modes[mode], modes[mode].__class__))
290+ modes[mode]._bind_key(key, types.MethodType(name, modes[mode]))
291 elif hasattr(modes[mode], name):
292 modes[mode]._bind_key(key, getattr(modes[mode], name))
293 else:
294
295=== modified file 'pyreadline/test/test_emacs.py'
296--- pyreadline/test/test_emacs.py 2010-07-20 16:30:15 +0000
297+++ pyreadline/test/test_emacs.py 2011-04-23 08:41:27 +0000
298@@ -9,12 +9,12 @@
299
300 import sys, unittest
301 import pdb
302-sys.path.append (u'../..')
303+sys.path.insert(0, u'../..')
304 from pyreadline.modes.emacs import *
305 from pyreadline import keysyms
306 from pyreadline.lineeditor import lineobj
307
308-from common import *
309+from pyreadline.test.common import *
310 from pyreadline.logger import log
311 import pyreadline.logger as logger
312 logger.sock_silent=True
313
314=== modified file 'pyreadline/test/test_vi.py'
315--- pyreadline/test/test_vi.py 2010-07-20 17:12:13 +0000
316+++ pyreadline/test/test_vi.py 2011-04-23 08:41:27 +0000
317@@ -7,15 +7,15 @@
318 #*****************************************************************************
319
320 import sys, unittest,pdb
321-sys.path.append (u'../..')
322+sys.path.insert(0, u'../..')
323 from pyreadline.modes.vi import *
324 from pyreadline import keysyms
325 from pyreadline.lineeditor import lineobj
326 from pyreadline.logger import log
327 import pyreadline.logger as logger
328-from common import *
329+from pyreadline.test.common import *
330
331-from common import *
332+from pyreadline.test.common import *
333 #----------------------------------------------------------------------
334
335 class ViModeTest (ViMode):
336
337=== modified file 'pyreadline/unicode_helper.py'
338--- pyreadline/unicode_helper.py 2010-07-15 16:23:16 +0000
339+++ pyreadline/unicode_helper.py 2011-04-23 08:41:27 +0000
340@@ -17,9 +17,14 @@
341 if pyreadline_codepage is None:
342 pyreadline_codepage = u"ascii"
343
344+if sys.version_info < (2, 6):
345+ bytes = str
346+
347+PY3 = (sys.version_info >= (3, 0))
348+
349 def ensure_unicode(text):
350 u"""helper to ensure that text passed to WriteConsoleW is unicode"""
351- if isinstance(text, str):
352+ if isinstance(text, bytes):
353 try:
354 return text.decode(pyreadline_codepage, u"replace")
355 except (LookupError, TypeError):
356@@ -34,3 +39,9 @@
357 except (LookupError, TypeError):
358 return text.encode(u"ascii", u"replace")
359 return text
360+
361+def biter(text):
362+ if PY3 and isinstance(text, bytes):
363+ return (s.to_bytes(1, 'big') for s in text)
364+ else:
365+ return iter(text)
366
367=== modified file 'setup.py'
368--- setup.py 2010-07-19 17:09:00 +0000
369+++ setup.py 2011-04-23 08:41:27 +0000
370@@ -9,6 +9,7 @@
371 #*****************************************************************************
372
373 import os
374+import sys
375 import glob
376
377 # BEFORE importing distutils, remove MANIFEST. distutils doesn't properly
378@@ -16,8 +17,25 @@
379 if os.path.exists('MANIFEST'): os.remove('MANIFEST')
380 #
381
382-from distutils.core import setup
383-execfile('pyreadline/release.py')
384+extra = {}
385+_distribute = False
386+
387+try:
388+ import setuptools
389+ setup = setuptools.setup
390+ _distribute = getattr(setuptools, '_distribute', False)
391+except ImportError:
392+ from distutils.core import setup
393+
394+if sys.version_info >= (3, 0):
395+ if _distribute == False:
396+ raise RuntimeError('You must installed `distribute` to setup pyreadline with Python3')
397+
398+ extra.update(
399+ use_2to3=True
400+ )
401+
402+exec(compile(open('pyreadline/release.py').read(), 'pyreadline/release.py', 'exec'))
403
404 try:
405 import sphinx
406@@ -50,5 +68,6 @@
407 package_data = {'pyreadline':['configuration/*']},
408 data_files = [],
409 cmdclass = cmd_class,
410+ **extra
411 )
412

Subscribers

People subscribed via source and target branches

to all changes:
to status/vote changes: