File iterator that uses alternative line terminators.
179450
def zlines(f = None, sep = "\0", osep = None, size = 8192):     # {{{1
  """"""
  if f is None: f = sys.stdin
  if osep is None: osep = sep
  buf = ""
  while True:
    chars = f.read(size)
    if not chars: break
    buf += chars; lines = buf.split(sep); buf = lines.pop()
    for line in lines: yield line + osep
  if buf: yield buf
133820
def iter_code_by_lines(self):
        

        lnt = self.get_linenumbertable()
        if not lnt:
            yield (None, None, self.disassemble())
            return

        lnt_offset = lnt[0][1]

        cur_line = None
        current = None

        for codelet in self.disassemble():
            abs_line = self.get_line_for_offset(codelet[0])

            if cur_line == abs_line:
                current.append(codelet)

            else:
                if cur_line is not None:
                    yield (cur_line, cur_line - lnt_offset, current)
                cur_line = abs_line
                current = [codelet]

        if current:
            yield (cur_line, cur_line - lnt_offset, current)
1138684
def iter_follower_file(fname):
    
    with open(fname, 'rt') as f:
        for line in f:
            parts = line.split()
            if len(parts) > 3:
                yield parts[1].lower(), set(int(x) for x in parts[2:])
144264
def lines_iter(self):
        '''
        
        '''
        # Convert unicode chars to string
        byte_to_string = lambda x: x.strip().decode(u'utf-8') if isinstance(x, bytes) else x.strip()

        # Read the entire contents of the Dockerfile, decoding each line, and return the result as an array
        with open(self.docker_file_path, u'r') as f:
            for line in f:
                yield byte_to_string(line)
188772
def copy_iterator(self):
        
        self.__udiff, iterator_copy = itertools.tee(self.__udiff)
        return iterator_copy
520205
def _make_io_iterator(handle):
    """"""
    name = ctypes.c_char_p()
    desc = ctypes.c_char_p()
    num_args = mx_uint()
    arg_names = ctypes.POINTER(ctypes.c_char_p)()
    arg_types = ctypes.POINTER(ctypes.c_char_p)()
    arg_descs = ctypes.POINTER(ctypes.c_char_p)()

    check_call(_LIB.MXDataIterGetIterInfo( \
            handle, ctypes.byref(name), ctypes.byref(desc), \
            ctypes.byref(num_args), \
            ctypes.byref(arg_names), \
            ctypes.byref(arg_types), \
            ctypes.byref(arg_descs)))
    iter_name = py_str(name.value)

    narg = int(num_args.value)
    param_str = _build_param_doc(
        [py_str(arg_names[i]) for i in range(narg)],
        [py_str(arg_types[i]) for i in range(narg)],
        [py_str(arg_descs[i]) for i in range(narg)])

    doc_str = ('%s\n\n' +
               '%s\n' +
               'Returns\n' +
               '-------\n' +
               'MXDataIter\n'+
               '    The result iterator.')
    doc_str = doc_str % (desc.value, param_str)

    def creator(*args, **kwargs):
        """Create an iterator.
        The parameters listed below can be passed in as keyword arguments.

        Parameters
        ----------
        name : string, required.
            Name of the resulting data iterator.

        Returns
        -------
        dataiter: Dataiter
            The resulting data iterator.
        """
        param_keys = []
        param_vals = []

        for k, val in kwargs.items():
            param_keys.append(k)
            param_vals.append(str(val))
        # create atomic symbol
        param_keys = c_str_array(param_keys)
        param_vals = c_str_array(param_vals)
        iter_handle = DataIterHandle()
        check_call(_LIB.MXDataIterCreateIter(
            handle,
            mx_uint(len(param_keys)),
            param_keys, param_vals,
            ctypes.byref(iter_handle)))

        if len(args):
            raise TypeError('%s can only accept keyword arguments' % iter_name)

        return MXDataIter(iter_handle, **kwargs)

    creator.__name__ = iter_name
    creator.__doc__ = doc_str
    return creator
910468
public static FilesIterator<File> getRelativeIterator(String baseDir) {
		return new FilesIterator<File>(new File(baseDir), Strategy.RELATIVE_FILES);
	}
545106
def _EntriesGenerator(self):
    
    location = getattr(self.path_spec, 'location', None)
    if location is not None:
      paths = self._file_system.GetPaths()

      for path in iter(paths.keys()):
        # Determine if the start of the path is similar to the location string.
        # If not the file the path refers to is not in the same directory.
        if not path or not path.startswith(location):
          continue

        _, suffix = self._file_system.GetPathSegmentAndSuffix(location, path)

        # Ignore anything that is part of a sub directory or the directory
        # itself.
        if suffix or path == location:
          continue

        path_spec_location = self._file_system.JoinPath([path])
        yield fake_path_spec.FakePathSpec(location=path_spec_location)
