def parse_region(region):
 if (isinstance(region, type) and issubclass(region, regions.REGION)):
  return region
 if str(region).isdigit():
  return regions.REGIONS_CHOICES_ID_DICT[int(region)]
 else:
  region_by_slug = regions.REGION_LOOKUP.get(region)
  if (region_by_slug is not None):
   return region_by_slug
  region_lower = region.lower()
  for region in regions.ALL_REGIONS:
   if (unicode(region.name).lower() == region_lower):
    return region

def parse_region ( region ) : if ( isinstance ( region , type ) and issubclass ( region , regions . REGION ) ) : return region if str ( region ) . isdigit ( ) : return regions . REGIONS_CHOICES_ID_DICT [ int ( region ) ] else : region_by_slug = regions . REGION_LOOKUP . get ( region ) if ( region_by_slug is not None ) : return region_by_slug region_lower = region . lower ( ) for region in regions . ALL_REGIONS : if ( unicode ( region . name ) . lower ( ) == region_lower ) : return region
returns a region class definition given a slug .