Python2/3 compatibility changes

Results from running 2to3 tooling.

Change-Id: I655fdf93635b70157595ca7b37352caad41c2b4d
(cherry picked from commit c444b81021)
This commit is contained in:
Thomas Bachman 2022-01-13 17:22:00 +00:00
parent dd7c9dde5c
commit 22ac1000f2
8 changed files with 78 additions and 75 deletions

View File

@ -10,7 +10,6 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from __future__ import absolute_import
import logging import logging

View File

@ -49,7 +49,7 @@ def update_service_policy_attributes(policy):
for item in np: for item in np:
dl = ["<dl class='dl-horizontal'>"] dl = ["<dl class='dl-horizontal'>"]
dl.extend(["<dt>%s<dt><dd>%s</dd>" % dl.extend(["<dt>%s<dt><dd>%s</dd>" %
(k, v) for k, v in item.items()]) (k, v) for k, v in list(item.items())])
dl.append("</dl>") dl.append("</dl>")
tags.append("".join(dl)) tags.append("".join(dl))
params = mark_safe("".join(tags)) params = mark_safe("".join(tags))
@ -298,7 +298,7 @@ def update_l3_policy_attributes(request, l3_policy):
reverse(url, kwargs={'external_connectivity_id': x.id}) + \ reverse(url, kwargs={'external_connectivity_id': x.id}) + \
"'>" + x.name + "</a>" + " : " + \ "'>" + x.name + "</a>" + " : " + \
l3_policy.external_segments[x.id][0] + "</li>" l3_policy.external_segments[x.id][0] + "</li>"
for ec in l3_policy.external_segments.keys(): for ec in list(l3_policy.external_segments.keys()):
external_connectivity = client.get_externalconnectivity(request, external_connectivity = client.get_externalconnectivity(request,
ec) ec)
value.append(li(external_connectivity)) value.append(li(external_connectivity))

View File

@ -47,16 +47,16 @@ class DeletePolicyRuleSetLink(tables.DeleteAction):
@staticmethod @staticmethod
def action_present(count): def action_present(count):
return ungettext_lazy( return ungettext_lazy(
u"Delete Policy Rule Set", "Delete Policy Rule Set",
u"Delete Policy Rule Sets", "Delete Policy Rule Sets",
count count
) )
@staticmethod @staticmethod
def action_past(count): def action_past(count):
return ungettext_lazy( return ungettext_lazy(
u"Scheduled deletion of Policy Rule Set", "Scheduled deletion of Policy Rule Set",
u"Scheduled deletion of Policy Rule Sets", "Scheduled deletion of Policy Rule Sets",
count count
) )
@ -89,16 +89,16 @@ class DeletePolicyRuleLink(tables.DeleteAction):
@staticmethod @staticmethod
def action_present(count): def action_present(count):
return ungettext_lazy( return ungettext_lazy(
u"Delete Policy Rule", "Delete Policy Rule",
u"Delete Policy Rules", "Delete Policy Rules",
count count
) )
@staticmethod @staticmethod
def action_past(count): def action_past(count):
return ungettext_lazy( return ungettext_lazy(
u"Scheduled deletion of Policy Rule", "Scheduled deletion of Policy Rule",
u"Scheduled deletion of Policy Rules", "Scheduled deletion of Policy Rules",
count count
) )
@ -131,16 +131,16 @@ class DeletePolicyClassifierLink(tables.DeleteAction):
@staticmethod @staticmethod
def action_present(count): def action_present(count):
return ungettext_lazy( return ungettext_lazy(
u"Delete Policy Classifier", "Delete Policy Classifier",
u"Delete Policy Classifiers", "Delete Policy Classifiers",
count count
) )
@staticmethod @staticmethod
def action_past(count): def action_past(count):
return ungettext_lazy( return ungettext_lazy(
u"Scheduled deletion of Policy Classifier", "Scheduled deletion of Policy Classifier",
u"Scheduled deletion of Policy Classifiers", "Scheduled deletion of Policy Classifiers",
count count
) )
@ -173,16 +173,16 @@ class DeletePolicyActionLink(tables.DeleteAction):
@staticmethod @staticmethod
def action_present(count): def action_present(count):
return ungettext_lazy( return ungettext_lazy(
u"Delete Policy Action", "Delete Policy Action",
u"Delete Policy Actions", "Delete Policy Actions",
count count
) )
@staticmethod @staticmethod
def action_past(count): def action_past(count):
return ungettext_lazy( return ungettext_lazy(
u"Scheduled deletion of Policy Action", "Scheduled deletion of Policy Action",
u"Scheduled deletion of Policy Actions", "Scheduled deletion of Policy Actions",
count count
) )

