Shift a name from PATH_INFO to SCRIPT_NAME, returning it If there are no remaining path segments in PATH_INFO, return None. Note: 'environ' is modified in-place; use a copy if you need to keep the original PATH_INFO or SCRIPT_NAME. Note: when PATH_INFO is just a '/', this returns '
(environ)
| 68 | return url |
| 69 | |
| 70 | def shift_path_info(environ): |
| 71 | """Shift a name from PATH_INFO to SCRIPT_NAME, returning it |
| 72 | |
| 73 | If there are no remaining path segments in PATH_INFO, return None. |
| 74 | Note: 'environ' is modified in-place; use a copy if you need to keep |
| 75 | the original PATH_INFO or SCRIPT_NAME. |
| 76 | |
| 77 | Note: when PATH_INFO is just a '/', this returns '' and appends a trailing |
| 78 | '/' to SCRIPT_NAME, even though empty path segments are normally ignored, |
| 79 | and SCRIPT_NAME doesn't normally end in a '/'. This is intentional |
| 80 | behavior, to ensure that an application can tell the difference between |
| 81 | '/x' and '/x/' when traversing to objects. |
| 82 | """ |
| 83 | path_info = environ.get('PATH_INFO','') |
| 84 | if not path_info: |
| 85 | return None |
| 86 | |
| 87 | path_parts = path_info.split('/') |
| 88 | path_parts[1:-1] = [p for p in path_parts[1:-1] if p and p != '.'] |
| 89 | name = path_parts[1] |
| 90 | del path_parts[1] |
| 91 | |
| 92 | script_name = environ.get('SCRIPT_NAME','') |
| 93 | script_name = posixpath.normpath(script_name+'/'+name) |
| 94 | if script_name.endswith('/'): |
| 95 | script_name = script_name[:-1] |
| 96 | if not name and not script_name.endswith('/'): |
| 97 | script_name += '/' |
| 98 | |
| 99 | environ['SCRIPT_NAME'] = script_name |
| 100 | environ['PATH_INFO'] = '/'.join(path_parts) |
| 101 | |
| 102 | # Special case: '/.' on PATH_INFO doesn't get stripped, |
| 103 | # because we don't strip the last element of PATH_INFO |
| 104 | # if there's only one path part left. Instead of fixing this |
| 105 | # above, we fix it here so that PATH_INFO gets normalized to |
| 106 | # an empty string in the environ. |
| 107 | if name=='.': |
| 108 | name = None |
| 109 | return name |
| 110 | |
| 111 | def setup_testing_defaults(environ): |
| 112 | """Update 'environ' with trivial defaults for testing purposes |