MCPcopy Index your code
hub / github.com/python/cpython / join

Function join

Lib/ntpath.py:99–140  ·  view source on GitHub ↗
(path, /, *paths)

Source from the content-addressed store, hash-verified

97
98# Join two (or more) paths.
99def join(path, /, *paths):
100 path = os.fspath(path)
101 if isinstance(path, bytes):
102 sep = b'\\'
103 seps = b'\\/'
104 colon_seps = b':\\/'
105 else:
106 sep = '\\'
107 seps = '\\/'
108 colon_seps = ':\\/'
109 try:
110 result_drive, result_root, result_path = splitroot(path)
111 for p in paths:
112 p_drive, p_root, p_path = splitroot(p)
113 if p_root:
114 # Second path is absolute
115 if p_drive or not result_drive:
116 result_drive = p_drive
117 result_root = p_root
118 result_path = p_path
119 continue
120 elif p_drive and p_drive != result_drive:
121 if p_drive.lower() != result_drive.lower():
122 # Different drives => ignore the first path entirely
123 result_drive = p_drive
124 result_root = p_root
125 result_path = p_path
126 continue
127 # Same drive in different case
128 result_drive = p_drive
129 # Second path is relative to the first
130 if result_path and result_path[-1] not in seps:
131 result_path = result_path + sep
132 result_path = result_path + p_path
133 ## add separator between UNC and non-absolute path
134 if (result_path and not result_root and
135 result_drive and result_drive[-1] not in colon_seps):
136 return result_drive + sep + result_path
137 return result_drive + result_root + result_path
138 except (TypeError, AttributeError, BytesWarning):
139 genericpath._check_arg_types('join', path, *paths)
140 raise
141
142
143# Split a path in a drive specification (a drive letter followed by a

Callers 10

deltreeFunction · 0.90
readconfigFunction · 0.90
openfileFunction · 0.90
copy_stripFunction · 0.90
show_idlehelpFunction · 0.90
expanduserFunction · 0.70
abspathFunction · 0.70
_readlink_deepFunction · 0.70
realpathFunction · 0.70

Calls 2

splitrootFunction · 0.90
lowerMethod · 0.45

Tested by 1

openfileFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…