Beispiel #1
0
def LookupRegionCountry(region, country):
	"""This will convert 'region' and 'country' into the best (English language) strings ever

	Keyword arguments:
	region -- the name of a region (state or province) (or null)
	country -- the name of a country (or null)
	"""
	if country and len(country) == 2:
		country = bm_locales.country_to_name(country)

	if country:
		if country == "U.S.A.": country = "United States"
		elif country == "USA.": country = "United States"
		elif country == "USA": country = "United States"

	if country in [ "Canada", "United States" ] and region:
		region, x = region_normalize.get(region.lower(), ( region, country ))

	if not country and region:
		region, country = region_normalize.get(region.lower(), ( region, country ))

	return	{
		Region : region or "", 
		CountryName : country or "",
	}
Beispiel #2
0
def LookupPhone(phone):
	phone = re.sub("[^+\d]", " ", phone)
	phone = re.sub("\s+", " ", phone)

	country_code = None
	area_code = None

	for pattern in pattern_res:
		match = re.search(pattern, phone)
		if match:
			try: area_code = match.group("area_code")
			except: pass

			try: country_code = match.group("country_code")
			except: pass

			break

	if area_code:
		area_code_map = bm_locales.area_code(area_code)
		if area_code_map:
			country = area_code_map.get("country")
			country = bm_locales.country_to_name(country)

			state = area_code_map.get("state")
			state, x = region_normalize.get(state.lower(), ( state, country ))

			return	{
				Region : state,
				CountryName : country,
				Locality : area_code_map.get("locality"),
			}
	elif country_code:
		for x in xrange(1, len(country_code) + 1):
			country_code_map = bm_locales.itu_calling_code(country_code[:x])
			if country_code_map:
				country = country_code_map.get("country")
				country = bm_locales.country_to_name(country)

				return	{
					CountryName : country,
				}

	return	{}