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

Appearance settings

Commit 0c54d08

Browse filesBrowse files
committed
Update python3 support. Fix python-mode#437
1 parent ca0078b commit 0c54d08
Copy full SHA for 0c54d08

File tree

Expand file treeCollapse file tree

7 files changed

+105
-25
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

7 files changed

+105
-25
lines changed
Open diff view settings
Collapse file

‎pymode/__init__.py‎

Copy file name to clipboardExpand all lines: pymode/__init__.py
+1-4Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ class Options(object):
2929

3030
def get_documentation():
3131
""" Search documentation and append to current buffer. """
32-
try:
33-
from StringIO import StringIO
34-
except ImportError:
35-
from io import StringIO
32+
from ._compat import StringIO
3633

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

‎pymode/_compat.py‎

Copy file name to clipboard
+98Lines 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+
import sys
11+
12+
PY2 = sys.version_info[0] == 2
13+
_identity = lambda x: x
14+
15+
16+
if not PY2:
17+
text_type = str
18+
string_types = (str,)
19+
integer_types = (int, )
20+
21+
iterkeys = lambda d: iter(d.keys())
22+
itervalues = lambda d: iter(d.values())
23+
iteritems = lambda d: iter(d.items())
24+
25+
from io import StringIO
26+
from queue import Queue # noqa
27+
28+
def reraise(tp, value, tb=None):
29+
if value.__traceback__ is not tb:
30+
raise value.with_traceback(tb)
31+
raise value
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 = lambda d: d.iterkeys()
41+
itervalues = lambda d: d.itervalues()
42+
iteritems = lambda d: d.iteritems()
43+
44+
from cStringIO import StringIO
45+
from Queue import Queue
46+
47+
exec('def reraise(tp, value, tb=None):\n raise tp, value, tb')
48+
49+
def implements_to_string(cls):
50+
cls.__unicode__ = cls.__str__
51+
cls.__str__ = lambda x: x.__unicode__().encode('utf-8')
52+
return cls
53+
54+
55+
def with_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+
class metaclass(meta):
66+
__call__ = type.__call__
67+
__init__ = type.__init__
68+
def __new__(cls, name, this_bases, d):
69+
if this_bases is None:
70+
return type.__new__(cls, name, (), d)
71+
return meta(name, bases, d)
72+
return metaclass('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+
if hasattr(sys, 'pypy_version_info'):
82+
class _Mgr(object):
83+
def __enter__(self):
84+
return self
85+
def __exit__(self, *args):
86+
sys.exc_clear()
87+
try:
88+
try:
89+
with _Mgr():
90+
raise AssertionError()
91+
except:
92+
raise
93+
except TypeError:
94+
BROKEN_PYPY_CTXMGR_EXIT = True
95+
except AssertionError:
96+
pass
97+
98+
# pylama:skip=1
Collapse file

‎pymode/async.py‎

Copy file name to clipboard
+1-4Lines 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-
from Queue import Queue
5-
except ImportError:
6-
from queue import Queue # noqa
3+
from ._compat import Queue
74

85

96
RESULTS = Queue()
Collapse file

‎pymode/environment.py‎

Copy file name to clipboardExpand all lines: pymode/environment.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import time
88
import os.path
99

10-
from .utils import PY2
10+
from ._compat import PY2
1111

1212

1313
class VimPymodeEnviroment(object):
Collapse file

‎pymode/rope.py‎

Copy file name to clipboardExpand all lines: pymode/rope.py
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@
66
import re
77
import site
88
import sys
9-
import StringIO
109

1110
from rope.base import project, libutils, exceptions, change, worder # noqa
1211
from rope.base.fscommands import FileSystemCommands # noqa
1312
from rope.base.taskhandle import TaskHandle # noqa
1413
from rope.contrib import autoimport as rope_autoimport, codeassist, findit, generate # noqa
1514
from rope.refactor import ModuleToPackage, ImportOrganizer, rename, extract, inline, usefunction, move, change_signature, importutils # noqa
1615

17-
16+
from ._compat import StringIO
1817
from .environment import env
1918

2019

Collapse file

‎pymode/run.py‎

Copy file name to clipboardExpand all lines: pymode/run.py
+2-7Lines 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-
from StringIO import StringIO
5-
except ImportError:
6-
from io import StringIO
7-
82
import sys
3+
from re import compile as re
94

5+
from ._compat import StringIO
106
from .environment import env
11-
from re import compile as re
127

138

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

‎pymode/utils.py‎

Copy file name to clipboardExpand all lines: pymode/utils.py
+1-7Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,10 @@
66
from contextlib import contextmanager
77

88
import vim # noqa
9-
10-
11-
try:
12-
from StringIO import StringIO
13-
except ImportError:
14-
from io import StringIO
9+
from ._compat import StringIO, 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.