Skip to content

Commit 8da9ca8

Browse files
authored
Remove last batch of easy 'six' dependencies (#18624)
1 parent ddf0510 commit 8da9ca8

File tree

7 files changed

+12
-30
lines changed

7 files changed

+12
-30
lines changed

citrix_hypervisor/datadog_checks/citrix_hypervisor/check.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
# All rights reserved
33
# Licensed under a 3-clause BSD style license (see LICENSE)
44
from typing import Any, Dict, List # noqa: F401
5+
from xmlrpc.client import ServerProxy
56

67
import yaml
7-
from six.moves import xmlrpc_client as xmlrpclib
88

99
from datadog_checks.base import AgentCheck, ConfigurationError
1010
from datadog_checks.base.ddyaml import yaml_load_force_loader
@@ -94,7 +94,7 @@ def _get_master_session(self, session):
9494
master_address = session['ErrorDescription'][1]
9595
if not master_address.startswith('http://'):
9696
master_address = 'http://' + master_address
97-
master_xenserver = xmlrpclib.Server(master_address)
97+
master_xenserver = ServerProxy(master_address)
9898

9999
# Master credentials can be different, we could specify new `master_username` and
100100
# `master_password` options later if requested
@@ -109,7 +109,7 @@ def _get_master_session(self, session):
109109
def open_session(self):
110110
# type: () -> Dict[str, str]
111111
try:
112-
self.xenserver = xmlrpclib.Server(self._base_url)
112+
self.xenserver = ServerProxy(self._base_url)
113113
except Exception as e:
114114
self.log.warning(str(e))
115115
return {}

citrix_hypervisor/tests/test_citrix_hypervisor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
],
2828
)
2929
def test_open_session(instance, side_effect, expected_session, tag):
30-
with mock.patch('six.moves.xmlrpc_client.Server', side_effect=side_effect):
30+
with mock.patch('datadog_checks.citrix_hypervisor.check.ServerProxy', side_effect=side_effect):
3131
check = CitrixHypervisorCheck('citrix_hypervisor', {}, [instance])
3232
session = check.open_session()
3333

@@ -38,7 +38,7 @@ def test_open_session(instance, side_effect, expected_session, tag):
3838
@pytest.mark.usefixtures('mock_responses')
3939
@pytest.mark.parametrize('server_type', [pytest.param('master'), pytest.param('slave')])
4040
def test_check(aggregator, dd_run_check, instance, server_type):
41-
with mock.patch('six.moves.xmlrpc_client.Server', return_value=mocked_xenserver(server_type)):
41+
with mock.patch('datadog_checks.citrix_hypervisor.check.ServerProxy', return_value=mocked_xenserver(server_type)):
4242
check = CitrixHypervisorCheck('citrix_hypervisor', {}, [instance])
4343
dd_run_check(check)
4444

citrix_hypervisor/tests/test_metadata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def test_collect_metadata(datadog_agent, instance):
3131
xenserver.session.get_this_host.return_value = {'Status': 'Success', 'Value': 'hostref'}
3232
xenserver.host.get_software_version.return_value = content
3333

34-
with mock.patch('six.moves.xmlrpc_client.Server', return_value=xenserver):
34+
with mock.patch('datadog_checks.citrix_hypervisor.check.ServerProxy', return_value=xenserver):
3535
check.check(None)
3636
datadog_agent.assert_metadata('test:123', version_metadata)
3737
datadog_agent.assert_metadata_count(len(version_metadata))

datadog_checks_tests_helper/datadog_test_libs/win/pdh_mocks.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
# All rights reserved
33
# Licensed under a 3-clause BSD style license (see LICENSE)
44
import os
5+
import winreg
56
from collections import defaultdict
67

78
import mock
89
import pytest
9-
from six import PY3
10-
from six.moves import winreg
1110

1211
HERE = os.path.abspath(os.path.dirname(__file__))
1312

@@ -19,10 +18,7 @@
1918

2019
@pytest.fixture
2120
def pdh_mocks_fixture():
22-
if PY3:
23-
regqueryvalueex = mock.patch('winreg.QueryValueEx', mock_QueryValueEx)
24-
else:
25-
regqueryvalueex = mock.patch('_winreg.QueryValueEx', mock_QueryValueEx)
21+
regqueryvalueex = mock.patch('winreg.QueryValueEx', mock_QueryValueEx)
2622

2723
pdhlookupbyindex = mock.patch('win32pdh.LookupPerfNameByIndex', mock_LookupPerfNameByIndex)
2824
pdhenumobjectitems = mock.patch('win32pdh.EnumObjectItems', mock_EnumObjectItems)
@@ -46,10 +42,7 @@ def pdh_mocks_fixture():
4642

4743
@pytest.fixture
4844
def pdh_mocks_fixture_bad_perf_strings():
49-
if PY3:
50-
regqueryvalueex = mock.patch('winreg.QueryValueEx', mock_QueryValueExWithRaise)
51-
else:
52-
regqueryvalueex = mock.patch('_winreg.QueryValueEx', mock_QueryValueExWithRaise)
45+
regqueryvalueex = mock.patch('winreg.QueryValueEx', mock_QueryValueExWithRaise)
5346

5447
pdhlookupbyindex = mock.patch('win32pdh.LookupPerfNameByIndex', mock_LookupPerfNameByIndex)
5548
pdhenumobjectitems = mock.patch('win32pdh.EnumObjectItems', mock_EnumObjectItems)

gearmand/datadog_checks/gearmand/gearmand.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,10 @@
33
# All rights reserved
44
# Licensed under Simplified BSD License (see LICENSE)
55

6-
from six import PY2
6+
import python3_gearman as gearman
77

88
from datadog_checks.base import AgentCheck
99

10-
# Python 3 compatibility is a different library
11-
# It's a drop in replacement but has a different name
12-
# This will enable the check to use the new library
13-
if PY2:
14-
import gearman
15-
else:
16-
import python3_gearman as gearman
17-
1810
MAX_NUM_TASKS = 200
1911

2012

network/datadog_checks/network/ethtool.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
import struct
1212
from collections import defaultdict
1313

14-
from six import PY3
15-
1614
from .const import (
1715
ENA_METRIC_NAMES,
1816
ENA_METRIC_PREFIX,
@@ -41,7 +39,7 @@ def _byte_array_to_string(s):
4139
Convert a byte array to string
4240
b'hv_netvsc\x00\x00\x00\x00' -> 'hv_netvsc'
4341
"""
44-
s = s.tobytes() if PY3 else s.tostring()
42+
s = s.tobytes()
4543
s = s.partition(b'\x00')[0].decode('utf-8')
4644
return s
4745

postgres/datadog_checks/postgres/statement_samples.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
import psycopg2
1212
from cachetools import TTLCache
13-
from six import PY2
1413

1514
from datadog_checks.postgres.cursor import CommenterCursor, CommenterDictCursor
1615

@@ -884,6 +883,6 @@ def _get_truncation_state(track_activity_query_size, statement):
884883
# multi-byte characters that fall on the limit are left out. One caveat is that if a statement's length
885884
# happens to be greater or equal to the threshold below but isn't actually truncated, this
886885
# would falsely report it as a truncated statement
887-
statement_bytes = bytes(statement) if PY2 else bytes(statement, "utf-8")
886+
statement_bytes = bytes(statement, "utf-8")
888887
truncated = len(statement_bytes) >= track_activity_query_size - (MAX_CHARACTER_SIZE_IN_BYTES + 1)
889888
return StatementTruncationState.truncated if truncated else StatementTruncationState.not_truncated

0 commit comments

Comments
 (0)