forked from VimPlug/jedi
new splitlines implementation to get rid of the ugly splitlines we now have as well as (partially) the issue with form feeds
This commit is contained in:
@@ -86,9 +86,7 @@ class Script(object):
|
||||
with open(path) as f:
|
||||
source = f.read()
|
||||
|
||||
lines = source.splitlines() or ['']
|
||||
if source and source[-1] == '\n':
|
||||
lines.append('')
|
||||
lines = common.splitlines(source)
|
||||
line = max(len(lines), 1) if line is None else line
|
||||
if not (0 < line <= len(lines)):
|
||||
raise ValueError('`line` parameter is not in a valid range.')
|
||||
|
||||
@@ -146,3 +146,13 @@ def source_to_unicode(source, encoding=None):
|
||||
|
||||
# cast to unicode by default
|
||||
return unicode(source, detect_encoding(), 'replace')
|
||||
|
||||
|
||||
def splitlines(string):
|
||||
"""
|
||||
A splitlines for Python code. In contrast to Python's ``str.splitlines``,
|
||||
looks at form feeds and other special characters as normal text. Just
|
||||
splits ``\n`` and ``\r\n``.
|
||||
Also different: Returns ``['']`` for an empty string input.
|
||||
"""
|
||||
return re.split('\n|\r\n', string)
|
||||
|
||||
Reference in New Issue
Block a user