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