Parses the file at filename and returns a PythonFile.

    If root is specified, it will open the file with root prepended to the path. The idea is to
    allow for errors to contain a friendlier file path than the full absolute path.
10761
def parse(cls, filename, root=None):
    
    if root is not None:
      if os.path.isabs(filename):
        raise ValueError("filename must be a relative path if root is specified")
      full_filename = os.path.join(root, filename)
    else:
      full_filename = filename

    with io.open(full_filename, 'rb') as fp:
      blob = fp.read()

    tree = cls._parse(blob, filename)
    return cls(blob=blob, tree=tree, root=root, filename=filename)
81137
def load(root_file, use_proxy=True, key=None):
    
    if isinstance(root_file, string_types):
        root_file = root_open(root_file)
        own_file = True
    else:
        own_file = False
    obj = Unpickler(root_file, use_proxy).load(key)
    if own_file:
        root_file.Close()
    return obj
1094137
def get(cls, filename):
        
        path = os.path.join(SparkFiles.getRootDirectory(), filename)
        return os.path.abspath(path)
754197
def _load_file(path):
    
    if not os.path.exists(path):
        parser.error("{} was not found!".format(path))
    if USING_PYTHON2:
        mode = "r"
    else:
        mode = "rb"
    try:
        f = open(path, mode)
        return f
    except IOError as ex:
        parser.error("{path} could not be read due to an I/O error! ({ex})".format(path=path, ex=ex))
29836
def from_path(cls, path: pathlib.Path) -> 'File':
        
        if not path.is_file():
            raise ValueError('Path does not point to a file')
        return File(path.name, path.stat().st_size, cls._md5(path))
1091901
def file(value, **kwarg):
    
    #a bit weird, but I don't want to hard code default values
    try:
        f = open(value, **kwarg)
    except IOError as e:
        raise ValueError("unable to open %s : %s" % (path.abspath(value), e))
    return f
259381
def _parse(self):
        
        with open(self.path, "rt") as reader:
            return ast.parse(reader.read(), filename=self.path)
148284
def read_file(self, filepath=None, filename=None):
        
        name = filename if filename else self.filename
        path = filepath if filepath else self.filepath
        name = self._ends_with(name, ".json")
        path = self._ends_with(path, os.path.sep)

        try:
            return self._read_json(path, name)
        except EnvironmentError as error:
            self.logger.error("Error while opening or reading the file: {}".format(error))
            raise
        except ValueError as error:
            self.logger.error("File contents cannot be decoded to JSON: {}".format(error))
            raise
811634
def load(self, filename):
        
        #if LXE and self.mode != Mode.XPATH:
        #    #workaround for xml:id problem (disabled)
        #    #f = open(filename)
        #    #s = f.read().replace(' xml:id=', ' id=')
        #    #f.close()
        #    self.tree = ElementTree.parse(filename)
        #else:
        self.tree = xmltreefromfile(filename)
        self.parsexml(self.tree.getroot())
        if self.mode != Mode.XPATH:
            #XML Tree is now obsolete (only needed when partially loaded for xpath queries)
            self.tree = None
1032513
def load_parameter_file(file_path, name = ''):
    
    if not os.path.exists(file_path):
        raise ValueError("{} doest not exist".format(file_path))
    if os.path.isdir(file_path):
        return ParameterNode(name, directory_path = file_path)
    data = _load_yaml_file(file_path)
    return _parse_child(name, data, file_path)
859682
def _read_xml_file(self):
        
        # this raises a IOError if the file doesn't exist
        root = ElementTree.parse(self.xml_uri)
        root.getroot()
        return root
31741
def parse_file(self, filename, skip_unreadable=False):
        
        if not os.access(filename, os.R_OK):
            if skip_unreadable:
                return
            raise ConfigReadingError("Unable to open file %s." % filename)
        with open(filename, 'rt') as f:
            return self.parse(f, name_hint=filename)
841771
def parse_file(self, name):
        
        with open(name, "rb") as fp:
            return self.parse(fp.read())
687276
def readfile(filename):
    
    with open(path_expand(filename), 'r') as f:
        content = f.read()
    return content
712524
def from_filename(cls, path_string, origin=MISSING, **kwargs):
        
        path = Path(path_string)
        return cls.from_path(path, origin, **kwargs)
1006679
def read_file(filename):
    """"""
    path = os.path.abspath(os.path.dirname(__file__))
    filepath = os.path.join(path, filename)
    try:
        return open(filepath).read()
    except IOError:
        return ''
1040190
def GetRealPath(filename):
  
  if os.path.isabs(filename):                # already absolute
    return filename

  if filename.startswith('./') or  filename.startswith('../'): # relative
    return os.path.abspath(filename)

  path = os.getenv('PATH', '')
  for directory in path.split(':'):
    tryname = os.path.join(directory, filename)
    if os.path.exists(tryname):
      if not os.path.isabs(directory):  # relative directory
        return os.path.abspath(tryname)
      return tryname
  if os.path.exists(filename):
    return os.path.abspath(filename)
  return None