<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def get_next(self, protocol='http', format=False, policy='loop'):
 """Get the next proxy Args: protocol (str):
 'http' or 'https'. (default 'http') format (bool):
 Whether to format the proxy. (default False) policy (str):
 Either 'loop' or 'random', indicating the policy of getting the next proxy. If set to 'loop', will return proxies in turn, otherwise will return a proxy randomly. Returns: Proxy or dict: If format is true, then return the formatted proxy which is compatible with requests.Session parameters, otherwise a Proxy object. """

        if not self.proxies[protocol]:
            return None
        if policy == 'loop':
            idx = self.idx[protocol]
            self.idx[protocol] = (idx + 1) % len(self.proxies[protocol])
        elif policy == 'random':
            idx = random.randint(0, self.proxy_num(protocol) - 1)
        else:
            self.logger.error('Unsupported get_next policy: {}'.format(policy))
            exit()
        proxy = self.proxies[protocol][self.addr_list[protocol][idx]]
        if proxy.weight < random.random():
            return self.get_next(protocol, format, policy)
        if format:
            return proxy.format()
        else:
            return proxy