This function extends os.path.join to support the "::" hop separator. It supports both paths and urls. A shorthand, particularly useful where you have multiple hops, is to “chain” the URLs with the special separator "::". This is used to access files inside a zip file over http for exa
(a, *p)
| 568 | |
| 569 | |
| 570 | def xjoin(a, *p): |
| 571 | """ |
| 572 | This function extends os.path.join to support the "::" hop separator. It supports both paths and urls. |
| 573 | |
| 574 | A shorthand, particularly useful where you have multiple hops, is to “chain” the URLs with the special separator "::". |
| 575 | This is used to access files inside a zip file over http for example. |
| 576 | |
| 577 | Let's say you have a zip file at https://host.com/archive.zip, and you want to access the file inside the zip file at /folder1/file.txt. |
| 578 | Then you can just chain the url this way: |
| 579 | |
| 580 | zip://folder1/file.txt::https://host.com/archive.zip |
| 581 | |
| 582 | The xjoin function allows you to apply the join on the first path of the chain. |
| 583 | |
| 584 | Example:: |
| 585 | |
| 586 | >>> xjoin("zip://folder1::https://host.com/archive.zip", "file.txt") |
| 587 | zip://folder1/file.txt::https://host.com/archive.zip |
| 588 | """ |
| 589 | a, *b = str(a).split("::") |
| 590 | if is_local_path(a): |
| 591 | return os.path.join(a, *p) |
| 592 | else: |
| 593 | a = posixpath.join(a, *p) |
| 594 | return "::".join([a] + b) |
| 595 | |
| 596 | |
| 597 | def xdirname(a): |