Skip to content

Commit d389b84

Browse files
committed
More compatability changes
Update several compat changes that were missed or added since origional commits - StringIO - urllib - print function
1 parent dfbe06e commit d389b84

File tree

8 files changed

+18
-22
lines changed

8 files changed

+18
-22
lines changed

src/collectors/etcdstat/etcdstat.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
"""
1414

1515
import diamond.collector
16+
import diamond.pycompat
1617
import json
17-
import urllib2
1818

1919
METRICS_KEYS = ['sendPkgRate',
2020
'recvPkgRate',
@@ -100,8 +100,8 @@ def get_metrics(self, category):
100100
url = "%s://%s:%s/v2/stats/%s" % (protocol, self.config['host'],
101101
self.config['port'], category)
102102

103-
return json.load(urllib2.urlopen(url, **opts))
104-
except (urllib2.HTTPError, ValueError), err:
103+
return json.load(diamond.pycompat.urlopen(url, **opts))
104+
except (HTTPError, ValueError) as err:
105105
self.log.error('Unable to read JSON response: %s' % err)
106106
return {}
107107

src/collectors/eventstoreprojections/eventstoreprojections.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717
1818
"""
1919

20-
import urllib2
2120
import json
2221
import diamond.collector
23-
22+
import diamond.pycompat
2423

2524
class EventstoreProjectionsCollector(diamond.collector.Collector):
2625

@@ -64,7 +63,7 @@ def _json_to_flat_metrics(self, prefix, data):
6463
for k, v in self._json_to_flat_metrics(
6564
"%s.%s" % (prefix, key), value):
6665
yield k, v
67-
elif isinstance(value, basestring):
66+
elif isinstance(value, str):
6867
if value == "Running":
6968
value = 1
7069
yield ("%s.%s" % (prefix, key), value)
@@ -91,12 +90,12 @@ def collect(self):
9190
self.config['route']
9291
)
9392

94-
req = urllib2.Request(eventstore_host, headers=self.config['headers'])
93+
req = diamond.pycompat.Request(eventstore_host, headers=self.config['headers'])
9594
req.add_header('Content-type', 'application/json')
9695

9796
try:
98-
resp = urllib2.urlopen(req)
99-
except urllib2.URLError as e:
97+
resp = diamond.pycompat.urlopen(req)
98+
except URLError as e:
10099
self.log.error("Can't open url %s. %s", eventstore_host, e)
101100
else:
102101
content = resp.read()

src/collectors/fluentd/fluentd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"""
2121

2222
import diamond.collector
23-
import urllib2
23+
import diamond.pycompat
2424
import json
2525

2626

src/collectors/jolokia/jolokia.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def __init__(self, *args, **kwargs):
139139

140140
self.domains = []
141141
if 'domains' in self.config:
142-
if isinstance(self.config['domains'], basestring):
142+
if isinstance(self.config['domains'], str):
143143
for domain in self.config['domains'].split('|'):
144144
self.domains.append(domain.strip())
145145
elif isinstance(self.config['domains'], list):

src/collectors/mesos_cgroup/mesos_cgroup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
"""
2424

2525
import diamond.collector
26+
import diamond.pycompat
2627
import json
27-
import urllib2
2828
import os
2929

3030

@@ -125,8 +125,8 @@ def get_mesos_state(self):
125125
self.config['port'],
126126
self.config['mesos_state_path'])
127127

128-
return json.load(urllib2.urlopen(url))
129-
except (urllib2.HTTPError, ValueError), err:
128+
return json.load(diamond.pycompat.urlopen(url))
129+
except (HTTPError, ValueError) as err:
130130
self.log.error('Unable to read JSON response: %s' % err)
131131
return {}
132132

src/collectors/mesos_cgroup/test/testmesos_cgroup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def urlopen_se(url):
3535
if url == 'http://localhost:5051/state.json':
3636
return self.getFixture('state.json')
3737
else:
38-
print url
38+
print(url)
3939
raise NotImplementedError()
4040

4141
def listdir_se(directory):
@@ -48,7 +48,7 @@ def listdir_se(directory):
4848
if directory in cgroup_directories:
4949
return ["b0d5971e-915c-414b-aa25-0da46e64ff4e"]
5050
else:
51-
print directory
51+
print(directory)
5252
raise NotImplementedError()
5353

5454
def isdir_se(directory):
@@ -61,7 +61,7 @@ def isdir_se(directory):
6161
if directory in task_directories:
6262
return True
6363
else:
64-
print directory
64+
print(directory)
6565
raise NotImplementedError()
6666

6767
def open_se(path, mode='r', create=True):

src/collectors/xfs/test/testxfs.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88
from test import Mock
99
from test import patch
1010

11-
try:
12-
from cStringIO import StringIO
13-
except ImportError:
14-
from StringIO import StringIO
11+
from test import StringIO
1512

1613
from diamond.collector import Collector
1714
from xfs import XFSCollector

src/diamond/handler/tsdb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def __init__(self, config=None):
7777
self.timeout = int(self.config['timeout'])
7878
self.metric_format = str(self.config['format'])
7979
self.tags = ""
80-
if isinstance(self.config['tags'], basestring):
80+
if isinstance(self.config['tags'], str):
8181
self.tags = self.config['tags']
8282
elif isinstance(self.config['tags'], list):
8383
for tag in self.config['tags']:

0 commit comments

Comments
 (0)