@@ -149,39 +149,39 @@ class PathModuleBase:
149
149
"""
150
150
151
151
@classmethod
152
- def _unsupported (cls , attr ):
153
- raise UnsupportedOperation ( f"{ cls .__name__ } .{ attr } is unsupported" )
152
+ def _unsupported_msg (cls , attribute ):
153
+ return f"{ cls .__name__ } .{ attribute } is unsupported"
154
154
155
155
@property
156
156
def sep (self ):
157
157
"""The character used to separate path components."""
158
- self ._unsupported ('sep' )
158
+ raise UnsupportedOperation ( self ._unsupported_msg ('sep' ) )
159
159
160
160
def join (self , path , * paths ):
161
161
"""Join path segments."""
162
- self ._unsupported ('join()' )
162
+ raise UnsupportedOperation ( self ._unsupported_msg ('join()' ) )
163
163
164
164
def split (self , path ):
165
165
"""Split the path into a pair (head, tail), where *head* is everything
166
166
before the final path separator, and *tail* is everything after.
167
167
Either part may be empty.
168
168
"""
169
- self ._unsupported ('split()' )
169
+ raise UnsupportedOperation ( self ._unsupported_msg ('split()' ) )
170
170
171
171
def splitdrive (self , path ):
172
172
"""Split the path into a 2-item tuple (drive, tail), where *drive* is
173
173
a device name or mount point, and *tail* is everything after the
174
174
drive. Either part may be empty."""
175
- self ._unsupported ('splitdrive()' )
175
+ raise UnsupportedOperation ( self ._unsupported_msg ('splitdrive()' ) )
176
176
177
177
def normcase (self , path ):
178
178
"""Normalize the case of the path."""
179
- self ._unsupported ('normcase()' )
179
+ raise UnsupportedOperation ( self ._unsupported_msg ('normcase()' ) )
180
180
181
181
def isabs (self , path ):
182
182
"""Returns whether the path is absolute, i.e. unaffected by the
183
183
current directory or drive."""
184
- self ._unsupported ('isabs()' )
184
+ raise UnsupportedOperation ( self ._unsupported_msg ('isabs()' ) )
185
185
186
186
187
187
class PurePathBase :
@@ -505,16 +505,15 @@ class PathBase(PurePathBase):
505
505
_max_symlinks = 40
506
506
507
507
@classmethod
508
- def _unsupported (cls , method_name ):
509
- msg = f"{ cls .__name__ } .{ method_name } () is unsupported"
510
- raise UnsupportedOperation (msg )
508
+ def _unsupported_msg (cls , attribute ):
509
+ return f"{ cls .__name__ } .{ attribute } is unsupported"
511
510
512
511
def stat (self , * , follow_symlinks = True ):
513
512
"""
514
513
Return the result of the stat() system call on this path, like
515
514
os.stat() does.
516
515
"""
517
- self ._unsupported ( " stat" )
516
+ raise UnsupportedOperation ( self ._unsupported_msg ( ' stat()' ) )
518
517
519
518
def lstat (self ):
520
519
"""
@@ -703,7 +702,7 @@ def open(self, mode='r', buffering=-1, encoding=None,
703
702
Open the file pointed by this path and return a file object, as
704
703
the built-in open() function does.
705
704
"""
706
- self ._unsupported ( " open" )
705
+ raise UnsupportedOperation ( self ._unsupported_msg ( ' open()' ) )
707
706
708
707
def read_bytes (self ):
709
708
"""
@@ -744,7 +743,7 @@ def iterdir(self):
744
743
The children are yielded in arbitrary order, and the
745
744
special entries '.' and '..' are not included.
746
745
"""
747
- self ._unsupported ( " iterdir" )
746
+ raise UnsupportedOperation ( self ._unsupported_msg ( ' iterdir()' ) )
748
747
749
748
def _scandir (self ):
750
749
# Emulate os.scandir(), which returns an object that can be used as a
@@ -871,7 +870,7 @@ def absolute(self):
871
870
872
871
Use resolve() to resolve symlinks and remove '..' segments.
873
872
"""
874
- self ._unsupported ( " absolute" )
873
+ raise UnsupportedOperation ( self ._unsupported_msg ( ' absolute()' ) )
875
874
876
875
@classmethod
877
876
def cwd (cls ):
@@ -886,7 +885,7 @@ def expanduser(self):
886
885
""" Return a new path with expanded ~ and ~user constructs
887
886
(as returned by os.path.expanduser)
888
887
"""
889
- self ._unsupported ( " expanduser" )
888
+ raise UnsupportedOperation ( self ._unsupported_msg ( ' expanduser()' ) )
890
889
891
890
@classmethod
892
891
def home (cls ):
@@ -898,7 +897,7 @@ def readlink(self):
898
897
"""
899
898
Return the path to which the symbolic link points.
900
899
"""
901
- self ._unsupported ( " readlink" )
900
+ raise UnsupportedOperation ( self ._unsupported_msg ( ' readlink()' ) )
902
901
readlink ._supported = False
903
902
904
903
def resolve (self , strict = False ):
@@ -973,27 +972,27 @@ def symlink_to(self, target, target_is_directory=False):
973
972
Make this path a symlink pointing to the target path.
974
973
Note the order of arguments (link, target) is the reverse of os.symlink.
975
974
"""
976
- self ._unsupported ( " symlink_to" )
975
+ raise UnsupportedOperation ( self ._unsupported_msg ( ' symlink_to()' ) )
977
976
978
977
def hardlink_to (self , target ):
979
978
"""
980
979
Make this path a hard link pointing to the same file as *target*.
981
980
982
981
Note the order of arguments (self, target) is the reverse of os.link's.
983
982
"""
984
- self ._unsupported ( " hardlink_to" )
983
+ raise UnsupportedOperation ( self ._unsupported_msg ( ' hardlink_to()' ) )
985
984
986
985
def touch (self , mode = 0o666 , exist_ok = True ):
987
986
"""
988
987
Create this file with the given access mode, if it doesn't exist.
989
988
"""
990
- self ._unsupported ( " touch" )
989
+ raise UnsupportedOperation ( self ._unsupported_msg ( ' touch()' ) )
991
990
992
991
def mkdir (self , mode = 0o777 , parents = False , exist_ok = False ):
993
992
"""
994
993
Create a new directory at this given path.
995
994
"""
996
- self ._unsupported ( " mkdir" )
995
+ raise UnsupportedOperation ( self ._unsupported_msg ( ' mkdir()' ) )
997
996
998
997
def rename (self , target ):
999
998
"""
@@ -1005,7 +1004,7 @@ def rename(self, target):
1005
1004
1006
1005
Returns the new Path instance pointing to the target path.
1007
1006
"""
1008
- self ._unsupported ( " rename" )
1007
+ raise UnsupportedOperation ( self ._unsupported_msg ( ' rename()' ) )
1009
1008
1010
1009
def replace (self , target ):
1011
1010
"""
@@ -1017,13 +1016,13 @@ def replace(self, target):
1017
1016
1018
1017
Returns the new Path instance pointing to the target path.
1019
1018
"""
1020
- self ._unsupported ( " replace" )
1019
+ raise UnsupportedOperation ( self ._unsupported_msg ( ' replace()' ) )
1021
1020
1022
1021
def chmod (self , mode , * , follow_symlinks = True ):
1023
1022
"""
1024
1023
Change the permissions of the path, like os.chmod().
1025
1024
"""
1026
- self ._unsupported ( " chmod" )
1025
+ raise UnsupportedOperation ( self ._unsupported_msg ( ' chmod()' ) )
1027
1026
1028
1027
def lchmod (self , mode ):
1029
1028
"""
@@ -1037,31 +1036,31 @@ def unlink(self, missing_ok=False):
1037
1036
Remove this file or link.
1038
1037
If the path is a directory, use rmdir() instead.
1039
1038
"""
1040
- self ._unsupported ( " unlink" )
1039
+ raise UnsupportedOperation ( self ._unsupported_msg ( ' unlink()' ) )
1041
1040
1042
1041
def rmdir (self ):
1043
1042
"""
1044
1043
Remove this directory. The directory must be empty.
1045
1044
"""
1046
- self ._unsupported ( " rmdir" )
1045
+ raise UnsupportedOperation ( self ._unsupported_msg ( ' rmdir()' ) )
1047
1046
1048
1047
def owner (self , * , follow_symlinks = True ):
1049
1048
"""
1050
1049
Return the login name of the file owner.
1051
1050
"""
1052
- self ._unsupported ( " owner" )
1051
+ raise UnsupportedOperation ( self ._unsupported_msg ( ' owner()' ) )
1053
1052
1054
1053
def group (self , * , follow_symlinks = True ):
1055
1054
"""
1056
1055
Return the group name of the file gid.
1057
1056
"""
1058
- self ._unsupported ( " group" )
1057
+ raise UnsupportedOperation ( self ._unsupported_msg ( ' group()' ) )
1059
1058
1060
1059
@classmethod
1061
1060
def from_uri (cls , uri ):
1062
1061
"""Return a new path from the given 'file' URI."""
1063
- cls ._unsupported ( " from_uri" )
1062
+ raise UnsupportedOperation ( cls ._unsupported_msg ( ' from_uri()' ) )
1064
1063
1065
1064
def as_uri (self ):
1066
1065
"""Return the path as a URI."""
1067
- self ._unsupported ( " as_uri" )
1066
+ raise UnsupportedOperation ( self ._unsupported_msg ( ' as_uri()' ) )
0 commit comments