def __init__(self, filename, *args, **kwargs): self.closing = kwargs.pop('closing', False) if isinstance(filename, six.string_types): self.fh = open_universal_newline(filename, "r") self.closing = True else: self.fh = filename
def read_from_python_file(self, filename): # Evaluates the content of a Python file containing code to set up a # context. # # Args: # filename (str): The name of the file to evaluate. if os.path.isfile(filename): with open_universal_newline(filename, 'r') as f: # This is so that there is a context in the scope of the exec context = self exec(f.read()) return self
def read_from_python_file(self, filename): # Evaluates the content of a Python file containing code to set up a # context. # # Args: # filename (str): The name of the file to evaluate. try: if os.path.isfile(filename): with open_universal_newline(filename, 'r') as f: l = {'context': self, '__file__': os.path.abspath(filename)} exec(f.read(), globals(), l) except Exception as exc: raise InvalidSettingsFileError('Error occured while reading file: %s' % filename, filename=filename, source=exc) return self
def read_from_python_file(self, filename): # Evaluates the content of a Python file containing code to set up a # context. # # Args: # filename (str): The name of the file to evaluate. try: if os.path.isfile(filename): with open_universal_newline(filename, 'r') as f: # This is so that there is a context in the scope of the exec context = self exec(f.read()) except Exception as exc: raise InvalidSettingsFileError('Error occured while reading file: %s' % filename, filename=filename, source=exc) return self