code: def _raise_closed(reason):
          
          if isinstance(reason, Message):
              if reason.method.klass.name == "channel":
                  raise ChannelClosed(reason)
              elif reason.method.klass.name == "connection":
                  raise ConnectionClosed(reason)
          raise Closed(reason)
docs: Raise the appropriate Closed-based error for the given reason.