import base64,struct,zlib,http.server
from urllib.parse import quote

def chunk(t,d):return struct.pack('>I',len(d))+t+d+struct.pack('>I',zlib.crc32(t+d)&0xffffffff)
raw=b''.join(b'\0'+b''.join(bytes((255,35,140,255) if x<16 else (255,220,40,255)) for x in range(32)) for y in range(32))
big=base64.b64encode(b'\x89PNG\r\n\x1a\n'+chunk(b'IHDR',struct.pack('>IIBBBBB',32,32,8,6,0,0,0))+chunk(b'IDAT',zlib.compress(raw))+chunk(b'IEND',b'')).decode()
# Ensure the exact same visible PNG payload exercises all reserved base64 characters.
while not all(c in big for c in '+/='):
 raw+=b'\0';big=base64.b64encode(b'\x89PNG\r\n\x1a\n'+chunk(b'IHDR',struct.pack('>IIBBBBB',32,32,8,6,0,0,0))+chunk(b'IDAT',zlib.compress(raw))+chunk(b'IEND',b'')).decode()
small='iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+ip1sAAAAASUVORK5CYII='
class Handler(http.server.BaseHTTPRequestHandler):
 def do_GET(self):
  if self.path not in ['/big-escaped.html','/big-plain.html','/escaped.html','/plain.html']:self.send_error(404);return
  payload=big if 'big-' in self.path else small
  escaped='escaped' in self.path; title=('32px ' if 'big-' in self.path else '1px ')+('Escaped' if escaped else 'Plain')
  href='data:image/png;base64,'+(quote(payload,safe="~()*!.'-") if escaped else payload)
  body=f'''<!doctype html><title>{title}</title><link rel="icon" href="{href}"><style>body{{font:20px system-ui;background:#f8fafc;color:#172033;padding:48px}}h1{{font-size:32px}}img{{width:96px;height:96px;image-rendering:pixelated;border:1px solid #ccd}}code{{font-size:16px;overflow-wrap:anywhere}}</style><h1>{title} inline favicon</h1><p>One PNG favicon, no external fallback.</p><img src="{href}"><p>Payload: {'percent-encoded base64 (%2B, %2F, %3D)' if escaped else 'plain base64 control'}</p><p>The Browser tab should show the same favicon for both forms.</p>'''.encode()
  self.send_response(200);self.send_header('Content-Type','text/html');self.end_headers();self.wfile.write(body)
 def log_message(self,*a):pass
http.server.HTTPServer(('127.0.0.1',18888),Handler).serve_forever()
