| 500 | |
| 501 | |
| 502 | class NetCache: |
| 503 | def __init__(self): |
| 504 | # type: () -> None |
| 505 | self._caches_list = [] # type: List[CacheInstance] |
| 506 | |
| 507 | def add_cache(self, cache): |
| 508 | # type: (CacheInstance) -> None |
| 509 | self._caches_list.append(cache) |
| 510 | setattr(self, cache.name, cache) |
| 511 | |
| 512 | def new_cache(self, name, timeout=None): |
| 513 | # type: (str, Optional[int]) -> CacheInstance |
| 514 | c = CacheInstance(name=name, timeout=timeout) |
| 515 | self.add_cache(c) |
| 516 | return c |
| 517 | |
| 518 | def __delattr__(self, attr): |
| 519 | # type: (str) -> NoReturn |
| 520 | raise AttributeError("Cannot delete attributes") |
| 521 | |
| 522 | def update(self, other): |
| 523 | # type: (NetCache) -> None |
| 524 | for co in other._caches_list: |
| 525 | if hasattr(self, co.name): |
| 526 | getattr(self, co.name).update(co) |
| 527 | else: |
| 528 | self.add_cache(co.copy()) |
| 529 | |
| 530 | def flush(self): |
| 531 | # type: () -> None |
| 532 | for c in self._caches_list: |
| 533 | c.flush() |
| 534 | |
| 535 | def __repr__(self): |
| 536 | # type: () -> str |
| 537 | return "\n".join(c.summary() for c in self._caches_list) |
| 538 | |
| 539 | |
| 540 | class ScapyExt: |