def _parse_moniker(moniker, accept_value=True):
    r"""Take a registry moniker and return the computer, root key, subkey path and value label.
    NB: neither the computer nor the registry key need exist; they
    need simply to be of the right format. The slashes must be backslashes (since
    registry key names can contain forward slashes). accept_value is mostly used
    internally to indicate that a key search is going on, where a colon is to be
    considered part of the key name; if it is True, then the colon is to be
    considered a value separator.

    The moniker must be of the form:

        [\\computer\]HKEY[\subkey path][:value]

    Valid monikers are:
        \\SVR01\HKEY_LOCAL_MACHINE\Software\Python:Version
        -> "SVR01", 0x80000002, "Software\Python", "Version"

        HKEY_CURRENT_USER\Software
        -> "", 0x80000001, "Software", None

        HKEY_CURRENT_USER\Software\Python:
        -> "", 0x80000001, "Software\Python", ""
    """
    if accept_value:
        moniker_parser = re.compile(r"(?:\\\\([^\\]+)\\)?([^:]+)(:?)(.*)", re.UNICODE)
    else:
        moniker_parser = re.compile(r"(?:\\\\([^\\]+)\\)?(.*)", re.UNICODE)

    matcher = moniker_parser.match(moniker)
    if not matcher:
        raise x_moniker_ill_formed(errctx="_parse_moniker", errmsg="Ill-formed moniker: %s" % moniker)

    if accept_value:
        computer, keypath, colon, value = matcher.groups()
    else:
        computer, keypath = matcher.groups()
        colon = value = None
    keys = keypath.split(sep)

    root = path = None

    key0 = keys.pop(0)
    try:
        root = REGISTRY_HIVE[key0.upper()]
    except KeyError:
        root = None

    if root is None and keys:
        key1 = keys.pop(0)
        try:
            root = REGISTRY_HIVE[key1.upper()]
        except __HOLE__:
            root = None

    if root is None:
        raise x_moniker_no_root(errctx="_parse_moniker", errmsg="A registry hive must be the first or second segment in moniker")

    path = sep.join(keys)

    #
    # If a value is indicated (by a colon) but none is supplied,
    # use "" to indicate that the default value is requested.
    # Otherwise use None to indicate that no value is requested
    #
    if value == "" and not colon:
        value = None
    return computer, root, path, value
dataset/ETHPy150Open tjguk/winsys/winsys/registry.py/_parse_moniker