View File

@ -81,9 +81,11 @@ class AddL3PolicyForm(forms.SelfHandlingForm):
ipversion = int(cleaned_data['ip_version']) ipversion = int(cleaned_data['ip_version'])
subnet_prefix_length = int(cleaned_data['subnet_prefix_length']) subnet_prefix_length = int(cleaned_data['subnet_prefix_length'])
msg = _("Subnet prefix out of range.") msg = _("Subnet prefix out of range.")
if ipversion == 4 and subnet_prefix_length not in range(2, 31): if ipversion == 4 and subnet_prefix_length not in list(
range(2, 31)):
raise forms.ValidationError(msg) raise forms.ValidationError(msg)
if ipversion == 6 and subnet_prefix_length not in range(2, 128): if ipversion == 6 and subnet_prefix_length not in list(
range(2, 128)):
raise forms.ValidationError(msg) raise forms.ValidationError(msg)
return cleaned_data return cleaned_data
@ -155,7 +157,7 @@ class UpdateL3PolicyForm(AddL3PolicyForm):
if bool(l3['external_segments']): if bool(l3['external_segments']):
es_choices = [] es_choices = []
es_initial = [] es_initial = []
for key, value in l3['external_segments'].items(): for key, value in list(l3['external_segments'].items()):
val = 'ES:' + key + ',IP:' + value[0] val = 'ES:' + key + ',IP:' + value[0]
es_choices.append((val, val)) es_choices.append((val, val))
es_initial.append(val) es_initial.append(val)
@ -173,9 +175,11 @@ class UpdateL3PolicyForm(AddL3PolicyForm):
ipversion = int(cleaned_data['ip_version']) ipversion = int(cleaned_data['ip_version'])
subnet_prefix_length = int(cleaned_data['subnet_prefix_length']) subnet_prefix_length = int(cleaned_data['subnet_prefix_length'])
msg = _("Subnet prefix out of range.") msg = _("Subnet prefix out of range.")
if ipversion == 4 and subnet_prefix_length not in range(2, 31): if ipversion == 4 and subnet_prefix_length not in list(
range(2, 31)):
raise forms.ValidationError(msg) raise forms.ValidationError(msg)
if ipversion == 6 and subnet_prefix_length not in range(2, 128): if ipversion == 6 and subnet_prefix_length not in list(
range(2, 128)):
raise forms.ValidationError(msg) raise forms.ValidationError(msg)
if cleaned_data['external_segments']: if cleaned_data['external_segments']:
dic = {} dic = {}

View File

