<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def from_flag(cls, flag):
 """ Return an Endpoint subclass instance based on the given flag. The instance that is returned depends on the endpoint name embedded though for legacy purposes, the ``endpoint.`` prefix can be omitted. The ``{name}}`` portion will be passed to :meth:`~charms.reactive.endpoints.Endpoint.from_name`. If the flag is not set, an appropriate Endpoint subclass cannot be found, or the flag name can't be parsed, ``None`` will be returned. """

        if not is_flag_set(flag) or '.' not in flag:
            return None
        parts = flag.split('.')
        if parts[0] == 'endpoint':
            return cls.from_name(parts[1])
        else:
            # some older handlers might not use the 'endpoint' prefix
            return cls.from_name(parts[0])