Skip to content

Commit 69d73cc

Browse files
committed
updated rope to my fork for python3 #202
1 parent 11435e1 commit 69d73cc

26 files changed

+700
-167
lines changed

pythonFiles/rope/base/astutils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ def _added(self, node, levels):
4040
def _Name(self, node):
4141
self._add_node(node)
4242

43+
def _ExceptHandler(self, node):
44+
self.names.append((node.name, []))
45+
4346
def _Tuple(self, node):
4447
new_levels = []
4548
if self.levels is not None:

pythonFiles/rope/base/builtins.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
raw_input = input
77

88
import rope.base.evaluate
9-
from rope.base import pynames, pyobjects, arguments, utils, ast
9+
from rope.base.utils import pycompat
10+
from rope.base import pynames, pyobjects, arguments, utils
1011

1112

1213
class BuiltinModule(pyobjects.AbstractModule):
@@ -271,7 +272,7 @@ def __init__(self, holding=None):
271272
collector('__getitem__', function=self._list_get)
272273
collector('pop', function=self._list_get)
273274
try:
274-
collector('__getslice__', function=self._self_get)
275+
collector('__getslice__', function=self._list_get)
275276
except AttributeError:
276277
pass
277278

@@ -297,6 +298,10 @@ def _self_set(self, context):
297298

298299
def _list_get(self, context):
299300
if self.holding is not None:
301+
args = context.get_arguments(['self', 'key'])
302+
if (len(args) > 1 and args[1] is not None and
303+
args[1].get_type() == builtins['slice'].get_object()):
304+
return get_list(self.holding)
300305
return self.holding
301306
return context.get_per_name()
302307

@@ -414,7 +419,7 @@ def __init__(self, *objects):
414419
if objects:
415420
first = objects[0]
416421
attributes = {
417-
'__getitem__': BuiltinName(BuiltinFunction(first)),
422+
'__getitem__': BuiltinName(BuiltinFunction(first)), # TODO: add slice support
418423
'__getslice__':
419424
BuiltinName(BuiltinFunction(pyobjects.PyObject(self))),
420425
'__new__': BuiltinName(BuiltinFunction(function=self._new_tuple)),
@@ -656,12 +661,12 @@ def get_name(self):
656661
return 'lambda'
657662

658663
def get_param_names(self, special_args=True):
659-
result = [node.id for node in self.arguments.args
660-
if isinstance(node, ast.Name)]
664+
result = [pycompat.get_ast_arg_arg(node) for node in self.arguments.args
665+
if isinstance(node, pycompat.ast_arg_type)]
661666
if self.arguments.vararg:
662-
result.append('*' + self.arguments.vararg)
667+
result.append('*' + pycompat.get_ast_arg_arg(self.arguments.vararg))
663668
if self.arguments.kwarg:
664-
result.append('**' + self.arguments.kwarg)
669+
result.append('**' + pycompat.get_ast_arg_arg(self.arguments.kwarg))
665670
return result
666671

667672
@property
@@ -801,4 +806,4 @@ def _input_function(args):
801806
builtin=raw_input)),
802807
}
803808

804-
builtins = BuiltinModule('__builtin__', initial=_initial_builtins)
809+
builtins = BuiltinModule(pycompat.builtins.__name__, initial=_initial_builtins)

pythonFiles/rope/base/codeanalyze.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -129,31 +129,27 @@ def __call__(self):
129129
i += 1
130130
return result
131131

132-
_main_chars = re.compile(r'[\'|"|#|\\|\[|\]|\{|\}|\(|\)]')
132+
# Doesn't match quotes which are escaped
133+
_main_tokens = re.compile(r'((?<!\\)(\'\'\'|"""|\'|")|#|\[|\]|\{|\}|\(|\))')
133134

