Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 17c2cf0

Browse files
committed
style: Run latest version of Black against all files
1 parent debadc8 commit 17c2cf0

31 files changed

+1028
-258
lines changed

docs/configtree.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,10 @@ def node_style(cls):
7070
style = "style=filled " + nodestyle[module] + " "
7171
except:
7272
pass
73-
result = ' {0} [{1}URL="../module-{2}.html#panos.{3}" target="_top"];\n'.format(
74-
cls_name, style, module, cls
73+
result = (
74+
' {0} [{1}URL="../module-{2}.html#panos.{3}" target="_top"];\n'.format(
75+
cls_name, style, module, cls
76+
)
7577
)
7678
else:
7779
if style:

examples/dyn_address_group.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757

5858

5959
def main():
60-
6160
# Get command line arguments
6261
parser = argparse.ArgumentParser(
6362
description="Tag an IP address on a Palo Alto Networks Next generation Firewall"
@@ -111,7 +110,11 @@ def main():
111110
logging.basicConfig(format=logging_format, level=logging_level)
112111

113112
# Connect to the device and determine its type (Firewall or Panorama).
114-
device = PanDevice.create_from_device(args.hostname, args.username, args.password,)
113+
device = PanDevice.create_from_device(
114+
args.hostname,
115+
args.username,
116+
args.password,
117+
)
115118

116119
# Panorama does not have a userid API, so exit.
117120
# You can use the userid API on a firewall with the Panorama 'target'

examples/upgrade.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353

5454

5555
def main():
56-
5756
# Get command line arguments
5857
parser = argparse.ArgumentParser(
5958
description="Upgrade a Palo Alto Networks Firewall or Panorama to the specified version"
@@ -95,7 +94,11 @@ def main():
9594

9695
# Connect to the device and determine its type (Firewall or Panorama).
9796
# This is important to know what version to upgrade to next.
98-
device = PanDevice.create_from_device(args.hostname, args.username, args.password,)
97+
device = PanDevice.create_from_device(
98+
args.hostname,
99+
args.username,
100+
args.password,
101+
)
99102

100103
# Perform the upgrades in sequence with reboots between each upgrade
101104
device.software.upgrade_to_version(args.version, args.dryrun)

examples/userid.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353

5454

5555
def main():
56-
5756
# Get command line arguments
5857
parser = argparse.ArgumentParser(
5958
description="Update User-ID by adding or removing a user-to-ip mapping"
@@ -90,7 +89,11 @@ def main():
9089
logging.basicConfig(format=logging_format, level=logging_level)
9190

9291
# Connect to the device and determine its type (Firewall or Panorama).
93-
device = PanDevice.create_from_device(args.hostname, args.username, args.password,)
92+
device = PanDevice.create_from_device(
93+
args.hostname,
94+
args.username,
95+
args.password,
96+
)
9497

9598
logging.debug("Detecting type of device")
9699

panos/__init__.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,12 @@ def __repr__(self):
178178
return "PanOSVersion ('%s')" % str(self)
179179

180180
def __lt__(self, other):
181-
182181
# Handle 'latest' is always higher
183182
if isstring(other) and other == "latest":
184183
return True
185184

186185
other = stringToVersion(other)
187-
for (x, y) in zip(self.mainrelease, other.mainrelease):
186+
for x, y in zip(self.mainrelease, other.mainrelease):
188187
if x < y:
189188
return True
190189
if x > y:
@@ -203,7 +202,6 @@ def __ge__(self, other):
203202
return not self.__lt__(other)
204203

205204
def __eq__(self, other):
206-
207205
# Handle 'latest' which is always different
208206
if isstring(other) and other == "latest":
209207
return False
@@ -241,7 +239,9 @@ def tree_legend_dot():
241239
result += (
242240
'{module} [style=filled fillcolor={color} URL="{url}'
243241
'/module-{module}.html" target="_blank"];'.format(
244-
module=module, color=node_color(module), url=DOCUMENTATION_URL,
242+
module=module,
243+
color=node_color(module),
244+
url=DOCUMENTATION_URL,
245245
)
246246
)
247247
result += "}"
@@ -286,7 +286,11 @@ def string_or_list(value):
286286
value,
287287
]
288288
return (
289-
list(value) if "__iter__" in dir(value) else [value,]
289+
list(value)
290+
if "__iter__" in dir(value)
291+
else [
292+
value,
293+
]
290294
)
291295

292296

@@ -463,8 +467,8 @@ def node_color(module):
463467

464468
def object_classes():
465469
import inspect
466-
from panos import errors
467-
from panos import base
470+
471+
from panos import base, errors
468472

469473
current_module = sys.modules[__name__]
470474

@@ -476,15 +480,17 @@ def object_classes():
476480
if the_cls not in omits:
477481
omits.append(the_cls)
478482

479-
from panos import device
480-
from panos import firewall
481-
from panos import ha
482-
from panos import network
483-
from panos import objects
484-
from panos import panorama
485-
from panos import plugins
486-
from panos import policies
487-
from panos import predefined
483+
from panos import (
484+
device,
485+
firewall,
486+
ha,
487+
network,
488+
objects,
489+
panorama,
490+
plugins,
491+
policies,
492+
predefined,
493+
)
488494

489495
classes = {}
490496
for pkg in (device, firewall, ha, network, objects, panorama, policies, predefined):

panos/base.py

Lines changed: 61 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,6 @@ def element(self, with_children=True, comparable=False):
446446
nextelement = root
447447

448448
for section in path:
449-
450449
if section.find("|") != -1:
451450
# This is an element variable, so create an element containing
452451
# the variables's value
@@ -1648,7 +1647,13 @@ def _set_reference(
16481647
if var_type == "list":
16491648
if var is None:
16501649
update_needed = True
1651-
setattr(obj, reference_var, [self,])
1650+
setattr(
1651+
obj,
1652+
reference_var,
1653+
[
1654+
self,
1655+
],
1656+
)
16521657
if update:
16531658
obj.update(reference_var)
16541659
elif not isinstance(var, list):
@@ -1992,7 +1997,9 @@ def delete_similar(self):
19921997
for chunk in chunk_instances_for_delete_similar(instances):
19931998
dev.xapi.delete(
19941999
"{0}/{1}[{2}]".format(
1995-
xpath, prefix, " or ".join(joiner.format(x.uid) for x in chunk),
2000+
xpath,
2001+
prefix,
2002+
" or ".join(joiner.format(x.uid) for x in chunk),
19962003
),
19972004
retry_on_peer=self.HA_SYNC,
19982005
)
@@ -2124,14 +2131,13 @@ def hierarchy_info(self):
21242131
dict: Hierarchy information about this object.
21252132
"""
21262133
from panos.firewall import Firewall
2127-
from panos.panorama import DeviceGroup
2128-
from panos.panorama import Panorama
2129-
from panos.panorama import Template
2130-
from panos.panorama import TemplateStack
2134+
from panos.panorama import DeviceGroup, Panorama, Template, TemplateStack
21312135

21322136
classes = panos.object_classes()
21332137
configs = [
2134-
[self.__class__,],
2138+
[
2139+
self.__class__,
2140+
],
21352141
]
21362142
updated_configs = []
21372143

@@ -2143,7 +2149,10 @@ def hierarchy_info(self):
21432149
configs.pop(num)
21442150
for p in parents:
21452151
configs.append(
2146-
chain + [p,]
2152+
chain
2153+
+ [
2154+
p,
2155+
]
21472156
)
21482157
break
21492158
else:
@@ -2801,7 +2810,8 @@ def __getattr__(self, name):
28012810

28022811
raise AttributeError(
28032812
"'{0}' object has no attribute '{1}'".format(
2804-
self.__class__.__name__, str(name),
2813+
self.__class__.__name__,
2814+
str(name),
28052815
)
28062816
)
28072817

@@ -2886,9 +2896,7 @@ def __repr__(self):
28862896

28872897

28882898
class ValueEntry(VersionedPanObject):
2889-
"""Base class for objects that only have a value element.
2890-
2891-
"""
2899+
"""Base class for objects that only have a value element."""
28922900

28932901
ROOT = Root.VSYS
28942902
SUFFIX = ENTRY
@@ -3722,7 +3730,12 @@ def get_device_version(self):
37223730

37233731
@classmethod
37243732
def create_from_device(
3725-
cls, hostname, api_username=None, api_password=None, api_key=None, port=443,
3733+
cls,
3734+
hostname,
3735+
api_username=None,
3736+
api_password=None,
3737+
api_key=None,
3738+
port=443,
37263739
):
37273740
"""Factory method to create a :class:`panos.firewall.Firewall`
37283741
or :class:`panos.panorama.Panorama` object from a live device
@@ -3744,18 +3757,33 @@ def create_from_device(
37443757
# Create generic PanDevice to connect and get information
37453758
from panos import firewall, panorama
37463759

3747-
device = PanDevice(hostname, api_username, api_password, api_key, port,)
3760+
device = PanDevice(
3761+
hostname,
3762+
api_username,
3763+
api_password,
3764+
api_key,
3765+
port,
3766+
)
37483767
system_info = device.refresh_system_info()
37493768
version = system_info[0]
37503769
model = system_info[1]
37513770
if model == "Panorama" or model.startswith("M-"):
37523771
instance = panorama.Panorama(
3753-
hostname, api_username, api_password, device.api_key, port,
3772+
hostname,
3773+
api_username,
3774+
api_password,
3775+
device.api_key,
3776+
port,
37543777
)
37553778
else:
37563779
serial = system_info[2]
37573780
instance = firewall.Firewall(
3758-
hostname, api_username, api_password, device.api_key, serial, port,
3781+
hostname,
3782+
api_username,
3783+
api_password,
3784+
device.api_key,
3785+
serial,
3786+
port,
37593787
)
37603788
instance._set_version_and_version_info(version)
37613789
return instance
@@ -3903,10 +3931,16 @@ def method(self, *args, **kwargs):
39033931

39043932
def classify_exception(self, e):
39053933
if str(e) == "Invalid credentials.":
3906-
return err.PanInvalidCredentials(str(e), pan_device=self.pan_device,)
3934+
return err.PanInvalidCredentials(
3935+
str(e),
3936+
pan_device=self.pan_device,
3937+
)
39073938
elif str(e).startswith("URLError:"):
39083939
if str(e).endswith("timed out"):
3909-
return err.PanConnectionTimeout(str(e), pan_device=self.pan_device,)
3940+
return err.PanConnectionTimeout(
3941+
str(e),
3942+
pan_device=self.pan_device,
3943+
)
39103944
else:
39113945
# This could be that we have an old version of OpenSSL
39123946
# that doesn't support TLSv1.1, so check for that and give
@@ -4836,7 +4870,12 @@ def _commit(
48364870
logger.debug(
48374871
self.id
48384872
+ ": commit requested: commit_all:%s sync:%s sync_all:%s cmd:%s"
4839-
% (str(commit_all), str(sync), str(sync_all), cmd,)
4873+
% (
4874+
str(commit_all),
4875+
str(sync),
4876+
str(sync_all),
4877+
cmd,
4878+
)
48404879
)
48414880
if commit_all:
48424881
action = "all"
@@ -5603,7 +5642,8 @@ def is_ready(self, minutes=None, seconds=None):
56035642
end = None
56045643
if minutes is not None or seconds is not None:
56055644
end = datetime.datetime.now() + datetime.timedelta(
5606-
minutes=minutes or 0, seconds=seconds or 0,
5645+
minutes=minutes or 0,
5646+
seconds=seconds or 0,
56075647
)
56085648

56095649
while True:

0 commit comments

Comments
 (0)