Permalink
Browse files

use translate instead of replace

  • Loading branch information...
TimZehta committed Nov 11, 2011
1 parent f169380 commit 461e307481e26747907141af1dc293c154d96093
Showing with 3 additions and 4 deletions.
  1. +3 −4 carbon_writer.py
View
@@ -15,6 +15,7 @@
import collectd
import errno
import socket
+from string import maketrans
from time import time
from traceback import format_exc
@@ -78,10 +79,8 @@ def sanitize_field(field):
parentheses. Convert to lower case if configured to do so.
"""
field = field.strip()
- field = field.replace('.', metric_separator)
- field = field.replace(' ', metric_separator)
- field = field.replace('(', '')
- field = field.replace(')', '')
+ trans = maketrans(' .', metric_separator * 2)
+ field = field.translate(trans, '()')
if lowercase_metric_names:
field = field.lower()
return field

0 comments on commit 461e307

Please sign in to comment.