@@ -64,7 +64,7 @@ def __next__(self):
64
64
raise AbstractMethodError (self )
65
65
66
66
67
- def _is_url (url ) -> bool :
67
+ def is_url (url ) -> bool :
68
68
"""
69
69
Check to see if a URL has a valid protocol.
70
70
@@ -102,7 +102,7 @@ def _expand_user(
102
102
return filepath_or_buffer
103
103
104
104
105
- def _validate_header_arg (header ) -> None :
105
+ def validate_header_arg (header ) -> None :
106
106
if isinstance (header , bool ):
107
107
raise TypeError (
108
108
"Passing a bool to header is invalid. "
@@ -112,7 +112,7 @@ def _validate_header_arg(header) -> None:
112
112
)
113
113
114
114
115
- def _stringify_path (
115
+ def stringify_path (
116
116
filepath_or_buffer : FilePathOrBuffer [AnyStr ],
117
117
) -> FilePathOrBuffer [AnyStr ]:
118
118
"""Attempt to convert a path-like object to a string.
@@ -193,9 +193,9 @@ def get_filepath_or_buffer(
193
193
compression, str,
194
194
should_close, bool)
195
195
"""
196
- filepath_or_buffer = _stringify_path (filepath_or_buffer )
196
+ filepath_or_buffer = stringify_path (filepath_or_buffer )
197
197
198
- if isinstance (filepath_or_buffer , str ) and _is_url (filepath_or_buffer ):
198
+ if isinstance (filepath_or_buffer , str ) and is_url (filepath_or_buffer ):
199
199
req = urlopen (filepath_or_buffer )
200
200
content_encoding = req .headers .get ("Content-Encoding" , None )
201
201
if content_encoding == "gzip" :
@@ -250,7 +250,7 @@ def file_path_to_url(path: str) -> str:
250
250
_compression_to_extension = {"gzip" : ".gz" , "bz2" : ".bz2" , "zip" : ".zip" , "xz" : ".xz" }
251
251
252
252
253
- def _get_compression_method (
253
+ def get_compression_method (
254
254
compression : Optional [Union [str , Mapping [str , str ]]]
255
255
) -> Tuple [Optional [str ], Dict [str , str ]]:
256
256
"""
@@ -283,7 +283,7 @@ def _get_compression_method(
283
283
return compression , compression_args
284
284
285
285
286
- def _infer_compression (
286
+ def infer_compression (
287
287
filepath_or_buffer : FilePathOrBuffer , compression : Optional [str ]
288
288
) -> Optional [str ]:
289
289
"""
@@ -317,7 +317,7 @@ def _infer_compression(
317
317
# Infer compression
318
318
if compression == "infer" :
319
319
# Convert all path types (e.g. pathlib.Path) to strings
320
- filepath_or_buffer = _stringify_path (filepath_or_buffer )
320
+ filepath_or_buffer = stringify_path (filepath_or_buffer )
321
321
if not isinstance (filepath_or_buffer , str ):
322
322
# Cannot infer compression of a buffer, assume no compression
323
323
return None
@@ -338,7 +338,7 @@ def _infer_compression(
338
338
raise ValueError (msg )
339
339
340
340
341
- def _get_handle (
341
+ def get_handle (
342
342
path_or_buf ,
343
343
mode : str ,
344
344
encoding = None ,
@@ -396,12 +396,12 @@ def _get_handle(
396
396
f = path_or_buf
397
397
398
398
# Convert pathlib.Path/py.path.local or string
399
- path_or_buf = _stringify_path (path_or_buf )
399
+ path_or_buf = stringify_path (path_or_buf )
400
400
is_path = isinstance (path_or_buf , str )
401
401
402
- compression , compression_args = _get_compression_method (compression )
402
+ compression , compression_args = get_compression_method (compression )
403
403
if is_path :
404
- compression = _infer_compression (path_or_buf , compression )
404
+ compression = infer_compression (path_or_buf , compression )
405
405
406
406
if compression :
407
407
@@ -421,7 +421,7 @@ def _get_handle(
421
421
422
422
# ZIP Compression
423
423
elif compression == "zip" :
424
- zf = BytesZipFile (path_or_buf , mode , ** compression_args )
424
+ zf = _BytesZipFile (path_or_buf , mode , ** compression_args )
425
425
# Ensure the container is closed as well.
426
426
handles .append (zf )
427
427
if zf .mode == "w" :
@@ -472,7 +472,7 @@ def _get_handle(
472
472
473
473
if memory_map and hasattr (f , "fileno" ):
474
474
try :
475
- wrapped = MMapWrapper (f )
475
+ wrapped = _MMapWrapper (f )
476
476
f .close ()
477
477
f = wrapped
478
478
except Exception :
@@ -485,7 +485,7 @@ def _get_handle(
485
485
return f , handles
486
486
487
487
488
- class BytesZipFile (zipfile .ZipFile , BytesIO ): # type: ignore
488
+ class _BytesZipFile (zipfile .ZipFile , BytesIO ): # type: ignore
489
489
"""
490
490
Wrapper for standard library class ZipFile and allow the returned file-like
491
491
handle to accept byte strings via `write` method.
@@ -518,7 +518,7 @@ def closed(self):
518
518
return self .fp is None
519
519
520
520
521
- class MMapWrapper (BaseIterator ):
521
+ class _MMapWrapper (BaseIterator ):
522
522
"""
523
523
Wrapper for the Python's mmap class so that it can be properly read in
524
524
by Python's csv.reader class.
@@ -537,7 +537,7 @@ def __init__(self, f: IO):
537
537
def __getattr__ (self , name : str ):
538
538
return getattr (self .mmap , name )
539
539
540
- def __iter__ (self ) -> "MMapWrapper " :
540
+ def __iter__ (self ) -> "_MMapWrapper " :
541
541
return self
542
542
543
543
def __next__ (self ) -> str :
0 commit comments