import requests

from django.conf import settings


AUTH = getattr(settings, 'BASIC_AUTH_DOMAINS', None)

def url_exists(url):
    """Check that a url (when following redirection) exists.

    This is needed because Django's validators rely on Python's urllib2
    which in verions < 2.6 won't follow redirects.

    """
    try:
        # This AUTH stuff is a hack to get around the HTTP Basic Auth on dev
        # and staging to prevent partner stuff from going public.
        if AUTH:
            for domain, auth in AUTH.items():
                if domain in url:
                    return 200 <= requests.head(url, auth=auth).status_code < 400

        return 200 <= requests.head(url).status_code < 400
    except requests.ConnectionError:
        return False

import requests


def url_exists(url):
    """Check that a url (when following redirection) exists.

    This is needed because Django's validators rely on Python's urllib2 which in
    verions < 2.6 won't follow redirects.

    """
    try:
        return 200 <= requests.head(url).status_code < 400
    except requests.ConnectionError:
        return False

Remove the unnecessary and never-used basic auth hack.
Remove the unnecessary and never-used basic auth hack.

  import requests
  
- from django.conf import settings
- 
- 
- AUTH = getattr(settings, 'BASIC_AUTH_DOMAINS', None)
  
  def url_exists(url):
      """Check that a url (when following redirection) exists.
  
-     This is needed because Django's validators rely on Python's urllib2
+     This is needed because Django's validators rely on Python's urllib2 which in
-     which in verions < 2.6 won't follow redirects.
+     verions < 2.6 won't follow redirects.
  
      """
      try:
-         # This AUTH stuff is a hack to get around the HTTP Basic Auth on dev
-         # and staging to prevent partner stuff from going public.
-         if AUTH:
-             for domain, auth in AUTH.items():
-                 if domain in url:
-                     return 200 <= requests.head(url, auth=auth).status_code < 400
- 
          return 200 <= requests.head(url).status_code < 400
      except requests.ConnectionError:
          return False
  
Remove the unnecessary and never-used basic auth hack.
## Code Before:
import requests

from django.conf import settings


AUTH = getattr(settings, 'BASIC_AUTH_DOMAINS', None)

def url_exists(url):
    """Check that a url (when following redirection) exists.

    This is needed because Django's validators rely on Python's urllib2
    which in verions < 2.6 won't follow redirects.

    """
    try:
        # This AUTH stuff is a hack to get around the HTTP Basic Auth on dev
        # and staging to prevent partner stuff from going public.
        if AUTH:
            for domain, auth in AUTH.items():
                if domain in url:
                    return 200 <= requests.head(url, auth=auth).status_code < 400

        return 200 <= requests.head(url).status_code < 400
    except requests.ConnectionError:
        return False

## Instruction:
Remove the unnecessary and never-used basic auth hack.
## Code After:
import requests


def url_exists(url):
    """Check that a url (when following redirection) exists.

    This is needed because Django's validators rely on Python's urllib2 which in
    verions < 2.6 won't follow redirects.

    """
    try:
        return 200 <= requests.head(url).status_code < 400
    except requests.ConnectionError:
        return False
