def METHOD_NAME(g1: str, g2: str) -> bool:
    """
    hostglob_matches determines whether or not two given DNS globs are
    compatible with each other, i.e. whether or not there can be a hostname
    that matches both globs.
    Note that it does not actually find such a hostname: a return of True
    just means that such a hostname could exist.
    """
    # logging.debug("hostglob_matches: %s ~ %s", g1, g2)
    # Short-circuit: if g1 & g2 are equal, we're done here.
    if g1 == g2:
        # logging.debug("  equal => True")
        return True
    # Next special case: if either glob is "*", then it matches everything.
    if (g1 == "*") or (g2 == "*"):
        # logging.debug("  \"*\" present => True")
        return True
    # Final special case: if either starts with a bare ".", that's not OK.
    # (Ending with a bare "." is different because DNS.)
    if g1[0] == "." or g2[0] == ".":
        # logging.debug("  exact match starts with bare \".\" => False")
        return False
    # OK, we don't have the simple-"*" case, so any wildcards must be at
    # the start or end, and they must be a component alone.
    g1start = g1[0] == "*"
    g1end = g1[-1] == "*"
    g2start = g2[0] == "*"
    g2end = g2[-1] == "*"
    # logging.debug("  g1start=%s g1end=%s g2start=%s g2end=%s", g1start, g1end, g2start, g2end)
    if (g1start and g1end) or (g2start and g2end):
        # Not a valid DNS glob: you can't have a "*" at both ends. (If you do,
        # Envoy will decide that the one at the start is the allowed wildcard, and
        # treat the one at the end as a literal "*", which will match nothing.)
        return g1 == g2
    if not (g1start or g1end or g2start or g2end):
        # No valid wildcards. and we already know that they're not equal,
        # so this is not a match.
        # logging.debug("  not equal => False")
        return False
    # OK, if we're here, we have a wildcard to check. There are a few cases
    # here, so we'll start with the easy one: one value starts with "*" and
    # the other ends with "*", because those can always overlap as long as
    # the overlap between isn't empty -- and in this method, we only need to
    # concern ourselves with being sure that there is a possibility of a match
    # to both.
    if (g1start and g2end) or (g2start and g1end):
        # logging.debug("  start/end pair => True")
        return True
    # OK, now we have to actually do some work. Again, we really only have to
    # be convinced that it's possible for something to match, so e.g.
    #
    # *example.com, example.com
    #
    # is not a valid pair, because that "*" must never match an empty string.
    # However,
    #
    # *example.com, *.example.com
    #
    # is fine, because e.g. "foo.example.com" matches both.
    if g1start:
        return hostglob_matches_start(g1, g2, g2start)
    if g2start:
        return hostglob_matches_start(g2, g1, g1start)
    if g1end:
        return hostglob_matches_end(g1, g2, g2end)
    if g2end:
        return hostglob_matches_end(g2, g1, g1end)
    # This is "impossible"
    return False