146b43bff003ceda46cf9a5d40a47f7674996d2e0Zhen Wang#!/usr/bin/env python 246b43bff003ceda46cf9a5d40a47f7674996d2e0Zhen Wangimport sys 346b43bff003ceda46cf9a5d40a47f7674996d2e0Zhen Wangimport urllib.request, urllib.error, urllib.parse 446b43bff003ceda46cf9a5d40a47f7674996d2e0Zhen Wangimport codecs 546b43bff003ceda46cf9a5d40a47f7674996d2e0Zhen Wang 646b43bff003ceda46cf9a5d40a47f7674996d2e0Zhen Wangdef main(): 746b43bff003ceda46cf9a5d40a47f7674996d2e0Zhen Wang encodings = [] 846b43bff003ceda46cf9a5d40a47f7674996d2e0Zhen Wang f = urllib.request.urlopen(sys.argv[1]) 946b43bff003ceda46cf9a5d40a47f7674996d2e0Zhen Wang for line in f: 1046b43bff003ceda46cf9a5d40a47f7674996d2e0Zhen Wang if line.startswith("Name: ") or line.startswith("Alias: "): 1146b43bff003ceda46cf9a5d40a47f7674996d2e0Zhen Wang enc = line.split()[1] 1246b43bff003ceda46cf9a5d40a47f7674996d2e0Zhen Wang try: 1346b43bff003ceda46cf9a5d40a47f7674996d2e0Zhen Wang codecs.lookup(enc) 1446b43bff003ceda46cf9a5d40a47f7674996d2e0Zhen Wang if enc.lower not in encodings: 1546b43bff003ceda46cf9a5d40a47f7674996d2e0Zhen Wang encodings.append(enc.lower()) 1646b43bff003ceda46cf9a5d40a47f7674996d2e0Zhen Wang except LookupError: 1746b43bff003ceda46cf9a5d40a47f7674996d2e0Zhen Wang pass 1846b43bff003ceda46cf9a5d40a47f7674996d2e0Zhen Wang sys.stdout.write("encodings = frozenset((\n") 1946b43bff003ceda46cf9a5d40a47f7674996d2e0Zhen Wang for enc in encodings: 2046b43bff003ceda46cf9a5d40a47f7674996d2e0Zhen Wang sys.stdout.write(' "%s",\n'%enc) 2146b43bff003ceda46cf9a5d40a47f7674996d2e0Zhen Wang sys.stdout.write(' ))') 2246b43bff003ceda46cf9a5d40a47f7674996d2e0Zhen Wang 2346b43bff003ceda46cf9a5d40a47f7674996d2e0Zhen Wangif __name__ == "__main__": 2446b43bff003ceda46cf9a5d40a47f7674996d2e0Zhen Wang main()