from typing import Optional
from typing import Dict
import shlex


def to_attributes(entry: str) -> Optional[Dict[str, str]]:
    """Convert list of key=value pairs to dictionary."""
    if not entry:
        return None

    lexer = shlex.shlex(entry, posix=True)
    lexer.whitespace_split = True
    lexer.whitespace = ','
    attributes_dict = {}  # type: Dict[str, str]
    attributes_dict = dict(
        pair.split('=', 1) for pair in lexer  # type: ignore
    )
    return attributes_dict