def get_site_url(request=None):
env = partial(environ.get)<EOL>settings_ = partial(getattr, settings)<EOL>domain = None<EOL>scheme = None<EOL>url = None<EOL>for src in (env, settings_):<EOL><INDENT>if url is None:<EOL><INDENT>url = src('<STR_LIT>', None)<EOL><DEDENT>if domain is None:<EOL><INDENT>domain = src('<STR_LIT>', None)<EOL><DEDENT>if scheme is None:<EOL><INDENT>scheme = src('<STR_LIT>', src('<STR_LIT>', None))<EOL><DEDENT><DEDENT>if domain is None and url is not None:<EOL><INDENT>scheme, domain = url.split('<STR_LIT>')[:<NUM_LIT:2>]<EOL><DEDENT>if domain is None:<EOL><INDENT>site = get_current_site(request or DomainGetter(domain))<EOL>domain = site.domain<EOL><DEDENT>if scheme is None and request:<EOL><INDENT>scheme = request.scheme<EOL><DEDENT>if domain is None:<EOL><INDENT>domain = '<STR_LIT>'<EOL><DEDENT>if scheme is None:<EOL><INDENT>scheme = '<STR_LIT:http>'<EOL><DEDENT>domain = domain.rstrip('<STR_LIT:/>')<EOL>return '<STR_LIT>' % (scheme, domain)<EOL>
Tries to get a site URL from environment and settings
    in the following order:

    1. (SITE_PROTO / SITE_SCHEME) + SITE_DOMAIN
    2. SITE_URL
    3. Django Sites contrib
    4. Request object

    :param HttpRequest request: Request object to deduce URL from.
    :rtype: str