Ticket #2537: 0001-converting-from-locale-fraction_sep-before-parsing.patch

File 0001-converting-from-locale-fraction_sep-before-parsing.patch, 1.6 KB (added by walter, 10 years ago)

removed unnecessary import locale

  • calculate.py

    From a05053c9ac79d0a469329f4197073b890d4d9ae4 Mon Sep 17 00:00:00 2001
    From: Walter Bender <walter@sugarlabs.org>
    Date: Wed, 22 Dec 2010 21:23:59 -0500
    Subject: [PATCH] converting-from-locale-fraction_sep-before-parsing
    
    ---
     calculate.py |   23 +++++++++++++++++++++++
     1 files changed, 23 insertions(+), 0 deletions(-)
    
    diff --git a/calculate.py b/calculate.py
    index bda756c..1e4e529 100644
    a b from svgimage import SVGImage 
    4848from decimal import Decimal
    4949from rational import Rational
    5050
     51def replace_fraction_seperator(text, fraction_sep):
     52    '''
     53    Replace the fraction separator with '.'
     54    A simple replace won't work, e.g. plot(x*x,x=-1,0..1,0)
     55    '''
     56
     57    if fraction_sep == '.':
     58        return text
     59
     60    new_text = ''
     61    parts = text.split(fraction_sep)
     62
     63    for i in range(len(parts) - 1):
     64        new_text += parts[i]
     65        if new_text[-1] in string.digits and parts[i + 1][0] in string.digits:
     66            new_text += '.'
     67        else:
     68            new_text += fraction_sep
     69
     70    return new_text + parts[-1]
     71
     72
    5173def findchar(text, chars, ofs=0):
    5274    '''
    5375    Find a character in set <chars> starting from offset ofs.
    class Calculate(ShareableActivity): 
    454476        s = unicode(self.text_entry.get_text())
    455477        label = unicode(self.label_entry.get_text())
    456478        _logger.debug('process(): parsing %r, label: %r', s, label)
     479        s = replace_fraction_seperator(s, self.ml.fraction_sep)
    457480        try:
    458481            tree = self.parser.parse(s)
    459482            res = self.parser.evaluate(tree)