File diff 4009c626d4cb → 3e21157f205b
import2ledger/hooks/ledger_entry.py
Show inline comments
...
 
@@ -54,7 +54,14 @@ class TokenTransformer:
 

	
 

	
 
class AmountTokenTransformer(TokenTransformer):
 
    SUPPORTED_NAMES = frozenset(['if', 'else'])
 
    SUPPORTED_NAMES = frozenset([
 
        'if',
 
        'else',
 
        'and',
 
        'or',
 
        'not',
 
        'in',
 
    ])
 
    SUPPORTED_OPS = frozenset([
 
        '(',
 
        ')',
...
 
@@ -110,8 +117,13 @@ class AmountTokenTransformer(TokenTransformer):
 
        else:
 
            raise ValueError("unsupported operator {!r}".format(tvalue))
 

	
 
    transform_STRING = TokenTransformer._noop_transformer
 

	
 

	
 
class AccountSplitter:
 
    EVAL_GLOBALS = {
 
        'Decimal': decimal.Decimal,
 
    }
 
    TARGET_LINE_LEN = 78
 
    # -4 because that's how many spaces prefix an account line.
 
    TARGET_ACCTLINE_LEN = TARGET_LINE_LEN - 4
...
 
@@ -166,13 +178,12 @@ class AccountSplitter:
 
            amounts[balance_index] = (account_name, start_amount + remainder)
 

	
 
    def _build_amounts(self, template_vars):
 
        amount_vars = {k: v for k, v in template_vars.items() if isinstance(v, decimal.Decimal)}
 
        amount_vars['Decimal'] = decimal.Decimal
 
        try:
 
            amounts = [
 
                (account, self._currency_decimal(eval(amount_expr, amount_vars),
 
                                                 template_vars['currency']))
 
                for account, amount_expr in self.splits
 
                (account,
 
                 self._currency_decimal(eval(amount_expr, self.EVAL_GLOBALS, template_vars),
 
                                        template_vars['currency']),
 
                ) for account, amount_expr in self.splits
 
            ]
 
        except (ArithmeticError, NameError, TypeError, ValueError) as error:
 
            raise errors.UserInputConfigurationError(