2
2
3
3
import bz2
4
4
import codecs
5
+ from collections .abc import Iterator
5
6
import gzip
6
7
from io import BufferedIOBase , BytesIO
7
8
import mmap
49
50
_VALID_URLS .discard ("" )
50
51
51
52
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
-
64
53
def is_url (url ) -> bool :
65
54
"""
66
55
Check to see if a URL has a valid protocol.
@@ -515,7 +504,7 @@ def closed(self):
515
504
return self .fp is None
516
505
517
506
518
- class _MMapWrapper (BaseIterator ):
507
+ class _MMapWrapper (Iterator ):
519
508
"""
520
509
Wrapper for the Python's mmap class so that it can be properly read in
521
510
by Python's csv.reader class.
@@ -552,7 +541,7 @@ def __next__(self) -> str:
552
541
return newline
553
542
554
543
555
- class UTF8Recoder (BaseIterator ):
544
+ class UTF8Recoder (Iterator ):
556
545
"""
557
546
Iterator that reads an encoded stream and re-encodes the input to UTF-8
558
547
"""
@@ -566,7 +555,7 @@ def read(self, bytes: int = -1) -> bytes:
566
555
def readline (self ) -> bytes :
567
556
return self .reader .readline ().encode ("utf-8" )
568
557
569
- def next (self ) -> bytes :
558
+ def __next__ (self ) -> bytes :
570
559
return next (self .reader ).encode ("utf-8" )
571
560
572
561
def close (self ):
0 commit comments