711002
function iterator(entry, nextIterator) {

        var url = entry.request.url;

        var isLocalUserEntryFile = url.indexOf(options.resourceDomainBase + '/user-entry.js') === 0;
        var isNotBootstrapFiles = url.indexOf(options.resourceDomainBase) !== 0;
        var isServedZipContent = url.indexOf(options.resourceDomainBase + '/zip') === 0;


        // filter out internals
        var isExternalContent =
            url.indexOf('http') === 0 &&
            (isLocalUserEntryFile || isServedZipContent || isNotBootstrapFiles) &&
            url.indexOf('es5-shim.min.js') < 0;

        if (isExternalContent !== true){
            return nextIterator();
        }

        var responseCounter = 2;
        var output = {
            'time': entry.request.time,
            'url': url
        };

        if (harConfig.checkTls && isLocalUserEntryFile !== true && isServedZipContent !== true) {
            responseCounter += 1;
            request(url.replace(/^http:/i,'https:'), requestOptions, tlsHandler);
        }


        request(url, requestOptions, gzipHandler);
        request(url, requestOptionsWithoutGzip, rawHandler);

        function done(err) {
            if (err){
                // errors here might come from gzip or raw handler -
                output.requestError = true;
                output.error = err;
            }

            responseCounter--;
            if (responseCounter <= 0) {
                rawFileData[url] = output;
                nextIterator();
            }
        }

        function tlsHandler(err, res) {
            if (err){
                output.validTls = false;
                output.tlsErrorMessage = err.message;
                output.tlsResponseCode = res && res.statusCode;
                return done();
            }

            output.validTls = !(res && res.statusCode >= 400);
            output.tlsResponseCode = res.statusCode;

            done();
        }

        function rawHandler(err, res, body) {

            if (err || !body){
                return done(err);
            }

            if (res && res.statusCode >= 400){
                return done(new Error('Request error'));
            }

            output.base64Content = body.toString('base64');
            output.unzippedSize = body.length;

            // find compression target
            zlib.gzip(body, function (err, buffer) {
                var compressionPossible = body.length - buffer.length;

                //entry.response.content.compression = compressionPossible;
                output.aproxCompressionPossible = compressionPossible;
                output.aproxCompressedSize = buffer.length;

                done();
            });
        }

        function gzipHandler(err, res, body) {

            if (err || !body){
                //console.log('gzipHandler', err);
                return done(err);
            }

            if (res && res.statusCode >= 400){
                return done(new Error('Request error'));
            }

            // HAr correction phantom sizes are buggy at best.
            // entry.response.bodySize = body.length;
            // entry.response.content.size = body.length;

            output.redirects = res.request.redirects;
            output.contentType = res.headers['content-type'];
            output.contentLength = res.headers['content-length'];
            output.bodyLength = body.length;

            var encoding = res.headers['content-encoding'];
            output.compressed = !! (encoding && (/gzip/i).test(encoding));

            done();
        }

    }
528561
public static FilesIterator<File> getAbsoluteIterator(String baseDir) {
		return new FilesIterator<File>(new File(baseDir), Strategy.FILES);
	}
435589
def _find_terminator(self, iterator):
        
        for line in iterator:
            if not line:
                break
            line = line.strip()
            if line:
                return line
        return b""
1372247
def input_iterator
      return arguments.each unless arguments.empty?
      return IO.foreach(options[:input]) if options[:input]

      $stdin.each_line
    end
1205414
def _line_iter(self, in_handle):
        
        reader = csv.reader(in_handle, dialect="excel-tab")
        for line in reader:
            if len(line) > 0 and line[0]:
                # check for section headers; all uppercase and a single value
                if line[0].upper() == line[0] and "".join(line[1:]) == "":
                    line = [line[0]]
                yield line
