- if args[0] == "--build-unihan":
- if len(args) != 3:
- print "cvt-utf8: --build expects two filename arguments"
- sys.exit(1)
- infile = open(args[1], "r")
- s = infile.read(1)
- # Unihan.txt starts with a hash. If this file starts with a
- # P, we assume it's a zip file ("PK").
- if s == "P":
- infile = zip_untangler(infile, s)
- s = ""
- outfile = args[2]
- else:
- if len(args) != 2:
- print "cvt-utf8: --fetch-build-unihan expects one filename argument"
- sys.exit(1)
- import urllib
- infile = urllib.urlopen("ftp://ftp.unicode.org/Public/UNIDATA/Unihan.zip")
- # We know this one is zipped.
- infile = zip_untangler(infile, "")
- outfile = args[1]
- s = ""
- # Now build the database.
- if outfile[-3:] == ".db":
- print "cvt-utf8: warning: you should not append .db to db name"
-
- db = anydbm.open(outfile, "n")
- while 1:
- s = s + infile.readline()
- if s == "": break
- while s[-1:] == "\r" or s[-1:] == "\n":
- s = s[:-1]
- sa = string.split(s, "\t")
- if len(sa) == 3 and sa[1] == "kDefinition" and sa[0][:2] == "U+":
- db[sa[0][2:]] = sa[2]
- s = ""
- db.close()
- sys.exit(0)
+ if args[0] == "--build-unihan":
+ if len(args) != 3:
+ print "cvt-utf8: --build expects two filename arguments"
+ sys.exit(1)
+ infile = open(args[1], "r")
+ s = infile.read(1)
+ # Unihan.txt starts with a hash. If this file starts with a
+ # P, we assume it's a zip file ("PK").
+ if s == "P":
+ infile = zip_untangler(infile, s)
+ s = ""
+ outfile = args[2]
+ else:
+ if len(args) != 2:
+ print "cvt-utf8: --fetch-build-unihan expects one filename argument"
+ sys.exit(1)
+ import urllib
+ infile = urllib.urlopen("ftp://ftp.unicode.org/Public/UNIDATA/Unihan.zip")
+ # We know this one is zipped.
+ infile = zip_untangler(infile, "")
+ outfile = args[1]
+ s = ""
+ # Now build the database.
+ if outfile[-3:] == ".db":
+ print "cvt-utf8: warning: you should not append .db to db name"
+
+ db = anydbm.open(outfile, "n")
+ while 1:
+ s = s + infile.readline()
+ if s == "": break
+ while s[-1:] == "\r" or s[-1:] == "\n":
+ s = s[:-1]
+ sa = string.split(s, "\t")
+ if len(sa) == 3 and sa[1] == "kDefinition" and sa[0][:2] == "U+":
+ db[sa[0][2:]] = sa[2]
+ s = ""
+ db.close()
+ sys.exit(0)