@ -46,16 +46,16 @@ class DeleteL2PolicyLink(tables.DeleteAction):
@staticmethod @staticmethod
def action_present(count): def action_present(count):
return ungettext_lazy( return ungettext_lazy(
u"Delete L2 Policy", "Delete L2 Policy",
u"Delete L2 Policies", "Delete L2 Policies",
count count
) )
@staticmethod @staticmethod
def action_past(count): def action_past(count):
return ungettext_lazy( return ungettext_lazy(
u"Scheduled deletion of L2 Policy", "Scheduled deletion of L2 Policy",
u"Scheduled deletion of L2 Policies", "Scheduled deletion of L2 Policies",
count count
) )
@ -107,16 +107,16 @@ class DeleteL3PolicyLink(tables.DeleteAction):
@staticmethod @staticmethod
def action_present(count): def action_present(count):
return ungettext_lazy( return ungettext_lazy(
u"Delete L3 Policy", "Delete L3 Policy",
u"Delete L3 Policies", "Delete L3 Policies",
count count
) )
@staticmethod @staticmethod
def action_past(count): def action_past(count):
return ungettext_lazy( return ungettext_lazy(
u"Scheduled deletion of L3 Policy", "Scheduled deletion of L3 Policy",
u"Scheduled deletion of L3 Policies", "Scheduled deletion of L3 Policies",
count count
) )
@ -170,16 +170,16 @@ class DeleteServicePolicyLink(tables.DeleteAction):
@staticmethod @staticmethod
def action_present(count): def action_present(count):
return ungettext_lazy( return ungettext_lazy(
u"Delete Network Service Policy", "Delete Network Service Policy",
u"Delete Network ServiceL3 Policies", "Delete Network ServiceL3 Policies",
count count
) )
@staticmethod @staticmethod
def action_past(count): def action_past(count):
return ungettext_lazy( return ungettext_lazy(
u"Scheduled deletion of Network Service Policy", "Scheduled deletion of Network Service Policy",
u"Scheduled deletion of Network Service Policies", "Scheduled deletion of Network Service Policies",
count count
) )
@ -235,16 +235,16 @@ class DeleteExternalConnectivityLink(tables.DeleteAction):
@staticmethod @staticmethod
def action_present(count): def action_present(count):
return ungettext_lazy( return ungettext_lazy(
u"Delete External Connectivity Policy", "Delete External Connectivity Policy",
u"Delete External Connectivity Policies", "Delete External Connectivity Policies",
count count
) )
@staticmethod @staticmethod
def action_past(count): def action_past(count):
return ungettext_lazy( return ungettext_lazy(
u"Scheduled deletion of External Connectivity Policy", "Scheduled deletion of External Connectivity Policy",
u"Scheduled deletion of External Connectivity Policies", "Scheduled deletion of External Connectivity Policies",
count count
) )
@ -284,16 +284,16 @@ class DeleteNATPoolLink(tables.DeleteAction):
@staticmethod @staticmethod
def action_present(count): def action_present(count):
return ungettext_lazy( return ungettext_lazy(
u"Delete NAT Pool", "Delete NAT Pool",
u"Delete NAT Pools", "Delete NAT Pools",
count count
) )
@staticmethod @staticmethod
def action_past(count): def action_past(count):
return ungettext_lazy( return ungettext_lazy(
u"Scheduled deletion of NAT Pool", "Scheduled deletion of NAT Pool",
u"Scheduled deletion of NAT Pools", "Scheduled deletion of NAT Pools",
count count
) )

View File

@ -45,16 +45,16 @@ class DeleteServiceChainSpecLink(tables.DeleteAction):
@staticmethod @staticmethod
def action_present(count): def action_present(count):
return ungettext_lazy( return ungettext_lazy(
u"Delete Service Chain Spec", "Delete Service Chain Spec",
u"Delete Service Chain Specs", "Delete Service Chain Specs",
count count
) )
@staticmethod @staticmethod
def action_past(count): def action_past(count):
return ungettext_lazy( return ungettext_lazy(
u"Scheduled deletion of Service Chain Spec", "Scheduled deletion of Service Chain Spec",
u"Scheduled deletion of Service Chain Specs", "Scheduled deletion of Service Chain Specs",
count count
) )
@ -105,16 +105,16 @@ class DeleteServiceChainNodeLink(tables.DeleteAction):
@staticmethod @staticmethod
def action_present(count): def action_present(count):
return ungettext_lazy( return ungettext_lazy(
u"Delete Service Chain Node", "Delete Service Chain Node",
u"Delete Service Chain Nodes", "Delete Service Chain Nodes",
count count
) )
@staticmethod @staticmethod
def action_past(count): def action_past(count):
return ungettext_lazy( return ungettext_lazy(
u"Scheduled deletion of Service Chain Node", "Scheduled deletion of Service Chain Node",
u"Scheduled deletion of Service Chain Nodes", "Scheduled deletion of Service Chain Nodes",
count count
) )
@ -166,16 +166,16 @@ class DeleteServiceChainInstanceLink(tables.DeleteAction):
@staticmethod @staticmethod
def action_present(count): def action_present(count):
return ungettext_lazy( return ungettext_lazy(
u"Delete Service Chain Instance", "Delete Service Chain Instance",
u"Delete Service Chain Instances", "Delete Service Chain Instances",
count count
) )
@staticmethod @staticmethod
def action_past(count): def action_past(count):
return ungettext_lazy( return ungettext_lazy(
u"Scheduled deletion of Service Chain Instance", "Scheduled deletion of Service Chain Instance",
u"Scheduled deletion of Service Chain Instances", "Scheduled deletion of Service Chain Instances",
count count
) )
@ -219,16 +219,16 @@ class DeleteServiceProfileLink(tables.DeleteAction):
@staticmethod @staticmethod
def action_present(count): def action_present(count):
return ungettext_lazy( return ungettext_lazy(
u"Delete Service Chain Profile", "Delete Service Chain Profile",
u"Delete Service Chain Profiles", "Delete Service Chain Profiles",
count count
) )
@staticmethod @staticmethod
def action_past(count): def action_past(count):
return ungettext_lazy( return ungettext_lazy(
u"Scheduled deletion of Service Chain Profile", "Scheduled deletion of Service Chain Profile",
u"Scheduled deletion of Service Chain Profiles", "Scheduled deletion of Service Chain Profiles",
count count
) )

