From 6a6352805e76839ee25c66552916acc9f87bbbea Mon Sep 17 00:00:00 2001 From: NaN?tic Date: Fri, 15 May 2015 10:42:04 +0200 Subject: [PATCH] Backed out changeset 9bd59fccddea --- issue9801002_40001.diff | 85 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 issue9801002_40001.diff diff --git a/issue9801002_40001.diff b/issue9801002_40001.diff new file mode 100644 index 0000000..ba10825 --- /dev/null +++ b/issue9801002_40001.diff @@ -0,0 +1,85 @@ +Index: trytond/trytond/tests/test_tools.py +=================================================================== + +--- a/trytond/trytond/tests/test_tools.py ++++ b/trytond/tests/test_tools.py +@@ -3,12 +3,13 @@ + #this repository contains the full copyright notices and license terms. + + import unittest ++import doctest + import datetime + import sql + import sql.operators + + from trytond.tools import reduce_ids, safe_eval, datetime_strftime, \ +- reduce_domain ++ reduce_domain, decimal_ + + + class ToolsTestCase(unittest.TestCase): +@@ -117,4 +118,5 @@ + suite = unittest.TestSuite() + for testcase in (ToolsTestCase,): + suite.addTests(func(testcase)) ++ suite.addTest(doctest.DocTestSuite(decimal_)) + return suite + +Index: trytond/trytond/tools/__init__.py +=================================================================== + +--- a/trytond/trytond/tools/__init__.py ++++ b/trytond/trytond/tools/__init__.py +@@ -2,6 +2,7 @@ + #this repository contains the full copyright notices and license terms. + from .misc import * + from .datetime_strftime import * ++from .decimal_ import * + + + class ClassProperty(property): + +Index: trytond/trytond/tools/decimal_.py +=================================================================== +new file mode 100644 + +--- /dev/null ++++ b/trytond/trytond/tools/decimal_.py +@@ -0,0 +1,36 @@ ++# This file is part of Tryton. The COPYRIGHT file at the top level of ++# this repository contains the full copyright notices and license terms. ++import tokenize ++from io import StringIO ++ ++# code snippet taken from http://docs.python.org/library/tokenize.html ++ ++ ++def decistmt(s): ++ """Substitute Decimals for floats in a string of statements. ++ ++ >>> from decimal import Decimal ++ >>> s = 'print +21.3e-5*-.1234/81.7' ++ >>> decistmt(s) ++ u"print +Decimal (u'21.3e-5')*-Decimal (u'.1234')/Decimal (u'81.7')" ++ ++ >>> exec(s) ++ -3.21716034272e-07 ++ >>> exec(decistmt(s)) ++ -3.217160342717258261933904529E-7 ++ """ ++ result = [] ++ # tokenize the string ++ g = tokenize.generate_tokens(StringIO(s.decode('utf-8')).readline) ++ for toknum, tokval, _, _, _ in g: ++ # replace NUMBER tokens ++ if toknum == tokenize.NUMBER and '.' in tokval: ++ result.extend([ ++ (tokenize.NAME, 'Decimal'), ++ (tokenize.OP, '('), ++ (tokenize.STRING, repr(tokval)), ++ (tokenize.OP, ')') ++ ]) ++ else: ++ result.append((toknum, tokval)) ++ return tokenize.untokenize(result) +