# Path: sfc_models/utils.py
# class LogicError(ValueError):
#     """
#     Throw this when code logic is broken.
#     """
#     pass
# 
# def replace_token_from_lookup(s, lookup):
#     """
#     Replace tokens using a lookup dictionary.
# 
#     >>> replace_token_from_lookup('y = x', {'y': 'H_y', 'x': 'H_x'})
#     'H_y =H_x '
# 
#     :param s: str
#     :param lookup: dict
#     :return: str
#     """
#     result = []
#     if is_python_3:
#         g = tokenize.tokenize(BytesIO(s.encode('utf-8')).readline)  # tokenize the string
#         for toknum, tokval, _, _, _ in g:
#             if toknum == NAME and tokval in lookup:  # replace NAME tokens
#                 result.append((NAME, lookup[tokval]))
#             else:
#                 result.append((toknum, tokval))
#         return untokenize(result).decode('utf-8')
#     else:  # pragma: no cover   [Do my coverage on Python 3]
#         g = tokenize.generate_tokens(BytesIO(s.encode('utf-8')).readline)  # tokenize the string
#         for toknum, tokval, _, _, _ in g:
#             if toknum == NAME and tokval in lookup:  # replace NAME tokens
#                 result.append((NAME, lookup[tokval]))
#             else:
#                 result.append((toknum, tokval))
#         return str(untokenize(result).decode('utf-8'))


import sys
import tokenize
import copy
from io import BytesIO
    from tokenize import untokenize, NAME, ENDMARKER, ENCODING, OP, NEWLINE, NUMBER
    from tokenize import untokenize, NAME, ENDMARKER, OP
from sfc_models.utils import LogicError, replace_token_from_lookup
                if not g[0][0] == NAME:
                    raise NotImplementedError('Non-simple parsing not done')
                    # self.IsSimple = False
            self.Term = term_s


    def __str__(self):
        """
        Convert the Term to a string
        :return: str
        """
        if self.IsBlob:
            return self.Term
        if not self.IsSimple: # pragma: no cover
            raise NotImplementedError('Not dealing with non-simple terms...')
        if self.Constant == 0.0:
            return ''
        if self.Constant == 1.0:
            lead = '+'
        elif self.Constant == -1:
            lead = '-'
        elif self.Constant > 0:
            lead = '+' + str(self.Constant) + '*'
        else:
            lead = str(self.Constant) + '*'
        return lead + self.Term

    def ReplaceTokensFromLookup(self, lookup):
        try:
            if self.IsBlob:

# Path: sfc_models/utils.py
# class LogicError(ValueError):
#     """
#     Throw this when code logic is broken.
#     """
#     pass
# 
# def replace_token_from_lookup(s, lookup):
#     """
#     Replace tokens using a lookup dictionary.
# 
#     >>> replace_token_from_lookup('y = x', {'y': 'H_y', 'x': 'H_x'})
#     'H_y =H_x '
# 
#     :param s: str
#     :param lookup: dict
#     :return: str
#     """
#     result = []
#     if is_python_3:
#         g = tokenize.tokenize(BytesIO(s.encode('utf-8')).readline)  # tokenize the string
#         for toknum, tokval, _, _, _ in g:
#             if toknum == NAME and tokval in lookup:  # replace NAME tokens
#                 result.append((NAME, lookup[tokval]))
#             else:
#                 result.append((toknum, tokval))
#         return untokenize(result).decode('utf-8')
#     else:  # pragma: no cover   [Do my coverage on Python 3]
#         g = tokenize.generate_tokens(BytesIO(s.encode('utf-8')).readline)  # tokenize the string
#         for toknum, tokval, _, _, _ in g:
#             if toknum == NAME and tokval in lookup:  # replace NAME tokens
#                 result.append((NAME, lookup[tokval]))
#             else:
#                 result.append((toknum, tokval))
#         return str(untokenize(result).decode('utf-8'))


# Path: sfc_models/equation.py
import sys
import tokenize
import copy
from io import BytesIO
    from tokenize import untokenize, NAME, ENDMARKER, ENCODING, OP, NEWLINE, NUMBER
    from tokenize import untokenize, NAME, ENDMARKER, OP
from sfc_models.utils import LogicError, replace_token_from_lookup

                if not g[0][0] == NAME:
                    raise NotImplementedError('Non-simple parsing not done')
                    # self.IsSimple = False
            self.Term = term_s


    def __str__(self):
        """
        Convert the Term to a string
        :return: str
        """
        if self.IsBlob:
            return self.Term
        if not self.IsSimple: # pragma: no cover
            raise NotImplementedError('Not dealing with non-simple terms...')
        if self.Constant == 0.0:
            return ''
        if self.Constant == 1.0:
            lead = '+'
        elif self.Constant == -1:
            lead = '-'
        elif self.Constant > 0:
            lead = '+' + str(self.Constant) + '*'
        else:
            lead = str(self.Constant) + '*'
        return lead + self.Term

    def ReplaceTokensFromLookup(self, lookup):
        try:
            if self.IsBlob:

                self.Term = replace_token_from_lookup(self.Term, lookup)