def version_from_string(version_str):
    """ Convert a version string of the form m, m.n or m.n.o to an encoded
    version number (or None if it was an invalid format).  version_str is the
    version string.
    """
    parts = version_str.split('.')
    if not isinstance(parts, list):
        return None
    if len(parts) == 1:
        parts.append('0')
    if len(parts) == 2:
        parts.append('0')
    if len(parts) != 3:
        return None
    version = 0
    for part in parts:
        try:
            v = int(part)
        except ValueError:
            return None
        version = (version << 8) + v
    return version
