(script_name, path_info, shift=1)
return new_script_name, new_path_info
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 the shift direction. (default: 1)
Shift path fragments from PATH_INFO to SCRIPT_NAME and vice versa.
Shift path fragments from PATH_INFO to SCRIPT_NAME and vice versa .
def path_shift(script_name, path_info, shift=1):
    ''' 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 the shift direction. (default: 1)
    '''
    if shift == 0: return script_name, path_info
    pathlist = path_info.strip('/').split('/')
    scriptlist = script_name.strip('/').split('/')
    if pathlist and pathlist[0] == '': pathlist = []
    if scriptlist and scriptlist[0] == '': scriptlist = []
    if shift > 0 and shift <= len(pathlist):
        moved = pathlist[:shift]
        scriptlist = scriptlist + moved
        pathlist = pathlist[shift:]
    elif shift < 0 and shift >= -len(scriptlist):
        moved = scriptlist[shift:]
        pathlist = moved + pathlist
        scriptlist = scriptlist[:shift]
    else:
        empty = 'SCRIPT_NAME' if shift < 0 else 'PATH_INFO'
        raise AssertionError("Cannot shift. Nothing left from %s" % empty)
    new_script_name = '/' + '/'.join(scriptlist)
    new_path_info = '/' + '/'.join(pathlist)
    if path_info.endswith('/') and pathlist: new_path_info += '/'
    return new_script_name, new_path_info
def path_shift ( script_name , path_info , shift = 1 ) : if shift == 0 : return script_name , path_info pathlist = path_info . strip ( '/' ) . split ( '/' ) scriptlist = script_name . strip ( '/' ) . split ( '/' ) if pathlist and pathlist [ 0 ] == '' : pathlist = [ ] if scriptlist and scriptlist [ 0 ] == '' : scriptlist = [ ] if shift > 0 and shift <= len ( pathlist ) : moved = pathlist [ : shift ] scriptlist = scriptlist + moved pathlist = pathlist [ shift : ] elif shift < 0 and shift >= - len ( scriptlist ) : moved = scriptlist [ shift : ] pathlist = moved + pathlist scriptlist = scriptlist [ : shift ] else : empty = 'SCRIPT_NAME' if shift < 0 else 'PATH_INFO' raise AssertionError ( "Cannot shift. Nothing left from %s" % empty ) new_script_name = '/' + '/' . join ( scriptlist ) new_path_info = '/' + '/' . join ( pathlist ) if path_info . endswith ( '/' ) and pathlist : new_path_info += '/' return new_script_name , new_path_info