Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
22 lines (14 sloc) 606 Bytes
from parse_config import parse
def valid_key(path):
# will consider a valid path if has no slashes and is not None
return path is not None and not path.count('/') and path.isalnum()
def clean_path(path):
return path.strip('/') if path else None
def application(environ, start_response):
path = clean_path(environ.get('PATH_INFO', ''))
shorts = parse('shorturls.cfg')
if valid_key(path) and path in shorts:
start_response('303 See Other', [('Location', shorts[path])])
start_response('404 Not Found', [('Content-type', 'text/plain')])
return []
You can’t perform that action at this time.