Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit52d05f1

Browse files
committed
A first step towards Python 3 support.
Please note that it requires Pygments > 1.0 and some things might not work yet.
1 parent171eb8e commit52d05f1

File tree

4 files changed

+52
-19
lines changed

4 files changed

+52
-19
lines changed

‎bpython/cli.py‎

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ def log(x):
7777
f=open('/tmp/bpython.log','a')
7878
f.write('%s\n'% (x,))
7979

80+
py3=sys.version_info[0]==3
8081
orig_stdout=sys.__stdout__
8182
stdscr=None
8283

@@ -205,7 +206,10 @@ def readline(self):
205206
finally:
206207
curses.raw(False)
207208

208-
returnbuffer.encode(getpreferredencoding())
209+
ifpy3:
210+
returnbuffer
211+
else:
212+
returnbuffer.encode(getpreferredencoding())
209213

210214
defread(self,x):
211215
pass
@@ -259,7 +263,7 @@ def make_colors():
259263
}
260264
foriinrange(63):
261265
ifi>7:
262-
j=i/8
266+
j=i//8
263267
else:
264268
j=c[OPTS.color_scheme['background']]
265269
curses.init_pair(i+1,i%8,j)
@@ -296,10 +300,11 @@ def __init__(self, locals=None, encoding=sys.getdefaultencoding()):
296300
# Unfortunately code.InteractiveInterpreter is a classic class, so no super()
297301
code.InteractiveInterpreter.__init__(self,locals)
298302

299-
defrunsource(self,source):
300-
source='# coding: %s\n%s'% (self.encoding,
301-
source.encode(self.encoding))
302-
returncode.InteractiveInterpreter.runsource(self,source)
303+
ifnotpy3:
304+
defrunsource(self,source):
305+
source='# coding: %s\n%s'% (self.encoding,
306+
source.encode(self.encoding))
307+
returncode.InteractiveInterpreter.runsource(self,source)
303308

304309
defshowsyntaxerror(self,filename=None):
305310
"""Override the regular handler, the code's copied and pasted from
@@ -374,7 +379,7 @@ def __enter__(self):
374379
# original methods. :-(
375380
# The upshot being that introspecting on an object to display its
376381
# attributes will avoid unwanted side-effects.
377-
iftype_!=types.InstanceType:
382+
ifpy3ortype_!=types.InstanceType:
378383
__getattr__=getattr(type_,'__getattr__',None)
379384
if__getattr__isnotNone:
380385
try:
@@ -795,7 +800,7 @@ def show_list(self, items, topline=None):
795800
shared.wl=0
796801
y,x=self.scr.getyx()
797802
h,w=self.scr.getmaxyx()
798-
down= (y<h/2)
803+
down= (y<h//2)
799804
ifdown:
800805
max_h=h-y
801806
else:
@@ -814,8 +819,8 @@ def lsize():
814819
wl=max(len(i)foriinv_items)+1
815820
ifnotwl:
816821
wl=1
817-
cols= ((max_w-2)/wl)or1
818-
rows=len(v_items)/cols
822+
cols= ((max_w-2)//wl)or1
823+
rows=len(v_items)//cols
819824

820825
ifcols*rows<len(v_items):
821826
rows+=1
@@ -1188,7 +1193,10 @@ def reevaluate(self):
11881193

11891194
self.iy,self.ix=self.scr.getyx()
11901195
forlineinself.history:
1191-
self.stdout_hist+=line.encode(getpreferredencoding())+'\n'
1196+
ifpy3:
1197+
self.stdout_hist+=line+'\n'
1198+
else:
1199+
self.stdout_hist+=line.encode(getpreferredencoding())+'\n'
11921200
self.print_line(line)
11931201
self.s_hist[-1]+=self.f_string
11941202
# I decided it was easier to just do this manually
@@ -1263,7 +1271,10 @@ def repl(self):
12631271
self.h_i=0
12641272
self.history.append(inp)
12651273
self.s_hist[-1]+=self.f_string
1266-
self.stdout_hist+=inp.encode(getpreferredencoding())+'\n'
1274+
ifpy3:
1275+
self.stdout_hist+=inp+'\n'
1276+
else:
1277+
self.stdout_hist+=inp.encode(getpreferredencoding())+'\n'
12671278
# Keep two copies so you can go up and down in the hist:
12681279
ifinp:
12691280
self.rl_hist.append(inp+'\n')
@@ -1303,7 +1314,7 @@ def write(self, s):
13031314
else:
13041315
t=s
13051316

1306-
ifisinstance(t,unicode):
1317+
ifnotpy3andisinstance(t,unicode):
13071318
t=t.encode(getpreferredencoding())
13081319

13091320
ifnotself.stdout_hist:
@@ -1338,7 +1349,7 @@ def echo(self, s, redraw=True):
13381349
uses the formatting method as defined in formatter.py to parse the
13391350
srings. It won't update the screen if it's reevaluating the code (as it
13401351
does with undo)."""
1341-
ifisinstance(s,unicode):
1352+
ifnotpy3andisinstance(s,unicode):
13421353
s=s.encode(getpreferredencoding())
13431354

13441355
a=get_colpair('output')
@@ -1859,7 +1870,8 @@ def get_key(self):
18591870
whileTrue:
18601871
try:
18611872
key+=self.scr.getkey()
1862-
key=key.decode(getpreferredencoding())
1873+
ifnotpy3:
1874+
key=key.decode(getpreferredencoding())
18631875
self.scr.nodelay(False)
18641876
exceptUnicodeDecodeError:
18651877
# Yes, that actually kind of sucks, but I don't see another way to get

‎bpython/keys.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ def __setitem__(self, key, value):
4141
key_dispatch=KeyMap()
4242

4343
# fill dispatch with letters
44-
forcinstring.lowercase:
45-
key_dispatch['C-%s'%c]= (chr(string.lowercase.index(c)+1),'^%s'%c.upper())
44+
forcinstring.ascii_lowercase:
45+
key_dispatch['C-%s'%c]= (chr(string.ascii_lowercase.index(c)+1),
46+
'^%s'%c.upper())
4647

4748
# fill dispatch with cool characters
4849
key_dispatch['C-[']= (chr(27),'^[')

‎data/bpython‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env python
2+
3+
importsys
4+
frombpython.cliimportmain
5+
6+
sys.exit(main())

‎setup.py‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33

4-
fromsetuptoolsimportsetup
4+
55
importglob
66
importos
77
importplatform
88
importre
99
importsys
10+
try:
11+
fromsetuptoolsimportsetup
12+
using_setuptools=True
13+
exceptImportError:
14+
fromdistutils.coreimportsetup
15+
using_setuptools=False
16+
17+
try:
18+
fromdistutils.command.build_pyimportbuild_py_2to3asbuild_py
19+
exceptImportError:
20+
fromdistutils.command.build_pyimportbuild_py
1021

1122
frombpythonimport__version__
1223

24+
1325
ifplatform.system()=='FreeBSD':
1426
man_dir='man'
1527
else:
@@ -38,7 +50,9 @@
3850
'console_scripts': [
3951
'bpython = bpython.cli:main',
4052
],
41-
}
53+
},
54+
scripts= ([]ifusing_setuptoolselse ['data/bpython']),
55+
cmdclass=dict(build_py=build_py)
4256
)
4357

4458
# vim: encoding=utf-8 sw=4 ts=4 sts=4 ai et sta

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp