Yield torrents in range from page_from to page_to
338858
def pages(self, page_from, page_to):
        
        if not all([page_from < self.url.max_page, page_from > 0,
                    page_to <= self.url.max_page, page_to > page_from]):
            raise IndexError("Invalid page numbers")

        size = (page_to + 1) - page_from
        threads = ret = []
        page_list = range(page_from, page_to+1)

        locks = [threading.Lock() for i in range(size)]

        for lock in locks[1:]:
            lock.acquire()

        def t_function(pos):
            """
            Thread function that fetch page for list of torrents
            """
            res = self.page(page_list[pos]).list()
            locks[pos].acquire()
            ret.extend(res)
            if pos != size-1:
                locks[pos+1].release()

        threads = [threading.Thread(target=t_function, args=(i,))
                   for i in range(size)]

        for thread in threads:
            thread.start()

        for thread in threads:
            thread.join()

        for torrent in ret:
            yield torrent
328312
def _iter_withprogress(iterable, progress, log):
    """"""
    before_all = time.time()
    before = before_all
    n = 0
    for i, o in enumerate(iterable):
        yield o
        n = i+1
        if n % progress == 0:
            after = time.time()
            log('%s rows in %.2fs; batch in %.2fs (%d rows/s)'
                % (n, after-before_all, after-before, progress/(after-before)))
            before = after
    after_all = time.time()
    log('%s rows in %.2fs (%d rows/s)'
        % (n, after_all-before_all, n/(after_all-before_all)))
582609
def _items(self):
        
        torrents = map(self._get_torrent, self._get_rows())

        for t in torrents:
            yield t
1083318
def _chunks(self, items, limit):
        
        for i in range(0, len(items), limit):
            yield items[i:i + limit]
319550
def _fetch_page_async(self, page_size, **q_options):
    """"""
    q_options.setdefault('batch_size', page_size)
    q_options.setdefault('produce_cursors', True)
    it = self.iter(limit=page_size + 1, **q_options)
    results = []
    while (yield it.has_next_async()):
      results.append(it.next())
      if len(results) >= page_size:
        break
    try:
      cursor = it.cursor_after()
    except datastore_errors.BadArgumentError:
      cursor = None
    raise tasklets.Return(results, cursor, it.probably_has_next())
1268188
def chunks(arr, size):
    
    for i in _range(0, len(arr), size):
        yield arr[i:i+size]
1063080
def cat(*args)
      in_files = []
      page_ranges = []
      file_handle = "A"
      output = normalize_path args.pop

      args.flatten.compact.each do |in_file|
        if in_file.is_a? Hash
          path = in_file.keys.first
          page_ranges.push *in_file.values.first.map {|range| "#{file_handle}#{range}"}
        else
          path = in_file
          page_ranges.push "#{file_handle}"
        end
        in_files.push "#{file_handle}=#{normalize_path(path)}"
        file_handle.next!
      end

      call_pdftk in_files, 'cat', page_ranges, 'output', output
    end
999871
def iter(self):
        

        page = 1
        fetch_all = True
        url = "{}/{}".format(__endpoint__, self.type.RESOURCE)

        if 'page' in self.params:
            page = self.params['page']
            fetch_all = False

        response = RestClient.get(url, self.params)[self.type.RESOURCE]
        while len(response):
            for item in response:
                yield self.type(item)

            if not fetch_all:
                break
            else:
                page += 1
                self.where(page=page)
            response = RestClient.get(url, self.params)[self.type.RESOURCE]
1285206
def pages
      @pages ||= begin
        from = @page - (@size / 2).ceil
        from = 1 if from < 1
        upto = from + @size - 1

        # Correct +from+ and +to+ if +to+ is more than number of pages
        if upto > pages_count
          from -= (upto - pages_count)
          from = 1 if from < 1
          upto = pages_count
        end

        (from..upto).to_a
      end
    end
942069
def i_batch(items, size):
    
    for items_batch in iter(lambda: tuple(islice(items, size)),
                            tuple()):
        yield items_batch
553773
def get(self, request):
        
        sections = self.generate_sections()

        if self.paginated:
            p = Paginator(sections, 25)

            page = request.GET.get('page')

            try:
                sections = p.page(page)
            except PageNotAnInteger:
                # If page is not an integer, deliver first page.
                sections = p.page(1)
            except EmptyPage:
                # If page is out of range (e.g. 9999), return last page
                # of results.
                sections = p.page(p.num_pages)

            pageUpper = int(p.num_pages) / 2

            try:
                pageLower = int(page) / 2
            except TypeError:
                pageLower = -999
        else:
            pageUpper = None
            pageLower = None

        context = {
            'sections': sections,
            'page_title': self.generate_page_title(),
            'browse_type': self.browse_type,
            'pageUpper': pageUpper,
            'pageLower': pageLower
        }

        return render(
            request,
            self.template_path,
            context
        )
490144
def stream(self, page, limit=None, page_limit=None):
        
        current_record = 1
        current_page = 1

        while page is not None:
            for record in page:
                yield record
                current_record += 1
                if limit and limit is not values.unset and limit < current_record:
                    return

            if page_limit and page_limit is not values.unset and page_limit < current_page:
                return

            page = page.next_page()
            current_page += 1
1166223
def _get_pages(self, locations, project_name):
        # type: (Iterable[Link], str) -> Iterable[HTMLPage]
        
        seen = set()  # type: Set[Link]
        for location in locations:
            if location in seen:
                continue
            seen.add(location)

            page = _get_html_page(location, session=self.session)
            if page is None:
                continue

            yield page
348230
def previous_pages_numbers(self):
        ''
        count = self._previous_pages_count() + 1
        for i in reversed(range(1, count)):
            yield i
887405
def _GenerateChunk(self, length):
    """"""

    while 1:
      to_read = min(length, self.RECV_BLOCK_SIZE)
      if to_read == 0:
        return

      data = self.rfile.read(to_read)
      if not data:
        return

      yield data
      length -= len(data)
793086
def get_targets(conn=None):
    
    targets = RBT
    results = targets.run(conn)
    for item in results:
        yield item
541826
def items(self):
        
        request = get(str(self.url), headers={'User-Agent' : "Magic Browser","origin_req_host" : "thepiratebay.se"})
        root = html.fromstring(request.text)
        items = [self._build_torrent(row) for row in
                 self._get_torrent_rows(root)]
        for item in items:
            yield item