(self, fors)
Get consecutive number-related formatting tokens.
Get consecutive number-related formatting tokens.
Get consecutive number - related formatting tokens .
def __init__(self, fors):
        """Get consecutive number-related formatting tokens."""
        word, digits_before, decimals = b'', 0, 0
        # + comes first
        leading_plus = (fors.peek() == b'+')
        if leading_plus:
            word += fors.read(1)
        # $ and * combinations
        c = fors.peek()
        if c in (b'$', b'*'):
            word += fors.read(2)
            if word[-1:] != c:
                fors.seek(-len(word), 1)
                raise ValueError()
            if c == b'*':
                digits_before += 2
                if fors.peek() == b'$':
                    word += fors.read(1)
            else:
                digits_before += 1
        # number field
        c = fors.peek()
        dot = (c == b'.')
        comma = False
        if dot:
            word += fors.read(1)
        if c in (b'.', b'#'):
            while True:
                c = fors.peek()
                if not dot and c == b'.':
                    word += fors.read(1)
                    dot = True
                elif c == b'#' or (not dot and c == b','):
                    word += fors.read(1)
                    if dot:
                        decimals += 1
                    else:
                        digits_before += 1
                        if c == b',':
                            comma = True
                else:
                    break
        if digits_before + decimals == 0:
            fors.seek(-len(word), 1)
            raise ValueError()
        # post characters
        if fors.peek(4) == b'^^^^':
            word += fors.read(4)
        if not leading_plus and fors.peek() in (b'-', b'+'):
            word += fors.read(1)
        self._tokens, self._digits_before = word, digits_before
        self._decimals, self._comma = decimals, comma
def __init__ ( self , fors ) : word , digits_before , decimals = b'' , 0 , 0 # + comes first leading_plus = ( fors . peek ( ) == b'+' ) if leading_plus : word += fors . read ( 1 ) # $ and * combinations c = fors . peek ( ) if c in ( b'$' , b'*' ) : word += fors . read ( 2 ) if word [ - 1 : ] != c : fors . seek ( - len ( word ) , 1 ) raise ValueError ( ) if c == b'*' : digits_before += 2 if fors . peek ( ) == b'$' : word += fors . read ( 1 ) else : digits_before += 1 # number field c = fors . peek ( ) dot = ( c == b'.' ) comma = False if dot : word += fors . read ( 1 ) if c in ( b'.' , b'#' ) : while True : c = fors . peek ( ) if not dot and c == b'.' : word += fors . read ( 1 ) dot = True elif c == b'#' or ( not dot and c == b',' ) : word += fors . read ( 1 ) if dot : decimals += 1 else : digits_before += 1 if c == b',' : comma = True else : break if digits_before + decimals == 0 : fors . seek ( - len ( word ) , 1 ) raise ValueError ( ) # post characters if fors . peek ( 4 ) == b'^^^^' : word += fors . read ( 4 ) if not leading_plus and fors . peek ( ) in ( b'-' , b'+' ) : word += fors . read ( 1 ) self . _tokens , self . _digits_before = word , digits_before self . _decimals , self . _comma = decimals , comma