Remove invalid characters and truncate the path if needed
(value)
| 563 | |
| 564 | #@TODO: Recheck in 0.4.10 |
| 565 | def safepath(value): |
| 566 | """ |
| 567 | Remove invalid characters and truncate the path if needed |
| 568 | """ |
| 569 | if os.name == "nt": |
| 570 | unt, value = os.path.splitunc(value) |
| 571 | else: |
| 572 | unt = "" |
| 573 | drive, filename = os.path.splitdrive(value) |
| 574 | filename = os.path.join(os.sep if os.path.isabs(filename) else "", *map(safename, filename.split(os.sep))) |
| 575 | path = unt + drive + filename |
| 576 | |
| 577 | try: |
| 578 | if os.name != "nt": |
| 579 | return |
| 580 | |
| 581 | length = len(path) - 259 |
| 582 | if length < 1: |
| 583 | return |
| 584 | |
| 585 | dirname, basename = os.path.split(filename) |
| 586 | name, ext = os.path.splitext(basename) |
| 587 | path = unt + drive + dirname + truncate(name, length) + ext |
| 588 | |
| 589 | finally: |
| 590 | return path |
| 591 | |
| 592 | |
| 593 | def safejoin(*args): |
no test coverage detected