Skip to content

Commit d7900d5

Browse files
committed
doc: Run blacken-docs on the mardown docs
1 parent 4227a37 commit d7900d5

File tree

7 files changed

+54
-48
lines changed

7 files changed

+54
-48
lines changed

sphinx-doc/cli.md

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,12 @@ router bgp 65111
4343
That CLI command is the equivalent of running this
4444
{func}`~ciscoconfparse2.CiscoConfParse.find_parent_objects` script:
4545

46-
```python
46+
```pycon
4747
>>> from ciscoconfparse2 import CiscoConfParse
48-
>>> parse = CiscoConfParse('conf/path/or/file/glob.conf')
49-
>>> for obj in parse.find_parent_objects(['router bgp'):
48+
>>> parse = CiscoConfParse("conf/path/or/file/glob.conf")
49+
>>> for obj in parse.find_parent_objects(["router bgp"]):
5050
... print(obj.text)
51+
...
5152
>>>
5253
```
5354

@@ -75,13 +76,14 @@ default-information originate
7576
That CLI command is the equivalent of running this
7677
{func}`~ciscoconfparse2.CiscoConfParse.find_child_objects` script:
7778

78-
```python
79+
```pycon
7980
>>> from ciscoconfparse2 import CiscoConfParse
80-
>>> parse = CiscoConfParse('conf/path/or/file/glob.conf')
81-
>>> for obj in parse.find_child_objects(['router bgp',
82-
... 'address-family',
83-
... 'default-information']):
81+
>>> parse = CiscoConfParse("conf/path/or/file/glob.conf")
82+
>>> for obj in parse.find_child_objects(
83+
... ["router bgp", "address-family", "default-information"]
84+
... ):
8485
... print(obj.text)
86+
...
8587
>>>
8688
```
8789

@@ -110,12 +112,12 @@ Output as : raw_text
110112
That CLI command is the equivalent of running this
111113
{func}`~ciscoconfparse2.CiscoConfParse.find_object_branches` script:
112114

113-
```python
115+
```pycon
114116
>>> from ciscoconfparse2 import CiscoConfParse
115-
>>> parse = CiscoConfParse('conf/path/or/file/glob.conf')
116-
>>> for branch in parse.find_object_branches(['router bgp',
117-
... 'address-family',
118-
... 'default-information']):
117+
>>> parse = CiscoConfParse("conf/path/or/file/glob.conf")
118+
>>> for branch in parse.find_object_branches(
119+
... ["router bgp", "address-family", "default-information"]
120+
... ):
119121
... print([obj.text for obj in branch])
120122
...
121123
>>>

sphinx-doc/example_complex.md

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Save this code in a file named example.py
1414
from ciscoconfparse2 import CiscoConfParse
1515
from ciscoconfparse2 import IPv4Obj
1616

17+
1718
def intf_csv(intf_obj) -> str:
1819
"""
1920
:return: CSV for each interface object.
@@ -24,44 +25,48 @@ def intf_csv(intf_obj) -> str:
2425
# something like 'interface Loopback0'
2526
intf_name = " ".join(intf_obj.split()[1:])
2627

27-
admin_status = intf_obj.re_match_iter_typed("^\s+(shutdown)",
28-
default="not_shutdown",
29-
result_type=str)
28+
admin_status = intf_obj.re_match_iter_typed(
29+
"^\s+(shutdown)", default="not_shutdown", result_type=str
30+
)
3031

3132
# Search children of all interfaces for a regex match and return
3233
# the value matched in regex match group 1. If there is no match,
3334
# return a default value: 0.0.0.1/32
34-
addr_netmask = intf_obj.re_match_iter_typed(r"^\s+ip\saddress\s(\d+\.\d+\.\d+\.\d+\s\S+)",
35-
result_type=IPv4Obj,
36-
group=1,
37-
default=IPv4Obj("0.0.0.1/32"))
35+
addr_netmask = intf_obj.re_match_iter_typed(
36+
r"^\s+ip\saddress\s(\d+\.\d+\.\d+\.\d+\s\S+)",
37+
result_type=IPv4Obj,
38+
group=1,
39+
default=IPv4Obj("0.0.0.1/32"),
40+
)
3841

3942
# Find the description and replace all commas in it
4043
description = intf_obj.re_match_iter_typed("description\s+(\S.*)").replace(",", "_")
4144

42-
switchport_status = intf_obj.re_match_iter_typed("(switchport)",
43-
default="not_switched")
45+
switchport_status = intf_obj.re_match_iter_typed(
46+
"(switchport)", default="not_switched"
47+
)
4448

4549
# Return a csv based on whether this is a switchport
4650
if switchport_status == "not_switched":
4751
return f"{intf_name},{admin_status},{addr_netmask.as_cidr_addr},{switchport_status},,,{description}"
4852

4953
else:
5054
# Only calculate switchport values if this is a switchport
51-
trunk_access = intf_obj.re_match_iter_typed("switchport mode (trunk)",
52-
default="access",
53-
result_type=str)
54-
access_vlan = intf_obj.re_match_iter_typed("switchport access vlan (\d+)",
55-
default=1,
56-
result_type=int)
55+
trunk_access = intf_obj.re_match_iter_typed(
56+
"switchport mode (trunk)", default="access", result_type=str
57+
)
58+
access_vlan = intf_obj.re_match_iter_typed(
59+
"switchport access vlan (\d+)", default=1, result_type=int
60+
)
5761

5862
# Return the CSV string of values...
5963
return f"{intf_name},{admin_status},{switchport_status},{trunk_access},{access_vlan},{description}"
6064

61-
parse = CiscoConfParse('tests/fixtures/configs/sample_08.ios', syntax='ios')
65+
66+
parse = CiscoConfParse("tests/fixtures/configs/sample_08.ios", syntax="ios")
6267

6368
# Find interface BaseCfgLine() instances...
64-
for intf_obj in parse.find_objects('^interface'):
69+
for intf_obj in parse.find_objects("^interface"):
6570
print(intf_csv(intf_obj))
6671
```
6772

sphinx-doc/example_simple.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ from ciscoconfparse2 import CiscoConfParse
2828
# !
2929

3030
# Search a configuration in the test fixutres directory
31-
parse = CiscoConfParse('tests/fixtures/configs/sample_02.ios', syntax='ios')
31+
parse = CiscoConfParse("tests/fixtures/configs/sample_02.ios", syntax="ios")
3232

3333
# Find a parent line containing 'interface' and child line with 'shutdown'
34-
for intf_obj in parse.find_parent_objects(['interface', 'shutdown']):
34+
for intf_obj in parse.find_parent_objects(["interface", "shutdown"]):
3535
intf_name = " ".join(intf_obj.split()[1:])
3636
print(f"Shutdown: {intf_name}")
3737
```

sphinx-doc/factory_hsrp.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ The following script should be used to extract the HSRP Groups from `GigabitEthe
3232
```python
3333
from ciscoconfparse2 import CiscoConfParse
3434

35-
parse = CiscoConfParse("/path/to/config/file",
36-
syntax="ios",
37-
factory=True)
35+
parse = CiscoConfParse("/path/to/config/file", syntax="ios", factory=True)
3836

3937
hsrp_intf = parse.find_objects("interface GigabitEthernet1/0")[0]
4038

sphinx-doc/intro.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ iterating in a loop (because two different interfaces have `parameter01`). Howev
9999
[ciscoconfparse2] can easily identify it by searching a list of elements with
100100
{py:meth}`~ciscoconfparse2.CiscoConfParse.find_child_objects`:
101101

102-
```python
102+
```pycon
103103
>>> from ciscoconfparse2 import CiscoConfParse
104104
>>> # Assume we parsed the config into 'parse'
105105
>>> parse
@@ -114,7 +114,7 @@ iterating in a loop (because two different interfaces have `parameter01`). Howev
114114
However, you can still get multiple children by using a less-specific
115115
regex:
116116

117-
```python
117+
```pycon
118118
>>>
119119
>>> # Expect to see a list of two children here... search across
120120
>>> # any Ethernet feature
@@ -124,7 +124,7 @@ regex:
124124

125125
Finally, you can still get parent objects with {py:meth}`~ciscoconfparse2.CiscoConfParse.find_parent_objects`:
126126

127-
```python
127+
```pycon
128128
>>> parse.find_parent_objects(["Ethernet", "feature01", "parameter"])
129129
[<IOSCfgLine # 3 'interface Ethernet0/1'>]
130130
```
@@ -144,14 +144,15 @@ layer2 trunks; the interface name is stored on one line, and the trunk
144144
configuration is stored somewhere below the interface name. With
145145
ciscoconfparse, it's really this easy...
146146

147-
```python
147+
```pycon
148148
>>> from ciscoconfparse2 import CiscoConfParse
149-
>>> parse = CiscoConfParse('/tftpboot/largeConfig.conf', syntax='ios', factory=False)
149+
>>> parse = CiscoConfParse("/tftpboot/largeConfig.conf", syntax="ios", factory=False)
150150
>>>
151151
>>> # Find parent interfaces that are configured with 'switchport trunk'
152152
>>> dot1q_trunks = parse.find_parent_objects(["^interface", "switchport trunk"])
153153
>>> for intf in dot1q_trunks:
154154
... print(intf)
155+
...
155156
<IOSCfgLine # 217 'interface GigabitEthernet1/1'>
156157
<IOSCfgLine # 237 'interface GigabitEthernet1/2'>
157158
...

sphinx-doc/tutorial_build_diffs.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ interface Serial1/1
6565
The script below will build read the configurations from disk and check to see whether
6666
there are diffs.
6767

68-
```python
68+
```pycon
6969
>>> from ciscoconfparse2.ciscoconfparse2 import Diff
7070
>>> # Parse the original configuration
71-
>>> old_config = '/tftpboot/bucksnort_before.conf'
72-
>>> new_config = '/tftpboot/bucksnort_after.conf'
71+
>>> old_config = "/tftpboot/bucksnort_before.conf"
72+
>>> new_config = "/tftpboot/bucksnort_after.conf"
7373
>>> diff = Diff(old_config=old_config, new_config=new_config)
7474
>>> diff.get_diff()
7575
['interface Serial1/0', ' mpls ip']
@@ -88,11 +88,11 @@ interface Serial1/0
8888

8989
The script below will build read the configurations from disk and build rollback diff configs.
9090

91-
```python
91+
```pycon
9292
>>> from ciscoconfparse2.ciscoconfparse2 import Diff
9393
>>> # Parse the original configuration
94-
>>> old_config = '/tftpboot/bucksnort_before.conf'
95-
>>> new_config = '/tftpboot/bucksnort_after.conf'
94+
>>> old_config = "/tftpboot/bucksnort_before.conf"
95+
>>> new_config = "/tftpboot/bucksnort_after.conf"
9696
>>> diff = Diff(old_config=old_config, new_config=new_config)
9797
>>> diff.get_rollback()
9898
['interface Serial1/0', ' mpls ip']

sphinx-doc/tutorial_parent_child.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ The assuming we use the configuration in the example above,
161161
configuration for matching config objects and stores a list of
162162
{class}`~ciscoconfparse2.models_cisco.IOSCfgLine` objects in `serial_objs`.
163163

164-
```python
164+
```pycon
165165
>>> serial_objs
166166
[<IOSCfgLine # 14 'interface Serial1/0'>,
167167
<IOSCfgLine # 18 'interface Serial1/1'>,
@@ -251,7 +251,7 @@ running globally on this device.
251251

252252
Results:
253253

254-
```python
254+
```pycon
255255
>>> cdp_intfs
256256
[<IOSCfgLine # 14 'interface Serial1/0'>, <IOSCfgLine # 18 'interface Serial1/1'>, <IOSCfgLine # 23 'interface Serial1/2'>]
257257
```

0 commit comments

Comments
 (0)