# Path: beancount_import/journal_editor.py
# META_IGNORE = get_meta_ignore()
# 
# Path: beancount_import/sorted_list.py
# class SortedList(Generic[K, V]):
#     def __init__(self, items: Iterable[Tuple[K, V]]) -> None:
#         entries = sorted(items, key=lambda x: x[0])
#         self.keys = [x[0] for x in entries]
#         self.values = [x[1] for x in entries]
# 
#     def __repr__(self) -> str:
#         return repr(list(zip(self.keys, self.values)))
# 
#     def find(self, lower_bound: K, upper_bound: K) -> Iterable[V]:
#         keys = self.keys
#         begin_pos = bisect.bisect_left(keys, lower_bound)
#         end_pos = bisect.bisect_right(keys, upper_bound)
#         if begin_pos == end_pos:
#             return ()
#         return itertools.islice(self.values, begin_pos, end_pos)
# 
# Path: beancount_import/posting_date.py
# def get_posting_date(entry, posting):
#     """Returns the date associated with a posting."""
#     return ((posting.meta and (posting.meta.get(POSTING_DATE_KEY) or
#                                posting.meta.get(POSTING_TRANSACTION_DATE_KEY))) or entry.date)
# 
# POSTING_DATE_KEY = 'date'
# 
# POSTING_TRANSACTION_DATE_KEY = 'transaction_date'


import datetime
import collections
import itertools
import beancount.parser.printer
from typing import Sequence, Tuple, List, NamedTuple, Dict, Callable, Optional, Iterable, Set, cast, FrozenSet, Union, Any
from beancount.core.number import MISSING, ZERO, Decimal
from beancount.core.data import Transaction, Posting, Meta, Cost, CostSpec
from beancount.core.amount import mul as amount_mul
from beancount.core.amount import Amount
from beancount.parser import booking_full
from .journal_editor import META_IGNORE
from .sorted_list import SortedList
from .posting_date import get_posting_date, POSTING_DATE_KEY, POSTING_TRANSACTION_DATE_KEY
    def remove_posting(self, entry: Transaction, mp: MatchablePosting):
        source_posting_ids = _entry_and_posting_ids_key(entry, mp)

        meta = mp.posting.meta
        account = mp.posting.account
        if not is_unknown_account(account) and meta:
            for key in self.metadata_keys:
                value = meta.get(key)
                if value is None: continue
                group = self._keyed_postings.get((account, key, value))
                if group is not None:
                    group.pop(source_posting_ids, None)

        group = self._postings.get(_date_key(entry, mp))
        if group is not None:
            group.pop(source_posting_ids, None)

    def remove_transaction(self, transaction: Transaction):
        for mp in get_matchable_postings_from_transaction(
                transaction, self.is_cleared):
            self.remove_posting(transaction, mp)

    def get_posting_matches(self,
                            entry: Transaction,
                            posting: Posting,
                            negate=False) -> List[Tuple[Transaction, MatchablePosting]]:
        posting_date = posting.meta and posting.meta.get(POSTING_DATE_KEY)
        is_date_exact = posting_date is not None
        date = (posting_date or
                (posting.meta and

# Path: beancount_import/journal_editor.py
# META_IGNORE = get_meta_ignore()
# 
# Path: beancount_import/sorted_list.py
# class SortedList(Generic[K, V]):
#     def __init__(self, items: Iterable[Tuple[K, V]]) -> None:
#         entries = sorted(items, key=lambda x: x[0])
#         self.keys = [x[0] for x in entries]
#         self.values = [x[1] for x in entries]
# 
#     def __repr__(self) -> str:
#         return repr(list(zip(self.keys, self.values)))
# 
#     def find(self, lower_bound: K, upper_bound: K) -> Iterable[V]:
#         keys = self.keys
#         begin_pos = bisect.bisect_left(keys, lower_bound)
#         end_pos = bisect.bisect_right(keys, upper_bound)
#         if begin_pos == end_pos:
#             return ()
#         return itertools.islice(self.values, begin_pos, end_pos)
# 
# Path: beancount_import/posting_date.py
# def get_posting_date(entry, posting):
#     """Returns the date associated with a posting."""
#     return ((posting.meta and (posting.meta.get(POSTING_DATE_KEY) or
#                                posting.meta.get(POSTING_TRANSACTION_DATE_KEY))) or entry.date)
# 
# POSTING_DATE_KEY = 'date'
# 
# POSTING_TRANSACTION_DATE_KEY = 'transaction_date'


# Path: beancount_import/matching.py
import datetime
import collections
import itertools
import beancount.parser.printer
from typing import Sequence, Tuple, List, NamedTuple, Dict, Callable, Optional, Iterable, Set, cast, FrozenSet, Union, Any
from beancount.core.number import MISSING, ZERO, Decimal
from beancount.core.data import Transaction, Posting, Meta, Cost, CostSpec
from beancount.core.amount import mul as amount_mul
from beancount.core.amount import Amount
from beancount.parser import booking_full
from .journal_editor import META_IGNORE
from .sorted_list import SortedList
from .posting_date import get_posting_date, POSTING_DATE_KEY, POSTING_TRANSACTION_DATE_KEY

    def remove_posting(self, entry: Transaction, mp: MatchablePosting):
        source_posting_ids = _entry_and_posting_ids_key(entry, mp)

        meta = mp.posting.meta
        account = mp.posting.account
        if not is_unknown_account(account) and meta:
            for key in self.metadata_keys:
                value = meta.get(key)
                if value is None: continue
                group = self._keyed_postings.get((account, key, value))
                if group is not None:
                    group.pop(source_posting_ids, None)

        group = self._postings.get(_date_key(entry, mp))
        if group is not None:
            group.pop(source_posting_ids, None)

    def remove_transaction(self, transaction: Transaction):
        for mp in get_matchable_postings_from_transaction(
                transaction, self.is_cleared):
            self.remove_posting(transaction, mp)

    def get_posting_matches(self,
                            entry: Transaction,
                            posting: Posting,
                            negate=False) -> List[Tuple[Transaction, MatchablePosting]]:
        posting_date = posting.meta and posting.meta.get(POSTING_DATE_KEY)
        is_date_exact = posting_date is not None
        date = (posting_date or
                (posting.meta and

                 posting.meta.get(POSTING_TRANSACTION_DATE_KEY)) or entry.date)