from typing import List from apollo_utils.core.constants import MARKET_WORLDWIDE from apollo_utils.core.constants.market import DELPHI_GLOBAL_MARKET, GLOBAL_MARKET, GLOBAL_MARKET_CODE from apollo_utils.core.legacy.constants.core import MARKET_GLOBAL, SPOTIFY_MARKET_GLOBAL def fix_country_code_worldwide( original_country_code: str or List[str], worldwide_country_code: str = MARKET_WORLDWIDE ) -> str or List[str]: """Replace global/worldwide/_gl with chosen value. Args: original_country_code: Original country code value or list. worldwide_country_code: Required worldwide value. Returns: Fixed country code value or list. """ if isinstance(original_country_code, str): if original_country_code in (MARKET_GLOBAL, SPOTIFY_MARKET_GLOBAL, MARKET_WORLDWIDE): original_country_code = worldwide_country_code elif isinstance(original_country_code, list): for index, item in enumerate(original_country_code): if item in (MARKET_GLOBAL, SPOTIFY_MARKET_GLOBAL, MARKET_WORLDWIDE): original_country_code[index] = worldwide_country_code return original_country_code def convert_market(market: str, global_market: str = DELPHI_GLOBAL_MARKET) -> str: """Convert global market codes. Args: market: Current market code. global_market: Required global market code. Returns: Correct market code. """ market = market.lower() if market in (DELPHI_GLOBAL_MARKET, GLOBAL_MARKET, GLOBAL_MARKET_CODE): return global_market return market