| Conditions | 1 |
| Total Lines | 237 |
| Code Lines | 177 |
| 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 |
||
| 115 | def __init__ (self, configurations, text=False): |
||
| 116 | _Configuration.__init__(self) |
||
| 117 | self.api_encoder = environment.settings().api.encoder |
||
| 118 | |||
| 119 | self._configurations = configurations |
||
| 120 | self._text = text |
||
| 121 | |||
| 122 | self.error = Error () |
||
| 123 | self.scope = Scope () |
||
| 124 | |||
| 125 | self.tokeniser = Tokeniser(self.scope,self.error,self.logger) |
||
| 126 | |||
| 127 | params = (self.tokeniser,self.scope,self.error,self.logger) |
||
| 128 | self.section = Section (*params) |
||
| 129 | self.process = ParseProcess (*params) |
||
| 130 | self.template = ParseTemplate (*params) |
||
| 131 | self.template_neighbor = ParseTemplateNeighbor (*params) |
||
| 132 | self.neighbor = ParseNeighbor (*params) |
||
| 133 | self.family = ParseFamily (*params) |
||
| 134 | self.addpath = ParseAddPath (*params) |
||
| 135 | self.nexthop = ParseNextHop (*params) |
||
| 136 | self.capability = ParseCapability (*params) |
||
| 137 | self.api = ParseAPI (*params) |
||
| 138 | self.api_send = ParseSend (*params) |
||
| 139 | self.api_receive = ParseReceive (*params) |
||
| 140 | self.static = ParseStatic (*params) |
||
| 141 | self.static_route = ParseStaticRoute (*params) |
||
| 142 | self.announce = SectionAnnounce (*params) |
||
| 143 | self.announce_ipv4 = AnnounceIPv4 (*params) |
||
| 144 | self.announce_ipv6 = AnnounceIPv6 (*params) |
||
| 145 | self.announce_l2vpn = AnnounceL2VPN (*params) |
||
| 146 | self.flow = ParseFlow (*params) |
||
| 147 | self.flow_route = ParseFlowRoute (*params) |
||
| 148 | self.flow_match = ParseFlowMatch (*params) |
||
| 149 | self.flow_then = ParseFlowThen (*params) |
||
| 150 | self.flow_scope = ParseFlowScope (*params) |
||
| 151 | self.l2vpn = ParseL2VPN (*params) |
||
| 152 | self.vpls = ParseVPLS (*params) |
||
| 153 | self.operational = ParseOperational (*params) |
||
| 154 | |||
| 155 | # We should check if name are unique when running Section.__init__ |
||
| 156 | |||
| 157 | self._structure = { |
||
| 158 | 'root': { |
||
| 159 | 'class': self.section, |
||
| 160 | 'commands': [], |
||
| 161 | 'sections': { |
||
| 162 | 'process': self.process.name, |
||
| 163 | 'neighbor': self.neighbor.name, |
||
| 164 | 'template': self.template.name, |
||
| 165 | }, |
||
| 166 | }, |
||
| 167 | self.process.name: { |
||
| 168 | 'class': self.process, |
||
| 169 | 'commands': self.process.known.keys(), |
||
| 170 | 'sections': {}, |
||
| 171 | }, |
||
| 172 | self.template.name: { |
||
| 173 | 'class': self.template, |
||
| 174 | 'commands': self.template.known.keys(), |
||
| 175 | 'sections': { |
||
| 176 | 'neighbor': self.template_neighbor.name, |
||
| 177 | }, |
||
| 178 | }, |
||
| 179 | self.template_neighbor.name: { |
||
| 180 | 'class': self.template_neighbor, |
||
| 181 | 'commands': self.template_neighbor.known.keys(), |
||
| 182 | 'sections': { |
||
| 183 | 'family': self.family.name, |
||
| 184 | 'capability': self.capability.name, |
||
| 185 | 'add-path': self.addpath.name, |
||
| 186 | 'nexthop': self.nexthop.name, |
||
| 187 | 'api': self.api.name, |
||
| 188 | 'static': self.static.name, |
||
| 189 | 'flow': self.flow.name, |
||
| 190 | 'l2vpn': self.l2vpn.name, |
||
| 191 | 'operational': self.operational.name, |
||
| 192 | 'announce': self.announce.name, |
||
| 193 | }, |
||
| 194 | }, |
||
| 195 | self.neighbor.name: { |
||
| 196 | 'class': self.neighbor, |
||
| 197 | 'commands': self.neighbor.known.keys(), |
||
| 198 | 'sections': { |
||
| 199 | 'family': self.family.name, |
||
| 200 | 'capability': self.capability.name, |
||
| 201 | 'add-path': self.addpath.name, |
||
| 202 | 'nexthop': self.nexthop.name, |
||
| 203 | 'api': self.api.name, |
||
| 204 | 'static': self.static.name, |
||
| 205 | 'flow': self.flow.name, |
||
| 206 | 'l2vpn': self.l2vpn.name, |
||
| 207 | 'operational': self.operational.name, |
||
| 208 | 'announce': self.announce.name, |
||
| 209 | }, |
||
| 210 | }, |
||
| 211 | self.family.name: { |
||
| 212 | 'class': self.family, |
||
| 213 | 'commands': self.family.known.keys(), |
||
| 214 | 'sections': { |
||
| 215 | }, |
||
| 216 | }, |
||
| 217 | self.capability.name: { |
||
| 218 | 'class': self.capability, |
||
| 219 | 'commands': self.capability.known.keys(), |
||
| 220 | 'sections': { |
||
| 221 | }, |
||
| 222 | }, |
||
| 223 | self.nexthop.name: { |
||
| 224 | 'class': self.nexthop, |
||
| 225 | 'commands': self.nexthop.known.keys(), |
||
| 226 | 'sections': { |
||
| 227 | }, |
||
| 228 | }, |
||
| 229 | self.addpath.name: { |
||
| 230 | 'class': self.addpath, |
||
| 231 | 'commands': self.addpath.known.keys(), |
||
| 232 | 'sections': { |
||
| 233 | }, |
||
| 234 | }, |
||
| 235 | self.api.name: { |
||
| 236 | 'class': self.api, |
||
| 237 | 'commands': self.api.known.keys(), |
||
| 238 | 'sections': { |
||
| 239 | 'send': self.api_send.name, |
||
| 240 | 'receive': self.api_receive.name, |
||
| 241 | }, |
||
| 242 | }, |
||
| 243 | self.api_send.name: { |
||
| 244 | 'class': self.api_send, |
||
| 245 | 'commands': self.api_send.known.keys(), |
||
| 246 | 'sections': { |
||
| 247 | }, |
||
| 248 | }, |
||
| 249 | self.api_receive.name: { |
||
| 250 | 'class': self.api_receive, |
||
| 251 | 'commands': self.api_receive.known.keys(), |
||
| 252 | 'sections': { |
||
| 253 | }, |
||
| 254 | }, |
||
| 255 | self.announce.name: { |
||
| 256 | 'class': self.announce, |
||
| 257 | 'commands': self.announce.known.keys(), |
||
| 258 | 'sections': { |
||
| 259 | 'ipv4': self.announce_ipv4.name, |
||
| 260 | 'ipv6': self.announce_ipv6.name, |
||
| 261 | 'l2vpn': self.announce_l2vpn.name, |
||
| 262 | }, |
||
| 263 | }, |
||
| 264 | self.announce_ipv4.name: { |
||
| 265 | 'class': self.announce_ipv4, |
||
| 266 | 'commands': ['unicast', 'multicast', 'nlri-mpls', 'mpls-vpn', 'flow', 'flow-vpn'], |
||
| 267 | 'sections': { |
||
| 268 | }, |
||
| 269 | }, |
||
| 270 | self.announce_ipv6.name: { |
||
| 271 | 'class': self.announce_ipv6, |
||
| 272 | 'commands': ['unicast', 'multicast', 'nlri-mpls', 'mpls-vpn', 'flow', 'flow-vpn'], |
||
| 273 | 'sections': { |
||
| 274 | }, |
||
| 275 | }, |
||
| 276 | self.announce_l2vpn.name: { |
||
| 277 | 'class': self.announce_l2vpn, |
||
| 278 | 'commands': ['vpls',], |
||
| 279 | 'sections': { |
||
| 280 | }, |
||
| 281 | }, |
||
| 282 | self.static.name: { |
||
| 283 | 'class': self.static, |
||
| 284 | 'commands': ['route','attributes'], |
||
| 285 | 'sections': { |
||
| 286 | 'route': self.static_route.name, |
||
| 287 | }, |
||
| 288 | }, |
||
| 289 | self.static_route.name: { |
||
| 290 | 'class': self.static_route, |
||
| 291 | 'commands': self.static_route.known.keys(), |
||
| 292 | 'sections': { |
||
| 293 | }, |
||
| 294 | }, |
||
| 295 | self.flow.name: { |
||
| 296 | 'class': self.flow, |
||
| 297 | 'commands': self.flow.known.keys(), |
||
| 298 | 'sections': { |
||
| 299 | 'route': self.flow_route.name, |
||
| 300 | }, |
||
| 301 | }, |
||
| 302 | self.flow_route.name: { |
||
| 303 | 'class': self.flow_route, |
||
| 304 | 'commands': self.flow_route.known.keys(), |
||
| 305 | 'sections': { |
||
| 306 | 'match': self.flow_match.name, |
||
| 307 | 'then': self.flow_then.name, |
||
| 308 | 'scope': self.flow_scope.name, |
||
| 309 | }, |
||
| 310 | }, |
||
| 311 | self.flow_match.name: { |
||
| 312 | 'class': self.flow_match, |
||
| 313 | 'commands': self.flow_match.known.keys(), |
||
| 314 | 'sections': { |
||
| 315 | }, |
||
| 316 | }, |
||
| 317 | self.flow_then.name: { |
||
| 318 | 'class': self.flow_then, |
||
| 319 | 'commands': self.flow_then.known.keys(), |
||
| 320 | 'sections': { |
||
| 321 | }, |
||
| 322 | }, |
||
| 323 | self.flow_scope.name: { |
||
| 324 | 'class': self.flow_scope, |
||
| 325 | 'commands': self.flow_scope.known.keys(), |
||
| 326 | 'sections': { |
||
| 327 | } |
||
| 328 | }, |
||
| 329 | self.l2vpn.name: { |
||
| 330 | 'class': self.l2vpn, |
||
| 331 | 'commands': self.l2vpn.known.keys(), |
||
| 332 | 'sections': { |
||
| 333 | 'vpls': self.vpls.name, |
||
| 334 | }, |
||
| 335 | }, |
||
| 336 | self.vpls.name: { |
||
| 337 | 'class': self.vpls, |
||
| 338 | 'commands': self.l2vpn.known.keys(), |
||
| 339 | 'sections': { |
||
| 340 | }, |
||
| 341 | }, |
||
| 342 | self.operational.name: { |
||
| 343 | 'class': self.operational, |
||
| 344 | 'commands': self.operational.known.keys(), |
||
| 345 | 'sections': { |
||
| 346 | } |
||
| 347 | }, |
||
| 348 | } |
||
| 349 | |||
| 350 | self._neighbors = {} |
||
| 351 | self._previous_neighbors = {} |
||
| 352 | |||
| 622 |