Shift path fragments from PATH_INFO to SCRIPT_NAME and vice versa. :return: The modified paths. :param script_name: The SCRIPT_NAME path. :param script_name: The PATH_INFO path. :param shift: The number of path fragments to shift. May be negative to change
(script_name, path_info, shift=1)
| 3519 | |
| 3520 | |
| 3521 | def path_shift(script_name, path_info, shift=1): |
| 3522 | """ Shift path fragments from PATH_INFO to SCRIPT_NAME and vice versa. |
| 3523 | |
| 3524 | :return: The modified paths. |
| 3525 | :param script_name: The SCRIPT_NAME path. |
| 3526 | :param script_name: The PATH_INFO path. |
| 3527 | :param shift: The number of path fragments to shift. May be negative to |
| 3528 | change the shift direction. (default: 1) |
| 3529 | """ |
| 3530 | if shift == 0: return script_name, path_info |
| 3531 | pathlist = path_info.strip('/').split('/') |
| 3532 | scriptlist = script_name.strip('/').split('/') |
| 3533 | if pathlist and pathlist[0] == '': pathlist = [] |
| 3534 | if scriptlist and scriptlist[0] == '': scriptlist = [] |
| 3535 | if 0 < shift <= len(pathlist): |
| 3536 | moved = pathlist[:shift] |
| 3537 | scriptlist = scriptlist + moved |
| 3538 | pathlist = pathlist[shift:] |
| 3539 | elif 0 > shift >= -len(scriptlist): |
| 3540 | moved = scriptlist[shift:] |
| 3541 | pathlist = moved + pathlist |
| 3542 | scriptlist = scriptlist[:shift] |
| 3543 | else: |
| 3544 | empty = 'SCRIPT_NAME' if shift < 0 else 'PATH_INFO' |
| 3545 | raise AssertionError("Cannot shift. Nothing left from %s" % empty) |
| 3546 | new_script_name = '/' + '/'.join(scriptlist) |
| 3547 | new_path_info = '/' + '/'.join(pathlist) |
| 3548 | if path_info.endswith('/') and pathlist: new_path_info += '/' |
| 3549 | return new_script_name, new_path_info |
| 3550 | |
| 3551 | |
| 3552 | def auth_basic(check, realm="private", text="Access denied"): |
no outgoing calls
no test coverage detected
searching dependent graphs…