I have a library coming out which I made as a drop in replacement for python hpack called cyhpack and I wanted to try developing a better solution for injecting my own Decoder and Encoder which runs ls-hpack under the hood. As of currently, here is my workaround but I was wondering if a better implementation could be implemented such as a factory attribute or an Abstract class could be made to accommodate my version and the pure python one as well?
from __future__ import annotations
from h2.config import H2Configuration
from h2.connection import H2Connection as _H2Connection
from .hpack import Decoder, Encoder
class H2Connection(_H2Connection):
"""
Contains an overridable version of H2Connection that drops
python hpack in exchange for cyhpack for faster performance
and speed.
"""
def __init__(self, config: H2Configuration | None = None):
super().__init__(config)
self.encoder = Encoder()
self.decoder = Decoder()