rebuilt_path += (':' if rebuilt_path else '') + step_name
yield rebuilt_path, step_name
- @classmethod
- def ensure_in_dict(cls, full_path: str, paths_to_accs: dict[str, Self]
- ) -> None:
- """If full_path not key in paths_to_accs, add it with new Account."""
- parent_path = ''
- for path, step_name in cls.path_to_steps(full_path):
- if path not in paths_to_accs:
- paths_to_accs[path] = cls(
- paths_to_accs[parent_path] if parent_path else None,
- step_name)
- parent_path = path
-
class DatLine(Dictable):
"""Line of .dat file parsed into comments and machine-readable data."""
return True
return False
- def apply_to_account_dict(self, acc_dict: dict[str, Account]) -> None:
- """Update account directory with data from .account_changes."""
- for acc_name, wealth in self.account_changes.items():
- Account.ensure_in_dict(acc_name, acc_dict)
- acc_dict[acc_name].add_wealth_diff(self.id_, wealth)
-
class Handler(PlomHttpHandler):
""""Handles HTTP requests."""
break
if already_registered:
continue
- Account.ensure_in_dict(path, self.server.accounts)
+ self.server.ensure_account(path)
before = self.server.accounts[path].get_wealth(id_ - 1)
after = self.server.accounts[path].get_wealth(id_)
direct_target = full_path == path
else:
if booked_lines:
booking = Booking(len(self.bookings), booked_lines[:])
- booking.apply_to_account_dict(self.accounts)
+ self._apply_booking_to_accounts(booking)
self.bookings += [booking]
booked_lines.clear()
for acc_name, desc in dat_line.comment_instructions.items():
- Account.ensure_in_dict(acc_name, self.accounts)
+ self.ensure_account(acc_name)
self.accounts[acc_name].desc = desc
self._check_date_order()
for booking in self.bookings:
booking.gap_lines = gap_lines[:-1]
self._recalc_prev_line_empty()
+ def _apply_booking_to_accounts(self, booking: Booking) -> None:
+ for acc_name, wealth in booking.account_changes.items():
+ self.ensure_account(acc_name)
+ self.accounts[acc_name].add_wealth_diff(booking.id_, wealth)
+
+ def ensure_account(self, full_path: str) -> None:
+ """If full_path not in self.accounts, add its tree with Accounts."""
+ parent_path = ''
+ for path, step_name in Account.path_to_steps(full_path):
+ if path not in self.accounts:
+ self.accounts[path] = Account(
+ self.accounts[parent_path] if parent_path else None,
+ step_name)
+ parent_path = path
+
def _check_date_order(self) -> None:
last_date = ''
err_msg = 'date < previous valid date'