@@ -80,32 +80,36 @@ def join(path, *paths):
8080 sep = '\\ '
8181 seps = '\\ /'
8282 colon = ':'
83- result_drive , result_path = splitdrive (path )
84- for p in paths :
85- p_drive , p_path = splitdrive (p )
86- if p_path and p_path [0 ] in seps :
87- # Second path is absolute
88- if p_drive or not result_drive :
89- result_drive = p_drive
90- result_path = p_path
91- continue
92- elif p_drive and p_drive != result_drive :
93- if p_drive .lower () != result_drive .lower ():
94- # Different drives => ignore the first path entirely
95- result_drive = p_drive
83+ try :
84+ result_drive , result_path = splitdrive (path )
85+ for p in paths :
86+ p_drive , p_path = splitdrive (p )
87+ if p_path and p_path [0 ] in seps :
88+ # Second path is absolute
89+ if p_drive or not result_drive :
90+ result_drive = p_drive
9691 result_path = p_path
9792 continue
98- # Same drive in different case
99- result_drive = p_drive
100- # Second path is relative to the first
101- if result_path and result_path [- 1 ] not in seps :
102- result_path = result_path + sep
103- result_path = result_path + p_path
104- ## add separator between UNC and non-absolute path
105- if (result_path and result_path [0 ] not in seps and
106- result_drive and result_drive [- 1 :] != colon ):
107- return result_drive + sep + result_path
108- return result_drive + result_path
93+ elif p_drive and p_drive != result_drive :
94+ if p_drive .lower () != result_drive .lower ():
95+ # Different drives => ignore the first path entirely
96+ result_drive = p_drive
97+ result_path = p_path
98+ continue
99+ # Same drive in different case
100+ result_drive = p_drive
101+ # Second path is relative to the first
102+ if result_path and result_path [- 1 ] not in seps :
103+ result_path = result_path + sep
104+ result_path = result_path + p_path
105+ ## add separator between UNC and non-absolute path
106+ if (result_path and result_path [0 ] not in seps and
107+ result_drive and result_drive [- 1 :] != colon ):
108+ return result_drive + sep + result_path
109+ return result_drive + result_path
110+ except (TypeError , AttributeError , BytesWarning ):
111+ genericpath ._check_arg_types ('join' , path , * paths )
112+ raise
109113
110114
111115# Split a path in a drive specification (a drive letter followed by a
@@ -558,27 +562,31 @@ def relpath(path, start=None):
558562 if not path :
559563 raise ValueError ("no path specified" )
560564
561- start_abs = abspath (normpath (start ))
562- path_abs = abspath (normpath (path ))
563- start_drive , start_rest = splitdrive (start_abs )
564- path_drive , path_rest = splitdrive (path_abs )
565- if normcase (start_drive ) != normcase (path_drive ):
566- raise ValueError ("path is on mount %r, start on mount %r" % (
567- path_drive , start_drive ))
568-
569- start_list = [x for x in start_rest .split (sep ) if x ]
570- path_list = [x for x in path_rest .split (sep ) if x ]
571- # Work out how much of the filepath is shared by start and path.
572- i = 0
573- for e1 , e2 in zip (start_list , path_list ):
574- if normcase (e1 ) != normcase (e2 ):
575- break
576- i += 1
565+ try :
566+ start_abs = abspath (normpath (start ))
567+ path_abs = abspath (normpath (path ))
568+ start_drive , start_rest = splitdrive (start_abs )
569+ path_drive , path_rest = splitdrive (path_abs )
570+ if normcase (start_drive ) != normcase (path_drive ):
571+ raise ValueError ("path is on mount %r, start on mount %r" % (
572+ path_drive , start_drive ))
573+
574+ start_list = [x for x in start_rest .split (sep ) if x ]
575+ path_list = [x for x in path_rest .split (sep ) if x ]
576+ # Work out how much of the filepath is shared by start and path.
577+ i = 0
578+ for e1 , e2 in zip (start_list , path_list ):
579+ if normcase (e1 ) != normcase (e2 ):
580+ break
581+ i += 1
577582
578- rel_list = [pardir ] * (len (start_list )- i ) + path_list [i :]
579- if not rel_list :
580- return curdir
581- return join (* rel_list )
583+ rel_list = [pardir ] * (len (start_list )- i ) + path_list [i :]
584+ if not rel_list :
585+ return curdir
586+ return join (* rel_list )
587+ except (TypeError , ValueError , AttributeError , BytesWarning ):
588+ genericpath ._check_arg_types ('relpath' , path , start )
589+ raise
582590
583591
584592# determine if two files are in fact the same file
0 commit comments