| Conditions | 1 |
| Total Lines | 167 |
| Code Lines | 138 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | # encoding: utf-8 |
||
| 108 | def __init__(self, configurations, text=False): |
||
| 109 | _Configuration.__init__(self) |
||
| 110 | self.api_encoder = getenv().api.encoder |
||
| 111 | |||
| 112 | self._configurations = configurations |
||
| 113 | self._text = text |
||
| 114 | |||
| 115 | self.error = Error() |
||
| 116 | self.scope = Scope() |
||
| 117 | |||
| 118 | self.tokeniser = Tokeniser(self.scope, self.error) |
||
| 119 | |||
| 120 | params = (self.tokeniser, self.scope, self.error) |
||
| 121 | self.section = Section(*params) |
||
| 122 | self.process = ParseProcess(*params) |
||
| 123 | self.template = ParseTemplate(*params) |
||
| 124 | self.template_neighbor = ParseTemplateNeighbor(*params) |
||
| 125 | self.neighbor = ParseNeighbor(*params) |
||
| 126 | self.family = ParseFamily(*params) |
||
| 127 | self.addpath = ParseAddPath(*params) |
||
| 128 | self.nexthop = ParseNextHop(*params) |
||
| 129 | self.capability = ParseCapability(*params) |
||
| 130 | self.api = ParseAPI(*params) |
||
| 131 | self.api_send = ParseSend(*params) |
||
| 132 | self.api_receive = ParseReceive(*params) |
||
| 133 | self.static = ParseStatic(*params) |
||
| 134 | self.static_route = ParseStaticRoute(*params) |
||
| 135 | self.announce = SectionAnnounce(*params) |
||
| 136 | self.announce_ipv4 = AnnounceIPv4(*params) |
||
| 137 | self.announce_ipv6 = AnnounceIPv6(*params) |
||
| 138 | self.announce_l2vpn = AnnounceL2VPN(*params) |
||
| 139 | self.flow = ParseFlow(*params) |
||
| 140 | self.flow_route = ParseFlowRoute(*params) |
||
| 141 | self.flow_match = ParseFlowMatch(*params) |
||
| 142 | self.flow_then = ParseFlowThen(*params) |
||
| 143 | self.flow_scope = ParseFlowScope(*params) |
||
| 144 | self.l2vpn = ParseL2VPN(*params) |
||
| 145 | self.vpls = ParseVPLS(*params) |
||
| 146 | self.operational = ParseOperational(*params) |
||
| 147 | |||
| 148 | # We should check if name are unique when running Section.__init__ |
||
| 149 | |||
| 150 | self._structure = { |
||
| 151 | 'root': { |
||
| 152 | 'class': self.section, |
||
| 153 | 'commands': [], |
||
| 154 | 'sections': { |
||
| 155 | 'process': self.process.name, |
||
| 156 | 'neighbor': self.neighbor.name, |
||
| 157 | 'template': self.template.name, |
||
| 158 | }, |
||
| 159 | }, |
||
| 160 | self.process.name: {'class': self.process, 'commands': self.process.known.keys(), 'sections': {},}, |
||
| 161 | self.template.name: { |
||
| 162 | 'class': self.template, |
||
| 163 | 'commands': self.template.known.keys(), |
||
| 164 | 'sections': {'neighbor': self.template_neighbor.name,}, |
||
| 165 | }, |
||
| 166 | self.template_neighbor.name: { |
||
| 167 | 'class': self.template_neighbor, |
||
| 168 | 'commands': self.template_neighbor.known.keys(), |
||
| 169 | 'sections': { |
||
| 170 | 'family': self.family.name, |
||
| 171 | 'capability': self.capability.name, |
||
| 172 | 'add-path': self.addpath.name, |
||
| 173 | 'nexthop': self.nexthop.name, |
||
| 174 | 'api': self.api.name, |
||
| 175 | 'static': self.static.name, |
||
| 176 | 'flow': self.flow.name, |
||
| 177 | 'l2vpn': self.l2vpn.name, |
||
| 178 | 'operational': self.operational.name, |
||
| 179 | 'announce': self.announce.name, |
||
| 180 | }, |
||
| 181 | }, |
||
| 182 | self.neighbor.name: { |
||
| 183 | 'class': self.neighbor, |
||
| 184 | 'commands': self.neighbor.known.keys(), |
||
| 185 | 'sections': { |
||
| 186 | 'family': self.family.name, |
||
| 187 | 'capability': self.capability.name, |
||
| 188 | 'add-path': self.addpath.name, |
||
| 189 | 'nexthop': self.nexthop.name, |
||
| 190 | 'api': self.api.name, |
||
| 191 | 'static': self.static.name, |
||
| 192 | 'flow': self.flow.name, |
||
| 193 | 'l2vpn': self.l2vpn.name, |
||
| 194 | 'operational': self.operational.name, |
||
| 195 | 'announce': self.announce.name, |
||
| 196 | }, |
||
| 197 | }, |
||
| 198 | self.family.name: {'class': self.family, 'commands': self.family.known.keys(), 'sections': {},}, |
||
| 199 | self.capability.name: {'class': self.capability, 'commands': self.capability.known.keys(), 'sections': {},}, |
||
| 200 | self.nexthop.name: {'class': self.nexthop, 'commands': self.nexthop.known.keys(), 'sections': {},}, |
||
| 201 | self.addpath.name: {'class': self.addpath, 'commands': self.addpath.known.keys(), 'sections': {},}, |
||
| 202 | self.api.name: { |
||
| 203 | 'class': self.api, |
||
| 204 | 'commands': self.api.known.keys(), |
||
| 205 | 'sections': {'send': self.api_send.name, 'receive': self.api_receive.name,}, |
||
| 206 | }, |
||
| 207 | self.api_send.name: {'class': self.api_send, 'commands': self.api_send.known.keys(), 'sections': {},}, |
||
| 208 | self.api_receive.name: { |
||
| 209 | 'class': self.api_receive, |
||
| 210 | 'commands': self.api_receive.known.keys(), |
||
| 211 | 'sections': {}, |
||
| 212 | }, |
||
| 213 | self.announce.name: { |
||
| 214 | 'class': self.announce, |
||
| 215 | 'commands': self.announce.known.keys(), |
||
| 216 | 'sections': { |
||
| 217 | 'ipv4': self.announce_ipv4.name, |
||
| 218 | 'ipv6': self.announce_ipv6.name, |
||
| 219 | 'l2vpn': self.announce_l2vpn.name, |
||
| 220 | }, |
||
| 221 | }, |
||
| 222 | self.announce_ipv4.name: { |
||
| 223 | 'class': self.announce_ipv4, |
||
| 224 | 'commands': ['unicast', 'multicast', 'nlri-mpls', 'mpls-vpn', 'flow', 'flow-vpn'], |
||
| 225 | 'sections': {}, |
||
| 226 | }, |
||
| 227 | self.announce_ipv6.name: { |
||
| 228 | 'class': self.announce_ipv6, |
||
| 229 | 'commands': ['unicast', 'multicast', 'nlri-mpls', 'mpls-vpn', 'flow', 'flow-vpn'], |
||
| 230 | 'sections': {}, |
||
| 231 | }, |
||
| 232 | self.announce_l2vpn.name: {'class': self.announce_l2vpn, 'commands': ['vpls',], 'sections': {},}, |
||
| 233 | self.static.name: { |
||
| 234 | 'class': self.static, |
||
| 235 | 'commands': ['route', 'attributes'], |
||
| 236 | 'sections': {'route': self.static_route.name,}, |
||
| 237 | }, |
||
| 238 | self.static_route.name: { |
||
| 239 | 'class': self.static_route, |
||
| 240 | 'commands': self.static_route.known.keys(), |
||
| 241 | 'sections': {}, |
||
| 242 | }, |
||
| 243 | self.flow.name: { |
||
| 244 | 'class': self.flow, |
||
| 245 | 'commands': self.flow.known.keys(), |
||
| 246 | 'sections': {'route': self.flow_route.name,}, |
||
| 247 | }, |
||
| 248 | self.flow_route.name: { |
||
| 249 | 'class': self.flow_route, |
||
| 250 | 'commands': self.flow_route.known.keys(), |
||
| 251 | 'sections': { |
||
| 252 | 'match': self.flow_match.name, |
||
| 253 | 'then': self.flow_then.name, |
||
| 254 | 'scope': self.flow_scope.name, |
||
| 255 | }, |
||
| 256 | }, |
||
| 257 | self.flow_match.name: {'class': self.flow_match, 'commands': self.flow_match.known.keys(), 'sections': {},}, |
||
| 258 | self.flow_then.name: {'class': self.flow_then, 'commands': self.flow_then.known.keys(), 'sections': {},}, |
||
| 259 | self.flow_scope.name: {'class': self.flow_scope, 'commands': self.flow_scope.known.keys(), 'sections': {}}, |
||
| 260 | self.l2vpn.name: { |
||
| 261 | 'class': self.l2vpn, |
||
| 262 | 'commands': self.l2vpn.known.keys(), |
||
| 263 | 'sections': {'vpls': self.vpls.name,}, |
||
| 264 | }, |
||
| 265 | self.vpls.name: {'class': self.vpls, 'commands': self.l2vpn.known.keys(), 'sections': {},}, |
||
| 266 | self.operational.name: { |
||
| 267 | 'class': self.operational, |
||
| 268 | 'commands': self.operational.known.keys(), |
||
| 269 | 'sections': {}, |
||
| 270 | }, |
||
| 271 | } |
||
| 272 | |||
| 273 | self._neighbors = {} |
||
| 274 | self._previous_neighbors = {} |
||
| 275 | |||
| 516 |