<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_iso3_country_code(cls, country, use_live=True, exception=None):
 # type: (str, bool, Optional[ExceptionUpperBound]) -> Optional[str] """Get ISO3 code for cls. Only exact matches or None are returned. Args: country (str):
 Country for which to get ISO3 code use_live (bool):
 Try to get use latest data from web rather than file in package. Defaults to True. exception (Optional[ExceptionUpperBound]):
 An exception to raise if country not found. Defaults to None. Returns: Optional[str]: ISO3 country code or None """

        countriesdata = cls.countriesdata(use_live=use_live)
        countryupper = country.upper()
        len_countryupper = len(countryupper)
        if len_countryupper == 3:
            if countryupper in countriesdata['countries']:
                return countryupper
        elif len_countryupper == 2:
            iso3 = countriesdata['iso2iso3'].get(countryupper)
            if iso3 is not None:
                return iso3

        iso3 = countriesdata['countrynames2iso3'].get(countryupper)
        if iso3 is not None:
            return iso3

        for candidate in cls.expand_countryname_abbrevs(countryupper):
            iso3 = countriesdata['countrynames2iso3'].get(candidate)
            if iso3 is not None:
                return iso3

        if exception is not None:
            raise exception
        return None