You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
flowy/splitter_validator.py

26 lines
1.1 KiB
Python

from copy import copy, deepcopy
from splitter import Branch as BranchImpl
from splitter import Splitter as SplitterImpl
class SplitterValidator(object):
def __init__(self, parser, filter_validator):
self.splitter = copy(parser.splitter)
self.branches = deepcopy(parser.branches)
self.branch_ids = filter_validator.branches_ids
self.filter_impl = filter_validator.impl
self.br_name_to_br = {}
self.impl = self.create_impl()
def sort_branches(self):
id_to_branch = dict(zip(self.branch_ids.values(),
self.branch_ids.keys()))
sorted_br = [id_to_branch[k] for k in sorted(id_to_branch.keys())]
return sorted_br
def create_impl(self):
br_names = self.sort_branches()
branches = [BranchImpl(name) for name in br_names]# Actual branch instances are being initiated
name_to_br = dict(zip(br_names, branches))# These instances are being mapped to the corresponding names, i.e. A, B
self.br_name_to_br = name_to_br
return SplitterImpl(name_to_br, self.filter_impl)