def list_slice(list, start=0, to=None): start = util.numify(start) if start < 0: start = len(list) + start if to is None or to < 0: return list[start:] else: to = util.numify(to) return list[start:to + 1]
def list_defined(list, index=None): if index is None: return 1 else: try: return int(list[util.numify(index)] is not None) except IndexError: return 0
def sqrt(self, x): root = math.sqrt(numify(x)) trunc = long(root) # Try to return an integer, if possible: if root == trunc: return trunc else: return root
def truncate_filter_factory(context, length=32, char="..."): length = numify(length) char = str(char) def truncate_filter(text=""): text = str(text) if len(text) <= length: return text else: return text[:length - len(char)] + char return truncate_filter
def list_splice(seq, start=0, length=None, *replace): start = util.numify(start) if start < 0: start = len(seq) + start if length is not None: stop = start + length else: stop = len(seq) if len(replace) == 1 and util.is_seq(replace[0]): replace = replace[0] s = slice(start, stop) removed = seq[s] seq[s] = replace return removed
def srand(self, x): return Random.seed(numify(x))
def asin(self, x): return math.asin(numify(x))
def grad2rad(self, x): return math.radians(numify(x) * 0.9)
def list_item(list, item=0): try: return list[util.numify(item)] except IndexError: return None
def coth(self, x): return 1.0 / math.tanh(numify(x))
def rad2deg(self, x): return math.degrees(numify(x))
def acos(self, x): return math.acos(numify(x))
def cosh(self, x): return math.cosh(numify(x))
def cot(self, x): return 1.0 / math.tan(numify(x))
def sec(self, x): return 1.0 / math.cos(numify(x))
def csc(self, x): return 1.0 / math.sin(numify(x))
def truly_random(self, x): if TrulyRandomFunction is None: raise Error("No truly_random dispatch function has been defined") return TrulyRandomFunction(numify(x))
def atan(self, x): return math.atan(numify(x))
def acot(self, x): return math.pi / 2.0 - math.atan(numify(x))
def asec(self, x): return math.acos(1.0 / numify(x))
def csch(self, x): return 1.0 / math.sinh(numify(x))
def acsch(self, x): x = numify(x) if x < 0: return math.log((1.0 - math.sqrt(1.0 + x * x)) / x) else: return math.log((1.0 + math.sqrt(1.0 + x * x)) / x)
def sinh(self, x): return math.sinh(numify(x))
def deg2rad(self, x): return math.radians(numify(x))
def log(self, x): return math.log(numify(x))
def tanh(self, x): return math.tanh(numify(x))
def hex(self, x): return int(str(numify(x)), 16)
def sech(self, x): return 1.0 / math.cosh(numify(x))
def asinh(self, x): x = numify(x) return math.log(x + math.sqrt(x * x + 1))
def acoth(self, x): x = numify(x) return math.log((1.0 + x) / (1.0 - x)) / 2.0
def rad2grad(self, x): return math.degrees(numify(x)) * 10.0 / 9.0
def deg2grad(self, x): return numify(x) * 10.0 / 9.0
def grad2deg(self, x): return numify(x) * 0.9
def exp(self, x): return math.exp(numify(x))
def repeat_filter(text=""): return str(text) * numify(count)
def int(self, x): return int(numify(x))
def atan2(self, x, y): return math.atan2(numify(x), numify(y))
def rand(self, x): return Random.uniform(0, numify(x))