summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Socol <me@jamessocol.com>2014-05-09 10:39:48 -0400
committerJames Socol <me@jamessocol.com>2014-05-09 11:29:12 -0400
commit043281baad434788013276c05eb8a030d7cce5b2 (patch)
tree81c21fa19aa6023547ebb536e0f0ef651ba29d41
parent269565b9fa5eab7069a162f68f9aaf2ac5341799 (diff)
downloadpystatsd-043281baad434788013276c05eb8a030d7cce5b2.tar.gz
Move default instances out of __init__.py
-rw-r--r--statsd/__init__.py38
-rw-r--r--statsd/defaults/__init__.py4
-rw-r--r--statsd/defaults/django.py15
-rw-r--r--statsd/defaults/env.py15
4 files changed, 35 insertions, 37 deletions
diff --git a/statsd/__init__.py b/statsd/__init__.py
index 444eab7..903fd18 100644
--- a/statsd/__init__.py
+++ b/statsd/__init__.py
@@ -1,44 +1,8 @@
from __future__ import absolute_import
-import os
-import socket
-
-try:
- from django.conf import settings
- from django.core.exceptions import ImproperlyConfigured
- try:
- # This handles the case where Django >=1.5 is in the python path
- # but this particular project is not a django project. In
- # that case, settings aren't configured.
- getattr(settings, 'STATSD_HOST', 'localhost')
- except ImproperlyConfigured:
- settings = None
-except ImportError:
- settings = None
from .client import StatsClient
VERSION = (2, 1, 2)
__version__ = '.'.join(map(str, VERSION))
-__all__ = ['StatsClient', 'statsd']
-
-statsd = None
-
-if settings:
- try:
- host = getattr(settings, 'STATSD_HOST', 'localhost')
- port = getattr(settings, 'STATSD_PORT', 8125)
- prefix = getattr(settings, 'STATSD_PREFIX', None)
- maxudpsize = getattr(settings, 'STATSD_MAXUDPSIZE', 512)
- statsd = StatsClient(host, port, prefix, maxudpsize)
- except (socket.error, socket.gaierror, ImportError):
- pass
-elif 'STATSD_HOST' in os.environ:
- try:
- host = os.environ['STATSD_HOST']
- port = int(os.environ['STATSD_PORT'])
- prefix = os.environ.get('STATSD_PREFIX')
- maxudpsize = int(os.environ.get('STATSD_MAXUDPSIZE', 512))
- statsd = StatsClient(host, port, prefix, maxudpsize)
- except (socket.error, socket.gaierror, KeyError):
- pass
+__all__ = ['StatsClient']
diff --git a/statsd/defaults/__init__.py b/statsd/defaults/__init__.py
new file mode 100644
index 0000000..2f2de3b
--- /dev/null
+++ b/statsd/defaults/__init__.py
@@ -0,0 +1,4 @@
+HOST = 'localhost'
+PORT = 8125
+PREFIX = None
+MAXUDPSIZE = 512
diff --git a/statsd/defaults/django.py b/statsd/defaults/django.py
new file mode 100644
index 0000000..c4c2951
--- /dev/null
+++ b/statsd/defaults/django.py
@@ -0,0 +1,15 @@
+from __future__ import absolute_import
+from django.conf import settings
+
+from statsd import defaults
+from statsd.client import StatsClient
+
+
+statsd = None
+
+if statsd is None:
+ host = getattr(settings, 'STATSD_HOST', defaults.HOST)
+ port = getattr(settings, 'STATSD_PORT', defaults.PORT)
+ prefix = getattr(settings, 'STATSD_PREFIX', defaults.PREFIX)
+ maxudpsize = getattr(settings, 'STATSD_MAXUDPSIZE', defaults.MAXUDPSIZE)
+ statsd = StatsClient(host, port, prefix, maxudpsize)
diff --git a/statsd/defaults/env.py b/statsd/defaults/env.py
new file mode 100644
index 0000000..eb857f9
--- /dev/null
+++ b/statsd/defaults/env.py
@@ -0,0 +1,15 @@
+from __future__ import absolute_import
+import os
+
+from statsd import defaults
+from statsd.client import StatsClient
+
+
+statsd = None
+
+if statsd is None:
+ host = os.getenv('STATSD_HOST', defaults.HOST)
+ port = int(os.getenv('STATSD_PORT', defaults.PORT))
+ prefix = os.getenv('STATSD_PREFIX', defaults.PREFIX)
+ maxudpsize = int(os.getenv('STATSD_MAXUDPSIZE', defaults.MAXUDPSIZE))
+ statsd = StatsClient(host, port, prefix, maxudpsize)