Project

General

Profile

« Previous | Next » 

Revision 7655

Moved parse_range() from xml_func.py to units.py

View differences:

lib/units.py
7 7
import strings
8 8
import util
9 9

  
10
def parse_range(str_, range_sep='-'):
11
    default = (str_, None)
12
    start, sep, end = str_.partition(range_sep)
13
    if sep == '': return default # not a range
14
    if start == '' and range_sep == '-': return default # negative number
15
    return tuple(d.strip() for d in (start, end))
16

  
10 17
class MissingUnitsException(Exception):
11 18
    def __init__(self, quantity):
12 19
        Exception.__init__(self, 'Quantity has no units: '
lib/xml_func.py
318 318
    return units.quantity2str(quantity)
319 319
funcs['_units'] = _units
320 320

  
321
def parse_range(str_, range_sep='-'):
322
    default = (str_, None)
323
    start, sep, end = str_.partition(range_sep)
324
    if sep == '': return default # not a range
325
    if start == '' and range_sep == '-': return default # negative number
326
    return tuple(d.strip() for d in (start, end))
327

  
328 321
def _rangeStart(items, node):
329 322
    items = dict(conv_items(strings.ustr, items))
330 323
    try: value = items['value']
331 324
    except KeyError: return None # input is empty
332
    return parse_range(value)[0]
325
    return units.parse_range(value)[0]
333 326
funcs['_rangeStart'] = _rangeStart
334 327

  
335 328
def _rangeEnd(items, node):
336 329
    items = dict(conv_items(strings.ustr, items))
337 330
    try: value = items['value']
338 331
    except KeyError: return None # input is empty
339
    return parse_range(value)[1]
332
    return units.parse_range(value)[1]
340 333
funcs['_rangeEnd'] = _rangeEnd
341 334

  
342 335
def _range(items, node):

Also available in: Unified diff