* started create paralell get_code

This commit is contained in:
Jean-Louis Fuchs
2013-12-12 22:11:15 +01:00
parent 0e00aa103f
commit 53e4962711
2 changed files with 49 additions and 3 deletions

View File

@@ -46,6 +46,15 @@ from jedi import common
from jedi import debug
class GetCodeState(object):
"""A helper class for passing the state of get_code in a thread-safe
manner"""
__slots__ = ("last_pos")
def __init__(self):
self.last_pos = (0, 0)
class Base(object):
"""
This is just here to have an isinstance check, which is also used on
@@ -60,6 +69,29 @@ class Base(object):
def isinstance(self, *cls):
return isinstance(self, cls)
@property
def newline(self):
"""Returns the newline type for the current code."""
#TODO: we need newline detection
return "\n"
@property
def whitespace(self):
"""Returns the whitespace type for the current code: tab or space."""
#TODO: we need tab detection
return " "
def space(self, from_pos, to_pos):
"""Return the space between two tokens"""
linecount = to_pos[0] - from_pos[0]
if linecount == 0:
return self.whitespace * (to_pos[1] - from_pos[1])
else:
return "%s%s" % (
self.newline * linecount,
self.whitespace * to_pos[1],
)
class Simple(Base):
"""
@@ -191,6 +223,10 @@ class Scope(Simple, IsScope):
i += s.get_imports()
return i
def get_code2(self, state=GetCodeState()):
string = []
return "".join(string)
def get_code(self, first_indent=False, indention=' '):
"""
:return: Returns the code of the current scope.

View File

@@ -2,11 +2,18 @@ import jedi.parser as parser
import difflib
code_basic_features = '''
"""A mod docstring"""
def a_function(a_argument, a_default = "default"):
"""A docstring"""
"""A func docstring"""
a_result = 3 * a_argument
print(a_result) # a comment
b = """
from
to""" + "huhu"
if a_default == "default":
return str(a_result)
else
@@ -22,7 +29,10 @@ def diff_code_assert(a, b, n=4):
n=n,
lineterm=""
))
assert False, "Code does not match:\n%s" % diff
assert False, "Code does not match:\n%s\n\ncreated code:\n%s" % (
diff,
b
)
pass
@@ -32,5 +42,5 @@ def test_basic_parsing():
prs = parser.Parser(code_basic_features)
diff_code_assert(
code_basic_features,
prs.top_module.get_code()
prs.top_module.get_code2()
)