[Mpuls-commits] r947 - wasko/branches/2.0/waskaweb/model
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Wed Jan 27 14:36:43 CET 2010
Author: torsten
Date: 2010-01-27 14:36:40 +0100 (Wed, 27 Jan 2010)
New Revision: 947
Removed:
wasko/branches/2.0/waskaweb/model/expr.py
Log:
Deleted. Not used anywhere
Deleted: wasko/branches/2.0/waskaweb/model/expr.py
===================================================================
--- wasko/branches/2.0/waskaweb/model/expr.py 2010-01-27 12:13:09 UTC (rev 946)
+++ wasko/branches/2.0/waskaweb/model/expr.py 2010-01-27 13:36:40 UTC (rev 947)
@@ -1,301 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: latin1 -*-
-#
-# Copyright 2007, 2008 Intevation GmbH, Germany, <info at intevation.de>
-#
-# This file is part of mpuls WASKA (CoMPUter-based case fiLeS -
-# Web-Anwendungs-Server fuer Kompetenzagenturen).
-#
-# mpuls WASKA is free software: you can redistribute it and/or modify it under
-# the terms of the GNU Affero General Public License as published by the
-# Free Software Foundation, either version 3 of the License, or (at your
-# option) any later version.
-#
-# mpuls WASKA is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
-# License for more details.
-#
-# You should have received a copy of the GNU Affero General Public
-# License along with mpuls WASKA. If not, see <http://www.gnu.org/licenses/>.
-#
-# mpuls WASKA has been developed on behalf of the
-# Projekttraeger im Deutschen Zentrum fuer Luft- und Raumfahrt e.V. (PT-DLR)
-# within the programme Kompetenzagenturen (Durchfuehrungsphase) funded by
-# the Bundesministerium fuer Familie, Senioren, Frauen und Jugend and
-# European Social Fund resources.
-#
-# Authors:
-# Sascha L. Teichmann <teichmann at intevation.de>
-#
-
-import sys
-import re
-import codecs
-
-from datetime import date
-
-FLT_RE = re.compile(r'^([-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?)$')
-INT_RE = re.compile(r'^([-+]?[0-9]+)$')
-VAR_RE = re.compile(r'^\$(\w+)$')
-
-from shlex import split as lexsplit
-
-class Expr:
-
- class EvalContext:
-
- def __init__(self, vars):
- self.vars = vars
- self.stack = []
-
- def evaluate(self, prog):
- for op in prog:
- op(self)
- if len(self.stack) > 0:
- return self.stack.pop()
- return None
-
- def _ADD(self):
- stack = self.stack
- stack.append(stack.pop() + stack.pop())
-
- def _MUL(self):
- stack = self.stack
- stack.append(stack.pop() * stack.pop())
-
- def _ISSET(self):
- stack = self.stack
- stack.append(stack.pop() is not None)
-
- def _MINUS(self):
- stack = self.stack
- b = stack.pop()
- stack.append(stack.pop() - b)
-
- def _DIV(self):
- stack = self.stack
- b = stack.pop()
- stack.append(stack.pop() / b)
-
- def _MOD(self):
- stack = self.stack
- b = stack.pop()
- stack.append(stack.pop() % b)
-
- def _POW(self):
- stack = self.stack
- b = stack.pop()
- stack.append(stack.pop() ** b)
-
- def _INT(self):
- stack = self.stack
- stack.append(int(stack.pop()))
-
- def _FLT(self):
- stack = self.stack
- stack.append(float(stack.pop()))
-
- def _STR(self):
- stack = self.stack
- stack.append(str(stack.pop()))
-
- def _LEN(self):
- stack = self.stack
- stack.append(len(stack.pop()))
-
- def _EQ(self):
- stack = self.stack
- stack.append(stack.pop() == stack.pop())
-
- def _NE(self):
- stack = self.stack
- stack.append(stack.pop() != stack.pop())
-
- def _GT(self):
- stack = self.stack
- b = stack.pop()
- stack.append(stack.pop() > b)
-
- def _LT(self):
- stack = self.stack
- b = stack.pop()
- stack.append(stack.pop() < b)
-
- def _GE(self):
- stack = self.stack
- b = stack.pop()
- stack.append(stack.pop() >= b)
-
- def _LE(self):
- stack = self.stack
- b = stack.pop()
- stack.append(stack.pop() <= b)
-
- def _AND(self):
- stack = self.stack
- b = stack.pop()
- stack.append(stack.pop() and b)
-
- def _OR(self):
- stack = self.stack
- b = stack.pop()
- stack.append(stack.pop() or b)
-
- def _NOT(self):
- stack = self.stack
- stack.append(not stack.pop())
-
- def _DATE(self):
- stack = self.stack
- year = stack.pop()
- month = stack.pop()
- day = stack.pop()
- stack.append(date(year, month, day))
-
- def _TODAY(self):
- self.stack.append(date.today())
-
- def _TYPE(self):
- stack = self.stack
- stack.append(type(stack.pop()))
-
-# def _ASSIGN(self):
-# stack = self.stack
-# var = str(stack.pop())
-# value = stack.pop()
-# self.vars[var] = value
-
- def _MIN(self):
- stack = self.stack
- stack.append(min(stack.pop(), stack.pop()))
-
- def _MAX(self):
- stack = self.stack
- stack.append(max(stack.pop(), stack.pop()))
-
- def _ABS(self):
- stack = self.stack
- stack.append(abs(stack.pop()))
-
-
- def _QUESTION(self):
- stack = self.stack
- q = stack.pop()
- b = stack.pop()
- a = stack.pop()
- if q:
- stack.append(a)
- else:
- stack.append(b)
-
- def _DUP(self):
- stack = self.stack
- stack.append(self.stack[-1])
-
- def _OUT(self):
- stack = self.stack
- print str(stack.pop())
-
- _OPS = {
- '.': _OUT,
- '+': _ADD,
- '-': _MINUS,
- '*': _MUL,
- '/': _DIV,
- '%': _MOD,
- '**': _POW,
- 'int': _INT,
- 'str': _STR,
- 'len': _LEN,
- 'min': _MIN,
- 'max': _MAX,
- 'abs': _ABS,
- 'float': _FLT,
- '==': _EQ,
- '!=': _NE,
- '>': _GT,
- '<': _LT,
- '>=': _GE,
- '<=': _LE,
- 'not': _NOT,
- 'isset': _ISSET,
- 'or': _OR,
- 'and': _AND,
- 'type': _TYPE,
- 'DUP': _DUP,
- 'date': _DATE,
- 'today': _TODAY,
- #'=': _ASSIGN,
- '?': _QUESTION,
- }
-
- def __init__(self, expr):
- self.expr = expr
- self.prog = None
- self.depends = None
-
- def clone(self):
- return Expr(self.expr)
-
- def getDependencies(self):
- if self.depends is None:
- self.compile()
- return self.depends
-
- def compile(self):
- prog = []
- depends = set()
-
- def _store(x):
- return lambda ec: ec.stack.append(x)
-
- def _storeVar(x):
- return lambda ec: ec.stack.append(ec.vars[x])
-
- prog_append = prog.append
- ops = Expr.EvalContext._OPS
-
- # XXX: shlex does not support unicode -> ascii
- encoder = codecs.getencoder("ascii")
- for token in lexsplit(encoder(self.expr)[0]):
- token = unicode(token)
- m = VAR_RE.match(token)
- if m:
- var = m.group(1)
- depends.add(var)
- prog_append(_storeVar(var))
- continue
- m = INT_RE.match(token)
- if m:
- prog_append(_store(int(m.group(1))))
- continue
- m = FLT_RE.match(token)
- if m:
- prog_append(_store(float(m.group(1))))
- continue
- try:
- prog_append(ops[token])
- except KeyError:
- prog_append(_store(token))
-
- self.prog = prog
- self.depends = depends
-
- def evaluate(self, vars=None):
- if self.prog is None:
- self.compile()
- result = Expr.EvalContext(vars).evaluate(self.prog)
- return result
-
-#def main():
-# for arg in sys.argv[1:]:
-# expr = Expr(arg)
-# vars = { 'a': 3 }
-# result = expr.evaluate(vars)
-# print str(result)
-#
-#if __name__ == "__main__":
-# main()
-
-# vim:set ts=4 sw=4 si et sta sts=4:
More information about the Mpuls-commits
mailing list