919399
def _iterate_lines(self):
        """"""
        self._num_lines = 0
        self._restarts = []
        self._rs_state = []

        ln = 0
        for ln, line in enumerate(self.filehandle):
            line = line.decode("utf-8", "replace")
            if (self._has_level is None and
                    line[28:31].strip() in LogEvent.log_levels and
                    line[31:39].strip() in LogEvent.log_components):
                self._has_level = True

            # find version string (fast check to eliminate most lines)
            if "version" in line[:100]:
                logevent = LogEvent(line)
                restart = self._check_for_restart(logevent)
                if restart:
                    self._restarts.append((restart, logevent))

            if "starting :" in line or "starting:" in line:
                # look for hostname, port
                match = re.search('port=(?P<port>\d+).*host=(?P<host>\S+)',
                                  line)
                if match:
                    self._hostname = match.group('host')
                    self._port = match.group('port')

            """ For 3.0 the "[initandlisten] options:" long entry contained the
                "engine" field if WiredTiger was the storage engine. There were
                only two engines, MMAPv1 and WiredTiger
            """
            if "[initandlisten] options:" in line:
                match = re.search('replSet: "(?P<replSet>\S+)"', line)
                if match:
                    self._repl_set = match.group('replSet')

                match = re.search('engine: "(?P<engine>\S+)"', line)
                if match:
                    self._storage_engine = match.group('engine')
                else:
                    self._storage_engine = 'mmapv1'

            """ For 3.2 the "[initandlisten] options:" no longer contains the
                "engine" field So now we have to look for the "[initandlisten]
                wiredtiger_open config:" which was present in 3.0, but would
                now tell us definitively that wiredTiger is being used
            """
            if "[initandlisten] wiredtiger_open config:" in line:
                self._storage_engine = 'wiredTiger'

            if "command admin.$cmd command: { replSetInitiate:" in line:
                match = re.search('{ _id: "(?P<replSet>\S+)", '
                                  'members: (?P<replSetMembers>[^]]+ ])', line)
                if match:
                    self._repl_set = match.group('replSet')
                    self._repl_set_members = match.group('replSetMembers')

            # Replica set config logging in MongoDB 3.0+
            new_config = ("New replica set config in use: ")
            if new_config in line:
                match = re.search('{ _id: "(?P<replSet>\S+)", '
                                  'version: (?P<replSetVersion>\d+), '
                                  '(protocolVersion: (?P<replSetProtocol>\d+), )?'
                                  'members: (?P<replSetMembers>[^]]+ ])', line)
                if match:
                    self._repl_set = match.group('replSet')
                    self._repl_set_members = match.group('replSetMembers')
                    self._repl_set_protocol = match.group('replSetProtocol')
                    self._repl_set_version = match.group('replSetVersion')

            # if ("is now in state" in line and
            #        next(state for state in states if line.endswith(state))):
            if "is now in state" in line:
                tokens = line.split()
                # 2.6
                if tokens[1].endswith(']'):
                    pos = 4
                else:
                    pos = 5
                host = tokens[pos]
                rs_state = tokens[-1]
                state = (host, rs_state, LogEvent(line))
                self._rs_state.append(state)
                continue

            if "[rsMgr] replSet" in line:
                tokens = line.split()
                if self._hostname:
                    host = self._hostname + ':' + self._port
                else:
                    host = os.path.basename(self.name)
                host += ' (self)'
                if tokens[-1] in self.states:
                    rs_state = tokens[-1]
                else:
                    # 2.6
                    if tokens[1].endswith(']'):
                        pos = 2
                    else:
                        pos = 6
                    rs_state = ' '.join(tokens[pos:])

                state = (host, rs_state, LogEvent(line))
                self._rs_state.append(state)
                continue

        self._num_lines = ln + 1

        # reset logfile
        self.filehandle.seek(0)
1093394
function iterator(filename, callback) {
    
    async.forEach(
      
        filters
      
      , function(filter, callback) {
          
          var test
            , regexp
            , matches
            
            , continuation  = filter[1]
            
            , file_path     = path.join(dir_path, filename)
            , emitter
            ;
          
          if (typeof filter[0] === 'string') {
            
            regexp = new RegExp('^' + filter[0] + '$');
            matches = regexp.exec(filename);
            
            checkAndContinue(null, matches);
            
          } else if (filter[0] instanceof RegExp) {
            
            regexp  = filter[0];
            matches = regexp.exec(filename);
            checkAndContinue(null, matches);
            
          } else {
            
            test = filter[0]
            test(filename, file_path, checkAndContinue);
            
          }
          
          function checkAndContinue(err, matches) {
            
            if (err) {
             
              callback(err);
            
            } else if (matches) {
              
              emitter = new FileEventEmitter(file_path);
              
              continuation(emitter, matches, callback);
              
            } else {
              
              callback(null);
              
            }
          
          }
        
        }
        
      , callback
    );
    
  }
482530
def iter_(obj):
    
    if six.PY2:
        file_types = file,  # noqa
    if six.PY3:
        file_types = io.IOBase,
        dict_items = {}.items().__class__
        dict_values = {}.values().__class__
        dict_keys = {}.keys().__class__
        dict_view = (dict_items, dict_values, dict_keys)

    if isinstance(obj, dict):
        return ordered_sequence_iterator(list(obj.keys()))
    if isinstance(obj, file_types):
        return file_iterator(obj)
    if six.PY2:
        if isinstance(obj, (list, tuple)):
            return ordered_sequence_iterator(obj)
        if isinstance(obj, xrange):  # noqa
            return range_iterator(obj)
        if NUMPY_AVAILABLE and isinstance(obj, numpy.ndarray):
            return ordered_sequence_iterator(obj)
    if six.PY3 and isinstance(obj, dict_view):
        return ordered_sequence_iterator(list(obj))
    return iter(obj)
723504
def _get_sorted_iterator(self, iterator):
        
        lines = list(next(iterator))
        if len(lines) < self.max_lines:
            return iter(sorted(lines, key=self.key))

        import tempfile
        tmp_dir = tempfile.mkdtemp()
        fnames = self._split(chain([lines], iterator), tmp_dir)
        return SortedIteratorMerger([unpickle_iter(open(fname, 'rb')) for fname in fnames], self.key)