import socket

try:
    from django.conf import settings
except ImportError:
    settings = None

from client import StatsClient


__all__ = ['StatsClient', 'statsd']

VERSION = (0, 4, 0)
__version__ = '.'.join(map(str, VERSION))


if settings:
    try:
        host = getattr(settings, 'STATSD_HOST', 'localhost')
        port = getattr(settings, 'STATSD_PORT', 8125)
        prefix = getattr(settings, 'STATSD_PREFIX', None)
        statsd = StatsClient(host, port, prefix)
    except (socket.error, socket.gaierror, ImportError):
        statsd = None

import socket
import os

try:
    from django.conf import settings
except ImportError:
    settings = None

from client import StatsClient


__all__ = ['StatsClient', 'statsd']

VERSION = (0, 4, 0)
__version__ = '.'.join(map(str, VERSION))


if settings:
    try:
        host = getattr(settings, 'STATSD_HOST', 'localhost')
        port = getattr(settings, 'STATSD_PORT', 8125)
        prefix = getattr(settings, 'STATSD_PREFIX', None)
        statsd = StatsClient(host, port, prefix)
    except (socket.error, socket.gaierror, ImportError):
        try:
            host = os.environ['STATSD_HOST']
            port = os.environ['STATSD_PORT']
            prefix = os.environ.get('STATSD_PREFIX')
            statsd = StatsClient(host, port, prefix)
        except (socket.error, socket.gaierror, KeyError):
            statsd = None


Read settings from environment, if available
Read settings from environment, if available

  import socket
+ import os
  
  try:
      from django.conf import settings
  except ImportError:
      settings = None
  
  from client import StatsClient
  
  
  __all__ = ['StatsClient', 'statsd']
  
  VERSION = (0, 4, 0)
  __version__ = '.'.join(map(str, VERSION))
  
  
  if settings:
      try:
          host = getattr(settings, 'STATSD_HOST', 'localhost')
          port = getattr(settings, 'STATSD_PORT', 8125)
          prefix = getattr(settings, 'STATSD_PREFIX', None)
          statsd = StatsClient(host, port, prefix)
      except (socket.error, socket.gaierror, ImportError):
+         try:
+             host = os.environ['STATSD_HOST']
+             port = os.environ['STATSD_PORT']
+             prefix = os.environ.get('STATSD_PREFIX')
+             statsd = StatsClient(host, port, prefix)
+         except (socket.error, socket.gaierror, KeyError):
-         statsd = None
+             statsd = None
  
+ 
Read settings from environment, if available
## Code Before:
import socket

try:
    from django.conf import settings
except ImportError:
    settings = None

from client import StatsClient


__all__ = ['StatsClient', 'statsd']

VERSION = (0, 4, 0)
__version__ = '.'.join(map(str, VERSION))


if settings:
    try:
        host = getattr(settings, 'STATSD_HOST', 'localhost')
        port = getattr(settings, 'STATSD_PORT', 8125)
        prefix = getattr(settings, 'STATSD_PREFIX', None)
        statsd = StatsClient(host, port, prefix)
    except (socket.error, socket.gaierror, ImportError):
        statsd = None

## Instruction:
Read settings from environment, if available
## Code After:
import socket
import os

try:
    from django.conf import settings
except ImportError:
    settings = None

from client import StatsClient


__all__ = ['StatsClient', 'statsd']

VERSION = (0, 4, 0)
__version__ = '.'.join(map(str, VERSION))


if settings:
    try:
        host = getattr(settings, 'STATSD_HOST', 'localhost')
        port = getattr(settings, 'STATSD_PORT', 8125)
        prefix = getattr(settings, 'STATSD_PREFIX', None)
        statsd = StatsClient(host, port, prefix)
    except (socket.error, socket.gaierror, ImportError):
        try:
            host = os.environ['STATSD_HOST']
            port = os.environ['STATSD_PORT']
            prefix = os.environ.get('STATSD_PREFIX')
            statsd = StatsClient(host, port, prefix)
        except (socket.error, socket.gaierror, KeyError):
            statsd = None

