def _parse_query_string(query):
    """Used for replacing cgi.parse_qsl.
    The cgi version returns the same pair for query 'key'
    and query 'key=', so reconstruction
    maps to the same string. But some sites does not handle both versions
    in the same way.
    This version returns (key, None) in the first case, and (key, '') in the
    second one, so correct reconstruction can be performed."""
    params = query.split('&')
    keyvals = []
    for param in params:
        kv = param.split('=') + [None]
        keyvals.append((kv[0], kv[1]))
    return keyvals
