Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
code = self.key
if self.label != None:
code += "='%s'" % self.label
if self.all:
code = "(%s ALL='%s')" % (code, self.all)
if self.child:
code += " * %s" % str(self.child)
return code
def _gather(self, collected):
collected['classes'].add(self.key)
if (self.child):
self.child._gather(collected)
class Var(TabulationItem):
def __str__(self):
code = self.key
if self.label != None:
code += "='%s'" % self.label
if self.child:
code += " * %s" % str(self.child)
return code
def __mul__(self, other):
if isinstance(other, Class):
raise SyntaxError('A Class variable cannot be a descendent of a Var')
return super().__mul__(other)
def _gather(self, collected):
collected['vars'].add(self.key)
if (self.child):
return other.add(self, True)
def __mul__(self, other):
if self.child:
self.child = self.child.__mul__(other)
else:
# always clone for composition purposes
return self.with_(child=other)
return self
# override for entities needing to add top-level entries
def _gather(self, collected):
pass
class Class(TabulationItem):
def __init__(self, key, **kwargs):
super().__init__(key, **kwargs)
self.all = kwargs.get('all', None)
self._kwargs += ['all']
def __str__(self):
code = self.key
if self.label != None:
code += "='%s'" % self.label
if self.all:
code = "(%s ALL='%s')" % (code, self.all)
if self.child:
code += " * %s" % str(self.child)
return code
def _gather(self, collected):
if self.child:
code += " * %s" % str(self.child)
return code
def __mul__(self, other):
if isinstance(other, Class):
raise SyntaxError('A Class variable cannot be a descendent of a Var')
return super().__mul__(other)
def _gather(self, collected):
collected['vars'].add(self.key)
if (self.child):
self.child._gather(collected)
class Statistic(TabulationItem):
def __init__(self, key, **kwargs):
super().__init__(key, **kwargs)
self.format = kwargs.get('format', None)
self._kwargs += ['format']
def __str__(self):
code = self.key
if self.label != None:
code += "='%s'" % self.label
if self.format:
code += "*f=%s" % self.format
return code
def __mul__(self, other):
raise SyntaxError("Statistics cannot have further descendents")
def __or__(self, other):
if isinstance(other, TabulationItem):
return Grouping([self, other])
if type(other) == Grouping:
return other.add(self, True)