summaryrefslogtreecommitdiff
path: root/scoped_nodes.py
diff options
context:
space:
mode:
Diffstat (limited to 'scoped_nodes.py')
-rw-r--r--scoped_nodes.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/scoped_nodes.py b/scoped_nodes.py
index d579913a..7141ef71 100644
--- a/scoped_nodes.py
+++ b/scoped_nodes.py
@@ -25,6 +25,10 @@ __doctype__ = "restructuredtext en"
import sys
from itertools import chain
+try:
+ from io import BytesIO
+except ImportError:
+ from cStringIO import StringIO as BytesIO
from logilab.common.compat import builtins
from logilab.common.decorators import cached
@@ -217,6 +221,8 @@ class Module(LocalsDictNodeNG):
# the file from which as been extracted the astroid representation. It may
# be None if the representation has been built from a built-in module
file = None
+ # Alternatively, if built from a string/bytes, this can be set
+ file_bytes = None
# encoding of python source file, so we can get unicode out of it (python2
# only)
file_encoding = None
@@ -245,6 +251,8 @@ class Module(LocalsDictNodeNG):
@property
def file_stream(self):
+ if self.file_bytes is not None:
+ return BytesIO(self.file_bytes)
if self.file is not None:
return open(self.file, 'rb')
return None