Add targeted comments for non-obvious constraints and invariants
- logger.py: note why log path uses abspath(__file__) instead of a relative path - token.py: note why [7:] slice is safe (startswith already verified) - ipcalc.py: explain /32 single-host and /31 RFC-3021 point-to-point special cases; explain why (~netmask) must be masked with 0xFFFFFFFF (Python ~int returns a negative arbitrary-precision value, not a 32-bit unsigned integer) - notes.py: document the module-level _table_ready flag lifetime; explain why tzinfo is stripped before passing datetime to mysql-connector - admin.py: document the module-level _tables_initialized flag lifetime Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -26,10 +26,13 @@ def ip_calculate():
|
||||
|
||||
# Avoid materialising millions of host objects for large networks.
|
||||
if prefix == 32:
|
||||
# Single-host route: the address is both network and host.
|
||||
total_hosts = 1
|
||||
first_host = str(network.network_address)
|
||||
last_host = str(network.network_address)
|
||||
elif prefix == 31:
|
||||
# RFC 3021 point-to-point: both addresses are usable hosts,
|
||||
# there is no dedicated network or broadcast address.
|
||||
total_hosts = 2
|
||||
first_host = str(network.network_address)
|
||||
last_host = str(network.broadcast_address)
|
||||
@@ -39,6 +42,8 @@ def ip_calculate():
|
||||
last_host = str(ipaddress.IPv4Address(bcast_int - 1))
|
||||
|
||||
netmask_int = int(network.netmask)
|
||||
# Python's ~ on an int yields a negative arbitrary-precision value;
|
||||
# mask to 32 bits to get the correct unsigned wildcard address.
|
||||
wildcard = str(ipaddress.IPv4Address((~netmask_int) & 0xFFFFFFFF))
|
||||
ip_class = "Privat" if network.is_private else "Öffentlich"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user