Returns a tar with the task definition.

        :param name: Name of the file
        :param contents: Contens of the definition, utf-8
971401
def tar_task_definition(self, name: str, contents: str) -> bytes:
        
        tarstream = BytesIO()
        tar = tarfile.TarFile(fileobj=tarstream, mode='w')
        tarinfo = tarfile.TarInfo(name=name)

        script_bytes = contents.encode("utf-8")

        tarinfo.size = len(script_bytes)
        tarinfo.mtime = int(time.time())
        tar.addfile(tarinfo, BytesIO(script_bytes))
        tar.close()

        return tarstream.getvalue()
583337
private File getTarFile(String name) {
        File hexCache = new File(dotHexCachePath);
        File[] files = hexCache.listFiles(new HexFileNameFilter(name));
        if (files != null && files.length > 0) {
            Arrays.sort(files, Collections.reverseOrder());
            return files[0];
        }
        logger.warn("Couldn't find tar file of {}", name);
        return null;
    }
580185
def contents(self, path):
        
        try:
            out, code, err = self.command_exec(['cat-file', '-p', self.ref_head+':'+path])
            if not code:
                return out.decode('utf-8')
        except Exception:
            pass

        return None
685946
function getDefinition(name) {
  var split      = name.split('::'),
      path       = split[0],
      field      = split[1],
      exported   = (path in require.cache) && require.cache[path].exports,
      definition = !!exported && (field ? exported[field] : exported);
  return !!definition && !!getProto(definition) && definition || null;
}
95436
def get_file(self):
        
        content = self._load()
        if not content:
            return None
        filename = "temporary_file.bin"
        with open(filename, "wb") as file_name:
            file_name.write(content)
        return filename
515802
def load(self, name):
        

        if self.reload:
            self._maybe_purge_cache()

        template = self.cache.get(name)
        if template:
            return template

        path = self.resolve(name)
        if not path:
            raise OSError(errno.ENOENT, "File not found: %s" % name)

        with codecs.open(path, 'r', encoding='UTF-8') as f:
            contents = f.read()
            mtime = os.fstat(f.fileno()).st_mtime

        template = self.load_string(contents, filename=path)
        template.mtime = mtime
        template.path = path

        self.cache[name] = template
        return template
920914
def get_task(self, name):
        
        config = getattr(self, "tasks__{}".format(name))
        if not config:
            raise TaskNotFoundError("Task not found: {}".format(name))
        return TaskConfig(config)
856597
def ReadFile(self, filename):
    
    with io.open(filename, 'r', encoding='utf-8') as file_object:
      for artifact_definition in self.ReadFileObject(file_object):
        yield artifact_definition
693948
def load_task_definition_file(task_def_file):
    """"""
    try:
        with open(task_def_file) as f:
            task_def = yaml.safe_load(f)
    except OSError as e:
        raise BenchExecException("Cannot open task-definition file: " + str(e))
    except yaml.YAMLError as e:
        raise BenchExecException("Invalid task definition: " + str(e))

    if str(task_def.get("format_version")) not in ["0.1", "1.0"]:
        raise BenchExecException(
            "Task-definition file {} specifies invalid format_version '{}'."
            .format(task_def_file, task_def.get("format_version")))

    return task_def
1096995
def taropen(cls, name, mode="r", fileobj=None, **kwargs):
        
        if len(mode) > 1 or mode not in "raw":
            raise ValueError("mode must be 'r', 'a' or 'w'")
        return cls(name, mode, fileobj, **kwargs)
875787
def load_template(name, directory, extension, encoding, encoding_errors):
    
    abs_path = get_abs_template_path(name, directory, extension)
    return load_file(abs_path, encoding, encoding_errors)
492686
function (tplContent, name) {
    if (tplContent) {
      var ret;
      try {
        ret = parser.parse(tplContent, name);
      } catch (err) {
        var e;
        if (err instanceof Error) {
          e = err;
        } else {
          e = new Error(err);
        }
        var errorStr = 'XTemplate error ';
        e.stack = errorStr + e.stack;
        e.message = errorStr + e.message;
        throw e;
      }
      return ret;
    } else {
      return {
        statements: []
      };
    }
  }
1369676
def _stub_task(self, description, tags=None, **kw):
        

        # If whitespace is not removed here, TW will do it when we pass the
        # task to it.
        task = {"description": description.strip()}

        # Allow passing "tags" in as part of kw.
        if 'tags' in kw and tags is None:
            task['tags'] = tags
            del(kw['tags'])

        if tags is not None:
            task['tags'] = tags

        task.update(kw)

        if self._marshal:
            return Task.from_stub(task, udas=self.config.get_udas())

        return task
559682
def get_task(config):
    
    path = os.path.join(config['work_dir'], "task.json")
    message = "Can't read task from {}!\n%(exc)s".format(path)
    contents = load_json_or_yaml(path, is_path=True, message=message)
    return contents
1236077
def content_from_path(path, encoding='utf-8'):
    
    if not os.path.isabs(path) and ':' in path:
        package, path = path.split(':', 1)
        content = resource_string(package, path)
    else:
        path = os.path.expanduser(path)
        with open(path, 'rb') as fh:
            content = fh.read()

    return content.decode(encoding)
1012539
def readme(filename, encoding='utf8'):
    

    with io.open(filename, encoding=encoding) as source:
        return source.read()
508947
def process_contents(self, contents, fname=None):
        
        self.stack = []
        self.dispatch_table = self.default_table.copy()
        self.current_file = fname
        self.tuples = self.tupleize(contents)

        self.initialize_result(fname)
        while self.tuples:
            t = self.tuples.pop(0)
            # Uncomment to see the list of tuples being processed (e.g.,
            # to validate the CPP lines are being translated correctly).
            #print(t)
            self.dispatch_table[t[0]](t)
        return self.finalize_result(fname)