def get_lastest_iso3166(filename=None, url=None):
    """
    Retrieves the latest ISO 3166-1 alpha-2 country code text file from the
    iso.org website.

    Saves URL contents to filename. Defaults to the current working directory
    and uses the basename from URL if not specified.

    Assumes the default ISO 3166 URL if not specified.

    """
    #   Pick default URL if not specified.
    if url is None:
        url='http://www.iso.org/iso/list-en1-semic-3.txt'

    print 'downloading %s' % url

    request = urllib2.Request(url)
    response = urllib2.urlopen(request)

    if filename is None:
        save_path = os.path.dirname(__file__)
        basename = os.path.basename(response.geturl())
        filename = os.path.join(save_path, basename)

    fh = open(filename, 'wb')
    fh.write(response.read())
    fh.close()

    Retrieves the latest ISO 3166-1 alpha-2 country code text file from the
    iso.org website.

    Saves URL contents to filename. Defaults to the current working directory
    and uses the basename from URL if not specified.

    Assumes the default ISO 3166 URL if not specified.

    
recipes/Python/576768_Capitalizing_ISO_3166_country_names/recipe-576768.py