docs: def decode(tagstring):
      '''Decodes a tag-string from an IRC-message into a python dictionary.
      See IRC Message Tags: http://ircv3.net/specs/core/message-tags-3.2.html
  
      >>> from pprint import pprint
      >>> pprint(decode('key=value'))
      {'key': 'value'}
  
      >>> pprint(decode('aaa=bbb;ccc;example.com/ddd=eee'))
      {'aaa': 'bbb', 'ccc': None, 'example.com/ddd': 'eee'}
  
      >>> s = r'key=value\\:with\\sspecial\\\\characters;key2=with=equals'
      >>> pprint(decode(s))
      {'key': 'value;with special\\\\characters', 'key2': 'with=equals'}
      >>> print(decode(s)['key'])
      value;with special\\characters
  
      >>> print(decode(r'key=\\\\something')['key'])
      \\something
  
      '''
      if not tagstring:
          # None/empty = no tags
          return {}
  
      tags = {}
  
      for tag in tagstring.split(";"):
          # value is either everything after "=", or None
          key, value = (tag.split("=", 1) + [None])[:2]
          if not _valid_key.match(key):
              raise ValueError("invalid tag key: " + key)
          if value:
              if not _valid_escaped_value.match(value):
                  raise ValueError("invalid escaped tag value: " + value)
              value = _unescape(value)
          tags[key] = value
  
      return tags