def urljoin(base, url, allow_fragments=True):
if not base:<EOL><INDENT>return url<EOL><DEDENT>if not url:<EOL><INDENT>return base<EOL><DEDENT>bscheme, bnetloc, bpath, bparams, bquery, bfragment =urlparse(base, '<STR_LIT>', allow_fragments)<EOL>scheme, netloc, path, params, query, fragment =urlparse(url, bscheme, allow_fragments)<EOL>if scheme != bscheme or scheme not in uses_relative:<EOL><INDENT>return url<EOL><DEDENT>if scheme in uses_netloc:<EOL><INDENT>if netloc:<EOL><INDENT>return urlunparse((scheme, netloc, path,<EOL>params, query, fragment))<EOL><DEDENT>netloc = bnetloc<EOL><DEDENT>if path[:<NUM_LIT:1>] == '<STR_LIT:/>':<EOL><INDENT>return urlunparse((scheme, netloc, path,<EOL>params, query, fragment))<EOL><DEDENT>if not path and not params:<EOL><INDENT>path = bpath<EOL>params = bparams<EOL>if not query:<EOL><INDENT>query = bquery<EOL><DEDENT>return urlunparse((scheme, netloc, path,<EOL>params, query, fragment))<EOL><DEDENT>segments = bpath.split('<STR_LIT:/>')[:-<NUM_LIT:1>] + path.split('<STR_LIT:/>')<EOL>if segments[-<NUM_LIT:1>] == '<STR_LIT:.>':<EOL><INDENT>segments[-<NUM_LIT:1>] = '<STR_LIT>'<EOL><DEDENT>while '<STR_LIT:.>' in segments:<EOL><INDENT>segments.remove('<STR_LIT:.>')<EOL><DEDENT>while <NUM_LIT:1>:<EOL><INDENT>i = <NUM_LIT:1><EOL>n = len(segments) - <NUM_LIT:1><EOL>while i < n:<EOL><INDENT>if (segments[i] == '<STR_LIT:..>'<EOL>and segments[i-<NUM_LIT:1>] not in ('<STR_LIT>', '<STR_LIT:..>')):<EOL><INDENT>del segments[i-<NUM_LIT:1>:i+<NUM_LIT:1>]<EOL>break<EOL><DEDENT>i = i+<NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>break<EOL><DEDENT><DEDENT>if segments == ['<STR_LIT>', '<STR_LIT:..>']:<EOL><INDENT>segments[-<NUM_LIT:1>] = '<STR_LIT>'<EOL><DEDENT>elif len(segments) >= <NUM_LIT:2> and segments[-<NUM_LIT:1>] == '<STR_LIT:..>':<EOL><INDENT>segments[-<NUM_LIT:2>:] = ['<STR_LIT>']<EOL><DEDENT>return urlunparse((scheme, netloc, '<STR_LIT:/>'.join(segments),<EOL>params, query, fragment))<EOL>
Join a base URL and a possibly relative URL to form an absolute
    interpretation of the latter.