Join a *canonical* `parentpath` with a *non-empty* `name`. .. versionchanged:: 3.0 The *parentPath* parameter has been renamed into *parentpath*. >>> join_path('/', 'foo') '/foo' >>> join_path('/foo', 'bar') '/foo/bar' >>> join_path('/foo', '/foo2/bar') '/foo/foo
(parentpath: str, name: str)
| 156 | |
| 157 | |
| 158 | def join_path(parentpath: str, name: str) -> str: |
| 159 | """Join a *canonical* `parentpath` with a *non-empty* `name`. |
| 160 | |
| 161 | .. versionchanged:: 3.0 |
| 162 | The *parentPath* parameter has been renamed into *parentpath*. |
| 163 | |
| 164 | >>> join_path('/', 'foo') |
| 165 | '/foo' |
| 166 | >>> join_path('/foo', 'bar') |
| 167 | '/foo/bar' |
| 168 | >>> join_path('/foo', '/foo2/bar') |
| 169 | '/foo/foo2/bar' |
| 170 | >>> join_path('/foo', '/') |
| 171 | '/foo' |
| 172 | |
| 173 | """ |
| 174 | if name.startswith("./"): # Support relative paths (mainly for links) |
| 175 | name = name[2:] |
| 176 | if parentpath == "/" and name.startswith("/"): |
| 177 | pstr = "%s" % name |
| 178 | elif parentpath == "/" or name.startswith("/"): |
| 179 | pstr = f"{parentpath}{name}" |
| 180 | else: |
| 181 | pstr = f"{parentpath}/{name}" |
| 182 | if pstr.endswith("/"): |
| 183 | pstr = pstr[:-1] |
| 184 | return pstr |
| 185 | |
| 186 | |
| 187 | def split_path(path: str) -> (str, str): |
no outgoing calls
no test coverage detected