View File

@ -160,7 +160,7 @@ class ServiceChainNodeDetailsTab(tabs.Tab):
def prepare_config_as_tree(self, config): def prepare_config_as_tree(self, config):
tree = [] tree = []
for key, value in config.iteritems(): for key, value in config.items():
node = {} node = {}
if isinstance(value, dict): if isinstance(value, dict):
node = self.prepare_root_node(value) node = self.prepare_root_node(value)
@ -184,7 +184,7 @@ class ServiceChainNodeDetailsTab(tabs.Tab):
def prepare_children(self, obj): def prepare_children(self, obj):
children = [] children = []
for key, value in obj.iteritems(): for key, value in obj.items():
node = {} node = {}
child = self.json2array(value) child = self.json2array(value)
node["text"] = key node["text"] = key
@ -195,7 +195,7 @@ class ServiceChainNodeDetailsTab(tabs.Tab):
def json2array(self, obj): def json2array(self, obj):
arr = [] arr = []
for key, value in obj.iteritems(): for key, value in obj.items():
node = {} node = {}
if isinstance(value, dict): if isinstance(value, dict):
children = self.json2array(value) children = self.json2array(value)

View File

@ -49,16 +49,16 @@ class DeletePTGLink(tables.DeleteAction):
@staticmethod @staticmethod
def action_present(count): def action_present(count):
return ungettext_lazy( return ungettext_lazy(
u"Delete Group", "Delete Group",
u"Delete Groups", "Delete Groups",
count count
) )
@staticmethod @staticmethod
def action_past(count): def action_past(count):
return ungettext_lazy( return ungettext_lazy(
u"Scheduled deletion of Group", "Scheduled deletion of Group",
u"Scheduled deletion of Groups", "Scheduled deletion of Groups",
count count
) )
@ -122,16 +122,16 @@ class DeleteExternalPTGLink(tables.DeleteAction):
@staticmethod @staticmethod
def action_present(count): def action_present(count):
return ungettext_lazy( return ungettext_lazy(
u"Delete External Group", "Delete External Group",
u"Delete External Groups", "Delete External Groups",
count count
) )
@staticmethod @staticmethod
def action_past(count): def action_past(count):
return ungettext_lazy( return ungettext_lazy(
u"Scheduled deletion of External Group", "Scheduled deletion of External Group",
u"Scheduled deletion of External Groups", "Scheduled deletion of External Groups",
count count
) )
@ -192,16 +192,16 @@ class RemoveVMLink(tables.DeleteAction):
@staticmethod @staticmethod
def action_present(count): def action_present(count):
return ungettext_lazy( return ungettext_lazy(
u"Delete Member", "Delete Member",
u"Delete Members", "Delete Members",
count count
) )
@staticmethod @staticmethod
def action_past(count): def action_past(count):
return ungettext_lazy( return ungettext_lazy(
u"Deleted Member", "Deleted Member",
u"Deleted Members", "Deleted Members",
count count
) )