def _init_source(self, pycore, source_code, resource): filename = 'string' if resource: filename = resource.path try: if source_code is None: source_bytes = resource.read_bytes() source_code = fscommands.file_data_to_unicode(source_bytes) else: if isinstance(source_code, unicode): source_bytes = fscommands.unicode_to_file_data(source_code) else: source_bytes = source_code ast_node = ast.parse(source_bytes, filename=filename) except SyntaxError, e: raise exceptions.ModuleSyntaxError(filename, e.lineno, e.msg)
def read(self): data = self.read_bytes() try: return fscommands.file_data_to_unicode(data) except UnicodeDecodeError as e: raise exceptions.ModuleDecodeError(self.path, e.reason)