Normalize ``path``. It returns ``path`` with leading and trailing slashes, and no multiple continuous slashes.
(path)
| 5 | |
| 6 | |
| 7 | def normalize_path(path): |
| 8 | """ |
| 9 | Normalize ``path``. |
| 10 | |
| 11 | It returns ``path`` with leading and trailing slashes, and no multiple |
| 12 | continuous slashes. |
| 13 | |
| 14 | """ |
| 15 | if path: |
| 16 | if path[0] != "/": |
| 17 | path = "/" + path |
| 18 | |
| 19 | if path[-1] != "/": |
| 20 | path = path + "/" |
| 21 | |
| 22 | path = _MULTIPLE_PATHS.sub("/", path) |
| 23 | else: |
| 24 | path = "/" |
| 25 | |
| 26 | return path |
| 27 | |
| 28 | |
| 29 | # ------ UNIT TESTS ------ |