def processMaps(self): """loops through classes and ids to process to determine shorter names to use for them and creates a dictionary with these mappings Returns: void """ # reverse sort so we can figure out the biggest savings classes = self.class_counter.items() classes.sort(key = itemgetter(1), reverse=True) for class_name, savings in classes: small_class = "." + VarFactory.getNext("class") # adblock extensions may block class "ad" so we should never generate it # also if the generated class already exists as a class to be processed # we can't use it or bad things will happen while small_class == ".ad" or Util.keyInTupleList(small_class, classes): small_class = "." + VarFactory.getNext("class") self.class_map[class_name] = small_class ids = self.id_counter.items() ids.sort(key = itemgetter(1), reverse=True) for id, savings in ids: small_id = "#" + VarFactory.getNext("id") # same holds true for ids as classes while small_id == "#ad" or Util.keyInTupleList(small_id, ids): small_id = "#" + VarFactory.getNext("id") self.id_map[id] = small_id
def processMaps(self): """loops through classes and ids to process to determine shorter names to use for them and creates a dictionary with these mappings Returns: void """ # reverse sort so we can figure out the biggest savings classes = self.class_counter.items() classes.sort(key=itemgetter(1), reverse=True) for class_name, savings in classes: small_class = "." + VarFactory.getNext("class") # adblock extensions may block class "ad" so we should never generate it # also if the generated class already exists as a class to be processed # we can't use it or bad things will happen while small_class == ".ad" or Util.keyInTupleList( small_class, classes): small_class = "." + VarFactory.getNext("class") self.class_map[class_name] = small_class ids = self.id_counter.items() ids.sort(key=itemgetter(1), reverse=True) for id, savings in ids: small_id = "#" + VarFactory.getNext("id") # same holds true for ids as classes while small_id == "#ad" or Util.keyInTupleList(small_id, ids): small_id = "#" + VarFactory.getNext("id") self.id_map[id] = small_id
def getNext(type): """gets the next letter name based on counter name Arguments: type -- name of counter we want the next value for Returns: string """ i = VarFactory.getVersion(type) return VarFactory.getSmallName(i)