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

Commit0c54d08

Browse files
committed
Update python3 support.Fixpython-mode#437
1 parentca0078b commit0c54d08

File tree

7 files changed

+105
-25
lines changed

7 files changed

+105
-25
lines changed

‎pymode/__init__.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ class Options(object):
2929

3030
defget_documentation():
3131
""" Search documentation and append to current buffer. """
32-
try:
33-
fromStringIOimportStringIO
34-
exceptImportError:
35-
fromioimportStringIO
32+
from ._compatimportStringIO
3633

3734
sys.stdout,_=StringIO(),sys.stdout
3835
help(vim.eval('a:word'))

‎pymode/_compat.py

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
""" Compatibility.
2+
3+
Some py2/py3 compatibility support based on a stripped down
4+
version of six so we don't have to depend on a specific version
5+
of it.
6+
7+
:copyright: (c) 2014 by Armin Ronacher.
8+
:license: BSD
9+
"""
10+
importsys
11+
12+
PY2=sys.version_info[0]==2
13+
_identity=lambdax:x
14+
15+
16+
ifnotPY2:
17+
text_type=str
18+
string_types= (str,)
19+
integer_types= (int, )
20+
21+
iterkeys=lambdad:iter(d.keys())
22+
itervalues=lambdad:iter(d.values())
23+
iteritems=lambdad:iter(d.items())
24+
25+
fromioimportStringIO
26+
fromqueueimportQueue# noqa
27+
28+
defreraise(tp,value,tb=None):
29+
ifvalue.__traceback__isnottb:
30+
raisevalue.with_traceback(tb)
31+
raisevalue
32+
33+
implements_to_string=_identity
34+
35+
else:
36+
text_type=unicode
37+
string_types= (str,unicode)
38+
integer_types= (int,long)
39+
40+
iterkeys=lambdad:d.iterkeys()
41+
itervalues=lambdad:d.itervalues()
42+
iteritems=lambdad:d.iteritems()
43+
44+
fromcStringIOimportStringIO
45+
fromQueueimportQueue
46+
47+
exec('def reraise(tp, value, tb=None):\n raise tp, value, tb')
48+
49+
defimplements_to_string(cls):
50+
cls.__unicode__=cls.__str__
51+
cls.__str__=lambdax:x.__unicode__().encode('utf-8')
52+
returncls
53+
54+
55+
defwith_metaclass(meta,*bases):
56+
# This requires a bit of explanation: the basic idea is to make a
57+
# dummy metaclass for one level of class instantiation that replaces
58+
# itself with the actual metaclass. Because of internal type checks
59+
# we also need to make sure that we downgrade the custom metaclass
60+
# for one level to something closer to type (that's why __call__ and
61+
# __init__ comes back from type etc.).
62+
#
63+
# This has the advantage over six.with_metaclass in that it does not
64+
# introduce dummy classes into the final MRO.
65+
classmetaclass(meta):
66+
__call__=type.__call__
67+
__init__=type.__init__
68+
def__new__(cls,name,this_bases,d):
69+
ifthis_basesisNone:
70+
returntype.__new__(cls,name, (),d)
71+
returnmeta(name,bases,d)
72+
returnmetaclass('temporary_class',None, {})
73+
74+
75+
# Certain versions of pypy have a bug where clearing the exception stack
76+
# breaks the __exit__ function in a very peculiar way. This is currently
77+
# true for pypy 2.2.1 for instance. The second level of exception blocks
78+
# is necessary because pypy seems to forget to check if an exception
79+
# happend until the next bytecode instruction?
80+
BROKEN_PYPY_CTXMGR_EXIT=False
81+
ifhasattr(sys,'pypy_version_info'):
82+
class_Mgr(object):
83+
def__enter__(self):
84+
returnself
85+
def__exit__(self,*args):
86+
sys.exc_clear()
87+
try:
88+
try:
89+
with_Mgr():
90+
raiseAssertionError()
91+
except:
92+
raise
93+
exceptTypeError:
94+
BROKEN_PYPY_CTXMGR_EXIT=True
95+
exceptAssertionError:
96+
pass
97+
98+
# pylama:skip=1

‎pymode/async.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
""" Python-mode async support. """
22

3-
try:
4-
fromQueueimportQueue
5-
exceptImportError:
6-
fromqueueimportQueue# noqa
3+
from ._compatimportQueue
74

85

96
RESULTS=Queue()

‎pymode/environment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
importtime
88
importos.path
99

10-
from .utilsimportPY2
10+
from ._compatimportPY2
1111

1212

1313
classVimPymodeEnviroment(object):

‎pymode/rope.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@
66
importre
77
importsite
88
importsys
9-
importStringIO
109

1110
fromrope.baseimportproject,libutils,exceptions,change,worder# noqa
1211
fromrope.base.fscommandsimportFileSystemCommands# noqa
1312
fromrope.base.taskhandleimportTaskHandle# noqa
1413
fromrope.contribimportautoimportasrope_autoimport,codeassist,findit,generate# noqa
1514
fromrope.refactorimportModuleToPackage,ImportOrganizer,rename,extract,inline,usefunction,move,change_signature,importutils# noqa
1615

17-
16+
from ._compatimportStringIO
1817
from .environmentimportenv
1918

2019

‎pymode/run.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
""" Code runnning support. """
2-
3-
try:
4-
fromStringIOimportStringIO
5-
exceptImportError:
6-
fromioimportStringIO
7-
82
importsys
3+
fromreimportcompileasre
94

5+
from ._compatimportStringIO
106
from .environmentimportenv
11-
fromreimportcompileasre
127

138

149
encoding=re(r'#[^\w]+coding:\s+utf.*$')

‎pymode/utils.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,10 @@
66
fromcontextlibimportcontextmanager
77

88
importvim# noqa
9-
10-
11-
try:
12-
fromStringIOimportStringIO
13-
exceptImportError:
14-
fromioimportStringIO
9+
from ._compatimportStringIO,PY2
1510

1611

1712
DEBUG=int(vim.eval('g:pymode_debug'))
18-
PY2=sys.version_info[0]==2
1913

2014
warnings.filterwarnings('ignore')
2115

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp