from six.moves.urllib.request import pathname2url


def _quoteLocalPath(filename):
    """Quote local paths to file URL-s.

    CifFile reads files with urlopen, which fails for Windows paths or
    for paths containing ":".

    Parameters
    ----------
    filename : str
        The path to be corrected.

    Returns
    -------
    str
        The fixed URL when it contains ":" or `filename`.
        Return filename if it forms http or ftp URL.
    """
    rv = filename
    cnvflag = False
    if ':' in filename:
        head = filename.split(':', 1)[0].lower()
        cnvflag = head.isalpha() and head not in ('http', 'https', 'ftp')
    if cnvflag:
        rv = pathname2url(filename)
    return rv