Exemplo n.º 1
0
def discover_country(**kwargs):
    """Method used to intelligently discover country record based on provided parameters

    Method requires at least one of the following parameters to be passed along:

    :param country_code
    :param country_prefix
    :
    """
    logging.debug('[discover_country] attempt to discover country against (kwargs: %s)', kwargs)

    if not len(kwargs):
        raise CountryParameterMissing(
            "At least one parameter needs to be passed along to in order be able discover country"
        )

    if kwargs.get('country_prefix'):
        country_search_string = kwargs.get('country_prefix')

    if kwargs.get('country_code'):
        country_search_string = kwargs.get('country_code')

    logging.debug('[discover_country] attempting to discover country against (string: %s)', country_search_string)

    package_class_name = country_search_string.capitalize()
    package_path = __import__('phonedb.countrydb.countries', globals(), locals(), [package_class_name])

    try:
        return getattr(package_path, package_class_name)()
    except AttributeError as e:
        logging.error('[discover_country] unable to discover country against (class_reference: %s)' % package_class_name)
        return None
Exemplo n.º 2
0
    def __init__(self, *args, **kwargs):
        pass

    def __unicode__(self):
        return unicode(' - '.join([self.__class__.__name__, self.country_name]))

    def __str__(self):
        return str(' - '.join([self.__class__.__name__, self.country_name]))

    def __repr__(self):
        return '%s()' % self.__class__.__name__


with closing(get_country_data()) as data:
    country_data = next(data)
    logging.debug('[builder] building country against (country_data: %s)' % country_data)

    country_class_name = str(country_data.get('country_code').capitalize())

    docstring = """%s country resource

    Country resource is designed to fetch out country and state specific data about the country
    -------------------------
    Attributes: %s

    """ % (
        country_class_name,
        map(str, []),
    )

    country_resource_dict = {