diff options
author | Phil Schaf <flying-sheep@web.de> | 2013-11-24 10:48:01 +0000 |
---|---|---|
committer | Phil Schaf <flying-sheep@web.de> | 2013-11-24 10:48:01 +0000 |
commit | a151d5467ce042f903ebc1a166a37fba5ec7d0d5 (patch) | |
tree | a2637eb4e6fc008621185ecf182386957a05a484 | |
parent | 17873292c1ca977827e0bea480113b8aff053587 (diff) | |
download | astroid-a151d5467ce042f903ebc1a166a37fba5ec7d0d5.tar.gz |
added file_bytes to Module to allow file_stream to be retrieved from it
-rw-r--r-- | scoped_nodes.py | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/scoped_nodes.py b/scoped_nodes.py index 0ee29be..223c2d7 100644 --- a/scoped_nodes.py +++ b/scoped_nodes.py @@ -24,6 +24,7 @@ from __future__ import with_statement __doctype__ = "restructuredtext en" import sys +from io import BytesIO from itertools import chain from logilab.common.compat import builtins @@ -217,6 +218,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 +248,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 |