MCPcopy Index your code
hub / github.com/pyload/pyload / safepath

Function safepath

module/plugins/internal/misc.py:565–590  ·  view source on GitHub ↗

Remove invalid characters and truncate the path if needed

(value)

Source from the content-addressed store, hash-verified

563
564#@TODO: Recheck in 0.4.10
565def 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
593def safejoin(*args):

Callers 2

safejoinFunction · 0.85
_create_packagesMethod · 0.85

Calls 3

joinMethod · 0.80
splitMethod · 0.80
truncateFunction · 0.70

Tested by

no test coverage detected