
def tag_args(kwargs):
    return "".join(f" {'class' if key == 'clazz' else key.replace('_', '-')}={repr(value)}" for key, value in kwargs.items())

class PairTag:
    __slots__ = ["stream", "name", "kwargs"]
    def __init__(self, stream, name, **kwargs):
        self.stream = stream
        self.name = name
        self.kwargs = tag_args(kwargs)
    def __enter__(self):
        print(f"<{self.name}{self.kwargs}>", file=self.stream, end="")
    def __exit__(self, _1, _2, _3):
        print(f"</{self.name}>", file=self.stream, end="")
