22
33import bz2
44import codecs
5+ from collections .abc import Iterator
56import gzip
67from io import BufferedIOBase , BytesIO
78import mmap
4950_VALID_URLS .discard ("" )
5051
5152
52- class BaseIterator :
53- """Subclass this and provide a "__next__()" method to obtain an iterator.
54- Useful only when the object being iterated is non-reusable (e.g. OK for a
55- parser, not for an in-memory table, yes for its iterator)."""
56-
57- def __iter__ (self ) -> "BaseIterator" :
58- return self
59-
60- def __next__ (self ):
61- raise AbstractMethodError (self )
62-
63-
6453def is_url (url ) -> bool :
6554 """
6655 Check to see if a URL has a valid protocol.
@@ -515,7 +504,7 @@ def closed(self):
515504 return self .fp is None
516505
517506
518- class _MMapWrapper (BaseIterator ):
507+ class _MMapWrapper (Iterator ):
519508 """
520509 Wrapper for the Python's mmap class so that it can be properly read in
521510 by Python's csv.reader class.
@@ -552,7 +541,7 @@ def __next__(self) -> str:
552541 return newline
553542
554543
555- class UTF8Recoder (BaseIterator ):
544+ class UTF8Recoder (Iterator ):
556545 """
557546 Iterator that reads an encoded stream and re-encodes the input to UTF-8
558547 """
@@ -566,7 +555,7 @@ def read(self, bytes: int = -1) -> bytes:
566555 def readline (self ) -> bytes :
567556 return self .reader .readline ().encode ("utf-8" )
568557
569- def next (self ) -> bytes :
558+ def __next__ (self ) -> bytes :
570559 return next (self .reader ).encode ("utf-8" )
571560
572561 def close (self ):
0 commit comments