Skip to content

Commit fef7ce1

Browse files
committed
Fix for Python 3.10
Allow newer versions of requests-toolbelt Fix all uses of collections
1 parent 18a2f45 commit fef7ce1

File tree

4 files changed

+24
-15
lines changed

4 files changed

+24
-15
lines changed

pytos/common/rest_requests.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11

2-
import collections
2+
try:
3+
from collections import Iterable
4+
except:
5+
from collections.abc import Iterable
36
import datetime
47
import hashlib
58
import http.cookiejar
@@ -222,7 +225,7 @@ def _ensure_response_status(self):
222225
status_code_ok = False
223226

224227
if status_code_ok:
225-
if isinstance(self.expected_status_codes, collections.Iterable):
228+
if isinstance(self.expected_status_codes, Iterable):
226229
if self.response.status_code not in self.expected_status_codes:
227230
status_code_ok = False
228231
elif isinstance(self.expected_status_codes, int):

pytos/securechange/xml_objects/rest.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import datetime
22
import time
33
import enum
4-
from collections import OrderedDict
4+
try:
5+
from collections import OrderedDict
6+
except:
7+
from collections.abc import OrderedDict
8+
59

610
# For backward compatibility import FileLock
711
from pytos.securechange.xml_objects.restapi.step.rule_decommission.rule_decommission import Step_Field_Rule_Decommission
@@ -2132,4 +2136,3 @@ def from_xml_node(cls, xml_node):
21322136
class RejectComment(Comment):
21332137
def __init__(self, comment):
21342138
super().__init__(comment, Elements.REJECT_COMMENT)
2135-

pytos/securetrack/helpers.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# coding=utf-8
2-
import collections
2+
try:
3+
from collections import Iterable
4+
except:
5+
from collections.abc import Iterable
36
import csv
47
import io
58
import itertools
@@ -1320,7 +1323,7 @@ def get_rule_documentation_by_device_id_and_rule_id(self, device_id, rule_id):
13201323
def get_rule_base(self, get_documentation=False, device_ids=None):
13211324
"""Get the rules for each of the devices configured in SecureTrack.
13221325
1323-
:type device_ids: collections.Iterable[int]
1326+
:type device_ids: Iterable[int]
13241327
:param device_ids: If specified, get the rule base only for the specified devices.
13251328
:param get_documentation: Whether or not to get the rule documentation together with the rule base.
13261329
:type get_documentation: bool
@@ -2140,13 +2143,13 @@ def get_services_by_device_and_object_ids(self, device_id, service_ids):
21402143
:param device_id: The device ID for which we want to get network objects.
21412144
:type device_id: int
21422145
:param service_ids: The ID of the service
2143-
:type service_ids: int|collections.Iterable[int]
2146+
:type service_ids: int|Iterable[int]
21442147
:return: The service for the specified device with the specified ID.
21452148
:rtype: Single_Service|Group_Service
21462149
:raise ValueError: If a device with the specified ID does not exist.
21472150
:raise IOError: If there was a communication problem trying to get the network objects.
21482151
"""
2149-
if isinstance(service_ids, collections.Iterable):
2152+
if isinstance(service_ids, Iterable):
21502153
service_ids = ",".join([str(service_id) for service_id in service_ids])
21512154
logger.info("Getting service with ID %s for device %s.", service_ids, device_id)
21522155
try:
@@ -2169,13 +2172,13 @@ def get_services_by_revision_and_object_ids(self, revision_id, service_ids=""):
21692172
:param revision_id: The revision ID for which we want to get network objects.
21702173
:type revision_id: int
21712174
:param service_ids: The ID of the service
2172-
:type service_ids: int|collections.Iterable[int]
2175+
:type service_ids: int|Iterable[int]
21732176
:return: The service for the specified revision with the specified ID.
21742177
:rtype: Services_List
21752178
:raise ValueError: If a revision with the specified ID does not exist.
21762179
:raise IOError: If there was a communication problem trying to get the services.
21772180
"""
2178-
if isinstance(service_ids, collections.Iterable):
2181+
if isinstance(service_ids, Iterable):
21792182
service_ids = ",".join([str(service_id) for service_id in service_ids])
21802183
logger.info("Getting service with ID %s for revision %s.", service_ids, revision_id)
21812184
try:
@@ -2198,14 +2201,14 @@ def get_network_objects_by_revision_and_object_ids(self, revision_id, network_ob
21982201
:param revision_id: The revision ID for which we want to get network objects.
21992202
:type revision_id: int
22002203
:param network_object_ids: The ID of the network object to get
2201-
:type network_object_ids: int|collections.Iterable[int]
2204+
:type network_object_ids: int|Iterable[int]
22022205
:return: The network objects for the specified revision.
22032206
:rtype: Network_Objects_List
22042207
:raise ValueError: If a revision with the specified ID does not exist.
22052208
:raise IOError: Ifp there was a communication problem trying to get the network objects.
22062209
"""
22072210
logger.info("Getting network object with ID %s for revision %s.", network_object_ids, revision_id)
2208-
if isinstance(network_object_ids, collections.Iterable):
2211+
if isinstance(network_object_ids, Iterable):
22092212
network_object_ids = ",".join([str(network_object_id) for network_object_id in network_object_ids])
22102213
try:
22112214
response_string = self.get_uri(
@@ -2227,14 +2230,14 @@ def get_network_objects_by_device_and_object_ids(self, device_id, network_object
22272230
:param device_id: The device ID for which we want to get network objects.
22282231
:type device_id: int
22292232
:param network_object_ids: The ID of the network object to get
2230-
:type network_object_ids: int|collections.Iterable[int]
2233+
:type network_object_ids: int|Iterable[int]
22312234
:return: The network objects for the specified device.
22322235
:rtype: Network_Objects_List
22332236
:raise ValueError: If a device with the specified ID does not exist.
22342237
:raise IOError: Ifp there was a communication problem trying to get the network objects.
22352238
"""
22362239
logger.info("Getting network object with ID %s for device %s.", network_object_ids, device_id)
2237-
if isinstance(network_object_ids, collections.Iterable):
2240+
if isinstance(network_object_ids, Iterable):
22382241
network_object_ids = ",".join([str(network_object_id) for network_object_id in network_object_ids])
22392242
try:
22402243
response_string = self.get_uri(

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def get_version():
4040
'netaddr>=0.7.14',
4141
'paramiko>=1.15.2',
4242
'requests>=2.6.0',
43-
'requests_toolbelt==0.7.1',
43+
'requests_toolbelt>=0.7.1',
4444
'netifaces==0.10.9',
4545
'dnspython3==1.15.0',
4646
'Mako',

0 commit comments

Comments
 (0)