Skip to content

Commit

Permalink
updated rope to my fork for python3 #202
Browse files Browse the repository at this point in the history
  • Loading branch information
DonJayamanne committed Aug 4, 2016
1 parent 11435e1 commit 69d73cc
Show file tree
Hide file tree
Showing 26 changed files with 700 additions and 167 deletions.
3 changes: 3 additions & 0 deletions pythonFiles/rope/base/astutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ def _added(self, node, levels):
def _Name(self, node):
self._add_node(node)

def _ExceptHandler(self, node):
self.names.append((node.name, []))

def _Tuple(self, node):
new_levels = []
if self.levels is not None:
Expand Down
21 changes: 13 additions & 8 deletions pythonFiles/rope/base/builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
raw_input = input

import rope.base.evaluate
from rope.base import pynames, pyobjects, arguments, utils, ast
from rope.base.utils import pycompat
from rope.base import pynames, pyobjects, arguments, utils


class BuiltinModule(pyobjects.AbstractModule):
Expand Down Expand Up @@ -271,7 +272,7 @@ def __init__(self, holding=None):
collector('__getitem__', function=self._list_get)
collector('pop', function=self._list_get)
try:
collector('__getslice__', function=self._self_get)
collector('__getslice__', function=self._list_get)
except AttributeError:
pass

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

def _list_get(self, context):
if self.holding is not None:
args = context.get_arguments(['self', 'key'])
if (len(args) > 1 and args[1] is not None and
args[1].get_type() == builtins['slice'].get_object()):
return get_list(self.holding)
return self.holding
return context.get_per_name()

Expand Down Expand Up @@ -414,7 +419,7 @@ def __init__(self, *objects):
if objects:
first = objects[0]
attributes = {
'__getitem__': BuiltinName(BuiltinFunction(first)),
'__getitem__': BuiltinName(BuiltinFunction(first)), # TODO: add slice support
'__getslice__':
BuiltinName(BuiltinFunction(pyobjects.PyObject(self))),
'__new__': BuiltinName(BuiltinFunction(function=self._new_tuple)),
Expand Down Expand Up @@ -656,12 +661,12 @@ def get_name(self):
return 'lambda'

def get_param_names(self, special_args=True):
result = [node.id for node in self.arguments.args
if isinstance(node, ast.Name)]
result = [pycompat.get_ast_arg_arg(node) for node in self.arguments.args
if isinstance(node, pycompat.ast_arg_type)]
if self.arguments.vararg:
result.append('*' + self.arguments.vararg)
result.append('*' + pycompat.get_ast_arg_arg(self.arguments.vararg))
if self.arguments.kwarg:
result.append('**' + self.arguments.kwarg)
result.append('**' + pycompat.get_ast_arg_arg(self.arguments.kwarg))
return result

@property
Expand Down Expand Up @@ -801,4 +806,4 @@ def _input_function(args):
builtin=raw_input)),
}

builtins = BuiltinModule('__builtin__', initial=_initial_builtins)
builtins = BuiltinModule(pycompat.builtins.__name__, initial=_initial_builtins)
28 changes: 12 additions & 16 deletions pythonFiles/rope/base/codeanalyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,31 +129,27 @@ def __call__(self):
i += 1
return result

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

def _analyze_line(self, line):
char = None
for match in self._main_chars.finditer(line):
char = match.group()
i = match.start()
if char in '\'"':
token = None
for match in self._main_tokens.finditer(line):
token = match.group()
if token in ["'''", '"""', "'", '"']:
if not self.in_string:
self.in_string = char
if char * 3 == line[i:i + 3]:
self.in_string = char * 3
elif self.in_string == line[i:i + len(self.in_string)] and \
not (i > 0 and line[i - 1] == '\\' and
not (i > 1 and line[i - 2] == '\\')):
self.in_string = token
elif self.in_string == token:
self.in_string = ''
if self.in_string:
continue
if char == '#':
if token == '#':
break
if char in '([{':
if token in '([{':
self.open_count += 1
elif char in ')]}':
elif token in ')]}':
self.open_count -= 1
if line and char != '#' and line.endswith('\\'):
if line and token != '#' and line.endswith('\\'):
self.continuation = True
else:
self.continuation = False
Expand Down
5 changes: 5 additions & 0 deletions pythonFiles/rope/base/default_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# The default ``config.py``
# flake8: noqa


def set_prefs(prefs):
Expand Down Expand Up @@ -79,6 +80,10 @@ def set_prefs(prefs):
# appear in the importing namespace.
prefs['ignore_bad_imports'] = False

# If `True`, rope will insert new module imports as
# `from <package> import <module>` by default.
prefs['prefer_module_from_imports'] = False

# If `True`, rope will transform a comma list of imports into
# multiple separate import statements when organizing
# imports.
Expand Down
7 changes: 6 additions & 1 deletion pythonFiles/rope/base/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import rope.base.pynames
import rope.base.pyobjects
from rope.base import ast, astutils, exceptions, pyobjects, arguments, worder
from rope.base.utils import pycompat


BadIdentifierError = exceptions.BadIdentifierError
Expand Down Expand Up @@ -290,7 +291,11 @@ def _Subscript(self, node):
self._call_function(node.value, '__getitem__',
[node.slice.value])
elif isinstance(node.slice, ast.Slice):
self._call_function(node.value, '__getslice__')
self._call_function(node.value, '__getitem__',
[node.slice])

def _Slice(self, node):
self.result = self._get_builtin_name('slice')

def _call_function(self, node, function_name, other_args=None):
pyname = eval_node(self.scope, node)
Expand Down
21 changes: 13 additions & 8 deletions pythonFiles/rope/base/fscommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import shutil
import subprocess

import rope.base.utils.pycompat as pycompat

try:
unicode
except NameError:
Expand Down Expand Up @@ -261,23 +263,26 @@ def read_str_coding(source):


def _find_coding(text):
if type(text) == bytes:
coding = b'coding'
else:
coding = "coding"
if isinstance(text, pycompat.str):
text = text.encode('utf-8')
coding = b'coding'
to_chr = chr if pycompat.PY3 else lambda x: x
try:
start = text.index(coding) + len(coding)
if text[start] not in '=:':
if text[start] not in b'=:':
return
start += 1
while start < len(text) and text[start].isspace():
while start < len(text) and to_chr(text[start]).isspace():
start += 1
end = start
while end < len(text):
c = text[end]
if not c.isalnum() and c not in '-_':
if not to_chr(c).isalnum() and c not in b'-_':
break
end += 1
return text[start:end]
result = text[start:end]
if isinstance(result, bytes):
result = result.decode('utf-8')
return result
except ValueError:
pass
4 changes: 2 additions & 2 deletions pythonFiles/rope/base/oi/doa.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def _init_data_receiving(self):
self.receiving_thread.start()

def _receive_information(self):
#temp = open('/dev/shm/info', 'w')
#temp = open('/dev/shm/info', 'wb')
for data in self.receiver.receive_data():
self.analyze_data(data)
#temp.write(str(data) + '\n')
Expand Down Expand Up @@ -128,7 +128,7 @@ def get_send_info(self):
def receive_data(self):
conn, addr = self.server_socket.accept()
self.server_socket.close()
my_file = conn.makefile('r')
my_file = conn.makefile('rb')
while True:
try:
yield pickle.load(my_file)
Expand Down
Loading

0 comments on commit 69d73cc

Please sign in to comment.