134135
def _analyze_line(self, line):
135-
char = None
136-
for match in self._main_chars.finditer(line):
137-
char = match.group()
138-
i = match.start()
139-
if char in '\'"':
136+
token = None
137+
for match in self._main_tokens.finditer(line):
138+
token = match.group()
139+
if token in ["'''", '"""', "'", '"']:
140140
if not self.in_string:
141-
self.in_string = char
142-
if char * 3 == line[i:i + 3]:
143-
self.in_string = char * 3
144-
elif self.in_string == line[i:i + len(self.in_string)] and \
145-
not (i > 0 and line[i - 1] == '\\' and
146-
not (i > 1 and line[i - 2] == '\\')):
141+
self.in_string = token
142+
elif self.in_string == token:
147143
self.in_string = ''
148144
if self.in_string:
149145
continue
150-
if char == '#':
146+
if token == '#':
151147
break
152-
if char in '([{':
148+
if token in '([{':
153149
self.open_count += 1
154-
elif char in ')]}':
150+
elif token in ')]}':
155151
self.open_count -= 1
156-
if line and char != '#' and line.endswith('\\'):
152+
if line and token != '#' and line.endswith('\\'):
157153
self.continuation = True
158154
else:
159155
self.continuation = False

pythonFiles/rope/base/default_config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# The default ``config.py``
2+
# flake8: noqa
23

34

45
def set_prefs(prefs):
@@ -79,6 +80,10 @@ def set_prefs(prefs):
7980
# appear in the importing namespace.
8081
prefs['ignore_bad_imports'] = False
8182

83+
# If `True`, rope will insert new module imports as
84+
# `from <package> import <module>` by default.
85+
prefs['prefer_module_from_imports'] = False
86+
8287
# If `True`, rope will transform a comma list of imports into
8388
# multiple separate import statements when organizing
8489
# imports.

pythonFiles/rope/base/evaluate.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import rope.base.pynames
33
import rope.base.pyobjects
44
from rope.base import ast, astutils, exceptions, pyobjects, arguments, worder
5+
from rope.base.utils import pycompat
56

67

78
BadIdentifierError = exceptions.BadIdentifierError
@@ -290,7 +291,11 @@ def _Subscript(self, node):
290291
self._call_function(node.value, '__getitem__',
291292
[node.slice.value])
292293
elif isinstance(node.slice, ast.Slice):
293-
self._call_function(node.value, '__getslice__')
294+
self._call_function(node.value, '__getitem__',
295+
[node.slice])
296+
297+
def _Slice(self, node):
298+
self.result = self._get_builtin_name('slice')
294299

295300
def _call_function(self, node, function_name, other_args=None):
296301
pyname = eval_node(self.scope, node)

pythonFiles/rope/base/fscommands.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import shutil
1111
import subprocess
1212

13+
import rope.base.utils.pycompat as pycompat
14+
1315
try:
1416
unicode
1517
except NameError:
@@ -261,23 +263,26 @@ def read_str_coding(source):
261263

262264

263265
def _find_coding(text):
264-
if type(text) == bytes:
265-
coding = b'coding'
266-
else:
267-
coding = "coding"
266+
if isinstance(text, pycompat.str):
267+
text = text.encode('utf-8')
268+
coding = b'coding'
269+
to_chr = chr if pycompat.PY3 else lambda x: x
268270
try:
269271
start = text.index(coding) + len(coding)
270-
if text[start] not in '=:':
272+
if text[start] not in b'=:':
271273
return
272274
start += 1
273-
while start < len(text) and text[start].isspace():
275+
while start < len(text) and to_chr(text[start]).isspace():
274276
start += 1
275277
end = start
276278
while end < len(text):
277279
c = text[end]
278-
if not c.isalnum() and c not in '-_':
280+
if not to_chr(c).isalnum() and c not in b'-_':
279281
break
280282
end += 1
281-
return text[start:end]
283+
result = text[start:end]
284+
if isinstance(result, bytes):
285+
result = result.decode('utf-8')
286+
return result
282287
except ValueError:
283288
pass

pythonFiles/rope/base/oi/doa.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def _init_data_receiving(self):
6565
self.receiving_thread.start()
6666

6767
def _receive_information(self):
68-
#temp = open('/dev/shm/info', 'w')
68+
#temp = open('/dev/shm/info', 'wb')
6969
for data in self.receiver.receive_data():
7070
self.analyze_data(data)
7171
#temp.write(str(data) + '\n')
@@ -128,7 +128,7 @@ def get_send_info(self):
128128
def receive_data(self):
129129
conn, addr = self.server_socket.accept()
130130
self.server_socket.close()
131-
my_file = conn.makefile('r')
131+
my_file = conn.makefile('rb')
132132
while True:
133133
try:
134134
yield pickle.load(my_file)

0 commit comments

Comments
 (0)