class Token(object): """ Token type to enable encapsulation of other token related data. Can be used as a dictionary key as this is hashable """ def __init__(self, value, tokentype): self.value = value self.tokentype = tokentype self.tags = BlitzSet([]) self.rows = set([]) def __hash__(self): return hash(self.value) def __eq__(self, other): return other.value == self.value def __repr__(self): return self.value def add_tags(self, tags): self.tags.update(tags) def add_row(self, row): self.rows.add(row) def set_tokentype(self, tokentype): """ Allow the tokentype to be overriden should the type of the token be upgraded. This may happen when a token is found in a path of one file, then subsequently in the file in another. """ self.tokentype = tokentype def css_value(self): """ Replace spaces with underscore as space is obviously not a valid character for a CSS class """ return self.value.replace(' ', '_')
def __init__(self, value, tokentype): self.value = value self.tokentype = tokentype self.tags = BlitzSet([]) self.rows = set([])