13
13
from abc import ABC , abstractmethod
14
14
from glob import _GlobberBase
15
15
from io import text_encoding
16
- from pathlib ._os import (magic_open , vfspath , ensure_distinct_paths ,
16
+ from pathlib ._os import (vfsopen , vfspath , ensure_distinct_paths ,
17
17
ensure_different_files , copyfileobj )
18
18
from pathlib import PurePath , Path
19
19
from typing import Optional , Protocol , runtime_checkable
@@ -264,18 +264,18 @@ def info(self):
264
264
raise NotImplementedError
265
265
266
266
@abstractmethod
267
- def __open_rb__ (self , buffering = - 1 ):
267
+ def __open_reader__ (self ):
268
268
"""
269
269
Open the file pointed to by this path for reading in binary mode and
270
- return a file object, like open(mode='rb') .
270
+ return a file object.
271
271
"""
272
272
raise NotImplementedError
273
273
274
274
def read_bytes (self ):
275
275
"""
276
276
Open the file in bytes mode, read it, and close the file.
277
277
"""
278
- with magic_open (self , mode = 'rb' , buffering = 0 ) as f :
278
+ with vfsopen (self , mode = 'rb' ) as f :
279
279
return f .read ()
280
280
281
281
def read_text (self , encoding = None , errors = None , newline = None ):
@@ -285,7 +285,7 @@ def read_text(self, encoding=None, errors=None, newline=None):
285
285
# Call io.text_encoding() here to ensure any warning is raised at an
286
286
# appropriate stack level.
287
287
encoding = text_encoding (encoding )
288
- with magic_open (self , mode = 'r' , encoding = encoding , errors = errors , newline = newline ) as f :
288
+ with vfsopen (self , mode = 'r' , encoding = encoding , errors = errors , newline = newline ) as f :
289
289
return f .read ()
290
290
291
291
@abstractmethod
@@ -394,10 +394,10 @@ def mkdir(self):
394
394
raise NotImplementedError
395
395
396
396
@abstractmethod
397
- def __open_wb__ (self , buffering = - 1 ):
397
+ def __open_writer__ (self , mode ):
398
398
"""
399
399
Open the file pointed to by this path for writing in binary mode and
400
- return a file object, like open(mode='wb') .
400
+ return a file object.
401
401
"""
402
402
raise NotImplementedError
403
403
@@ -407,7 +407,7 @@ def write_bytes(self, data):
407
407
"""
408
408
# type-check for the buffer interface before truncating the file
409
409
view = memoryview (data )
410
- with magic_open (self , mode = 'wb' ) as f :
410
+ with vfsopen (self , mode = 'wb' ) as f :
411
411
return f .write (view )
412
412
413
413
def write_text (self , data , encoding = None , errors = None , newline = None ):
@@ -420,7 +420,7 @@ def write_text(self, data, encoding=None, errors=None, newline=None):
420
420
if not isinstance (data , str ):
421
421
raise TypeError ('data must be str, not %s' %
422
422
data .__class__ .__name__ )
423
- with magic_open (self , mode = 'w' , encoding = encoding , errors = errors , newline = newline ) as f :
423
+ with vfsopen (self , mode = 'w' , encoding = encoding , errors = errors , newline = newline ) as f :
424
424
return f .write (data )
425
425
426
426
def _copy_from (self , source , follow_symlinks = True ):
@@ -439,8 +439,8 @@ def _copy_from(self, source, follow_symlinks=True):
439
439
stack .append ((child , dst .joinpath (child .name )))
440
440
else :
441
441
ensure_different_files (src , dst )
442
- with magic_open (src , 'rb' ) as source_f :
443
- with magic_open (dst , 'wb' ) as target_f :
442
+ with vfsopen (src , 'rb' ) as source_f :
443
+ with vfsopen (dst , 'wb' ) as target_f :
444
444
copyfileobj (source_f , target_f )
445
445
446
446
0 commit comments