summaryrefslogtreecommitdiff
path: root/astroid/builder.py
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2018-06-03 12:39:07 +0800
committerClaudiu Popa <pcmanticore@gmail.com>2018-06-04 06:52:05 -0700
commita98a76baacf0e77548f8e084b4adf44608e5810b (patch)
tree83e3458b05509f65baa7d9cd1d50b722f97775c9 /astroid/builder.py
parenta4f500b3c960bffd09ec90caa41863a64479487d (diff)
downloadastroid-git-a98a76baacf0e77548f8e084b4adf44608e5810b.tar.gz
Remove some code that's always going to be the same now that we run on Python 3
Diffstat (limited to 'astroid/builder.py')
-rw-r--r--astroid/builder.py43
1 files changed, 8 insertions, 35 deletions
diff --git a/astroid/builder.py b/astroid/builder.py
index 433bd848..dec83674 100644
--- a/astroid/builder.py
+++ b/astroid/builder.py
@@ -12,10 +12,9 @@ The builder is not thread safe and can't be used to parse different sources
at the same time.
"""
-import re
import os
-import sys
import textwrap
+from tokenize import detect_encoding
from astroid._ast import _parse
from astroid import bases
@@ -36,41 +35,15 @@ _TRANSIENT_FUNCTION = '__'
# when calling extract_node.
_STATEMENT_SELECTOR = '#@'
-
-if sys.version_info >= (3, 0):
- from tokenize import detect_encoding
-
- def open_source_file(filename):
- with open(filename, 'rb') as byte_stream:
- encoding = detect_encoding(byte_stream.readline)[0]
- stream = open(filename, 'r', newline=None, encoding=encoding)
- data = stream.read()
- return stream, encoding, data
-
-else:
- _ENCODING_RGX = re.compile(r"\s*#+.*coding[:=]\s*([-\w.]+)")
-
- def _guess_encoding(string):
- """get encoding from a python file as string or return None if not found"""
- # check for UTF-8 byte-order mark
- if string.startswith('\xef\xbb\xbf'):
- return 'UTF-8'
- for line in string.split('\n', 2)[:2]:
- # check for encoding declaration
- match = _ENCODING_RGX.match(line)
- if match is not None:
- return match.group(1)
- return None
-
- def open_source_file(filename):
- """get data for parsing a file"""
- stream = open(filename, 'U')
- data = stream.read()
- encoding = _guess_encoding(data)
- return stream, encoding, data
+MANAGER = manager.AstroidManager()
-MANAGER = manager.AstroidManager()
+def open_source_file(filename):
+ with open(filename, 'rb') as byte_stream:
+ encoding = detect_encoding(byte_stream.readline)[0]
+ stream = open(filename, 'r', newline=None, encoding=encoding)
+ data = stream.read()
+ return stream, encoding, data
def _can_assign_attr(node, attrname):