Return Context Manager for a file-like (stream) object to store a diff.
559848
def receive(self, diff, paths):
        
        path = self.selectReceivePath(paths)
        path = self._relativePath(path)

        if Store.skipDryRun(logger, self.dryrun)("receive to %s", path):
            return None

        (diffTo, diffFrom) = self.toArg.diff(diff)
        self._client.receive(path, diffTo, diffFrom)

        progress = DisplayProgress(diff.size) if self.showProgress is True else None
        return _SSHStream(self._client, progress)
124844
function Context(name, files, ignore) {
    this.name = name;
    this.files = files || {};
    this.ingore = ignore || [];
}
121178
@NonNull
  public static File getFile(@NonNull Context context, @NonNull String fileName) {
    return new File(context.getFilesDir(), fileName);
  }
671963
def stream(self, name):
        
        if self.stream_name != "default":
            raise ValueError("Nested streams aren't supported")
        if self._streams.get(name) == None:
            self._streams[name] = History(self.fname, out_dir=self.out_dir,
                                          add_callback=self._add_callback, stream_name=name)
        return self._streams[name]
574968
def __getFileObj(self, f):
        """"""
        if not f:
            raise ShapefileException("Shapefile Reader requires a shapefile or file-like object.")
        if self.shp and self.shpLength is None:
            self.load()
        if self.dbf and len(self.fields) == 0:
            self.load()
        return f
890950
def _full_diff(merge_result, key, context_lines=3):
    """"""
    header_printed = False
    for group in _split_diff(merge_result, context_lines=context_lines):
        if not header_printed:
            header_printed = True
            yield color.Header('diff a/%s b/%s' % (key, key))
            yield color.DeletedHeader('--- %s' % key)
            yield color.AddedHeader('+++ %s' % key)

        for l in _diff_group(group):
            yield l
619845
def cache_context(self, context):
        '''
        
        '''
        if not os.path.isdir(os.path.dirname(self.cache_path)):
            os.mkdir(os.path.dirname(self.cache_path))
        with salt.utils.files.fopen(self.cache_path, 'w+b') as cache:
            self.serial.dump(context, cache)
1305902
def diff(local_path, remote_path):
    """"""
    with hide('commands'):
        if isinstance(local_path, basestring):
            with open(local_path) as stream:
                local_content = stream.read()
        else:
            pos = local_path.tell()
            local_content = local_path.read()
            local_path.seek(pos)
        remote_content = StringIO()
        with settings(hide('warnings'), warn_only=True):
            if get(remote_path, remote_content).failed:
                return True
        return local_content.strip() != remote_content.getvalue().strip()
943152
def parse(self, stream):
        """"""
        yaml = self._load_yaml()

        try:
            parsed_obj = yaml.safe_load(stream)
        except Exception as e:
            raise ConfigFileParserException("Couldn't parse config file: %s" % e)

        if not isinstance(parsed_obj, dict):
            raise ConfigFileParserException("The config file doesn't appear to "
                "contain 'key: value' pairs (aka. a YAML mapping). "
                "yaml.load('%s') returned type '%s' instead of 'dict'." % (
                getattr(stream, 'name', 'stream'),  type(parsed_obj).__name__))

        result = OrderedDict()
        for key, value in parsed_obj.items():
            if isinstance(value, list):
                result[key] = value
            else:
                result[key] = str(value)

        return result
118128
def _normalize_compare_config(self, diff):
        """"""
        ignore_strings = [
            "Contextual Config Diffs",
            "No changes were found",
            "ntp clock-period",
        ]
        if self.auto_file_prompt:
            ignore_strings.append("file prompt quiet")

        new_list = []
        for line in diff.splitlines():
            for ignore in ignore_strings:
                if ignore in line:
                    break
            else:  # nobreak
                new_list.append(line)
        return "\n".join(new_list)
82890
def diff(self, obj=None):
        """"""
        if self.no_resource:
            return NOOP

        if not self.present:
            if self.existing:
                return DEL

            return NOOP

        if not obj:
            obj = self.obj()

        is_diff = NOOP
        if self.present and self.existing:
            if isinstance(self.existing, dict):
                current = dict(self.existing)
                if 'refresh_interval' in current:
                    del current['refresh_interval']

                if diff_dict(current, obj):
                    is_diff = CHANGED
            elif is_unicode(self.existing):
                if self.existing != obj:
                    is_diff = CHANGED

        elif self.present and not self.existing:
            is_diff = ADD

        return is_diff
713932
def diff(self):
        """"""

        if not self.present:
            if self.existing:
                return DEL

            return NOOP

        is_diff = NOOP
        if self.present and self.existing:
            a_obj = self.config.copy()
            if self.config and diff_dict(a_obj, self.existing, True):
                is_diff = CHANGED

            if self.description != self.existing.get('description'):
                is_diff = CONFLICT

        elif self.present and not self.existing:
            is_diff = ADD

        return is_diff
237219
@TargetApi(Build.VERSION_CODES.FROYO)
    public static File getExternalFilesDirForDcim(Context context) {
        return context.getExternalFilesDir(Environment.DIRECTORY_DCIM);
    }
398120
def build_stack_changes(stack_name, new_stack, old_stack, new_params,
                        old_params):
    """"""
    from_file = "old_%s" % (stack_name,)
    to_file = "new_%s" % (stack_name,)
    lines = difflib.context_diff(
        old_stack, new_stack,
        fromfile=from_file, tofile=to_file,
        n=7)  # ensure at least a few lines of context are displayed afterward

    template_changes = list(lines)
    log_lines = []
    if not template_changes:
        log_lines.append("*** No changes to template ***")
    param_diffs = diff_parameters(old_params, new_params)
    if param_diffs:
        log_lines.append(format_params_diff(param_diffs))
    if template_changes:
        log_lines.append("".join(template_changes))
    return log_lines
1189612
def ngram_diff(args, parser):
    """"""
    store = utils.get_data_store(args)
    corpus = utils.get_corpus(args)
    catalogue = utils.get_catalogue(args)
    tokenizer = utils.get_tokenizer(args)
    store.validate(corpus, catalogue)
    if args.asymmetric:
        store.diff_asymmetric(catalogue, args.asymmetric, tokenizer,
                              sys.stdout)
    else:
        store.diff(catalogue, tokenizer, sys.stdout)
156920
def diff_files(from_file, to_file, index_columns, sep=',', ignored_columns=None):
    
    with open(from_file) as from_stream:
        with open(to_file) as to_stream:
            from_records = records.load(from_stream, sep=sep)
            to_records = records.load(to_stream, sep=sep)
            return patch.create(from_records, to_records, index_columns,
                                ignore_columns=ignored_columns)
1229381
function getStreamStream (readable, file) {
  return () => {
    const counter = new stream.Transform()
    counter._transform = function (buf, enc, done) {
      file.length += buf.length
      this.push(buf)
      done()
    }
    readable.pipe(counter)
    return counter
  }
}