def build_iso3166(filename):
    """Rebuild the iso3166 (country code) module from the URL. """
    import urllib2
    outf = open(filename, "w")

    outf.write("""#!/usr/bin/python
# -*- coding: iso-8859-1 -*-
# generated by build_iso3166()

""")
    outf.write("COUNTRYCODES = {\n")
    try:
        ccf = urllib2.urlopen(URLS["countrycodes"])
    except:
        print "Could not get country codes from %r, using local file." % (URLS["countrycodes"],)
        ccf = open(URLS["countrycodesfile"])
    ccf.readline() # eat first header line
    for line in ccf.readlines():
        vals = line.strip().split(";")
        if len(vals) != 2:
            continue
        outf.write("  %r: %r,\n" % (vals[1], vals[0]))
    outf.write("}\n\n")
    outf.close()
    ccf.close()
dataset/ETHPy150Open kdart/pycopia/core/pycopia/ISO/__init__.py/build_iso3166/original