Package gchecky :: Module data
[hide private]
[frames] | no frames]

Source Code for Module gchecky.data

  1  #!/usr/bin/python 
  2  # coding=utf-8 
  3   
  4  from gxml import String 
  5   
  6  """ 
  7  Country Code: 
  8  http://www.iso.org/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1.html 
  9  """ 
 10   
 11  COUNTRY_CODES = { 
 12  'AF':'AFGHANISTAN', 
 13  'AX':'ÅLAND ISLANDS', 
 14  'AL':'ALBANIA', 
 15  'DZ':'ALGERIA', 
 16  'AS':'AMERICAN SAMOA', 
 17  'AD':'ANDORRA', 
 18  'AO':'ANGOLA', 
 19  'AI':'ANGUILLA', 
 20  'AQ':'ANTARCTICA', 
 21  'AG':'ANTIGUA AND BARBUDA', 
 22  'AR':'ARGENTINA', 
 23  'AM':'ARMENIA', 
 24  'AW':'ARUBA', 
 25  'AU':'AUSTRALIA', 
 26  'AT':'AUSTRIA', 
 27  'AZ':'AZERBAIJAN', 
 28  'BS':'BAHAMAS', 
 29  'BH':'BAHRAIN', 
 30  'BD':'BANGLADESH', 
 31  'BB':'BARBADOS', 
 32  'BY':'BELARUS', 
 33  'BE':'BELGIUM', 
 34  'BZ':'BELIZE', 
 35  'BJ':'BENIN', 
 36  'BM':'BERMUDA', 
 37  'BT':'BHUTAN', 
 38  'BO':'BOLIVIA', 
 39  'BA':'BOSNIA AND HERZEGOVINA', 
 40  'BW':'BOTSWANA', 
 41  'BV':'BOUVET ISLAND', 
 42  'BR':'BRAZIL', 
 43  'IO':'BRITISH INDIAN OCEAN TERRITORY', 
 44  'BN':'BRUNEI DARUSSALAM', 
 45  'BG':'BULGARIA', 
 46  'BF':'BURKINA FASO', 
 47  'BI':'BURUNDI', 
 48  'KH':'CAMBODIA', 
 49  'CM':'CAMEROON', 
 50  'CA':'CANADA', 
 51  'CV':'CAPE VERDE', 
 52  'KY':'CAYMAN ISLANDS', 
 53  'CF':'CENTRAL AFRICAN REPUBLIC', 
 54  'TD':'CHAD', 
 55  'CL':'CHILE', 
 56  'CN':'CHINA', 
 57  'CX':'CHRISTMAS ISLAND', 
 58  'CC':'COCOS (KEELING) ISLANDS', 
 59  'CO':'COLOMBIA', 
 60  'KM':'COMOROS', 
 61  'CG':'CONGO', 
 62  'CD':'CONGO, THE DEMOCRATIC REPUBLIC OF THE', 
 63  'CK':'COOK ISLANDS', 
 64  'CR':'COSTA RICA', 
 65  'CI':'COTE D\'IVOIRE', 
 66  'HR':'CROATIA', 
 67  'CU':'CUBA', 
 68  'CY':'CYPRUS', 
 69  'CZ':'CZECH REPUBLIC', 
 70  'DK':'DENMARK', 
 71  'DJ':'DJIBOUTI', 
 72  'DM':'DOMINICA', 
 73  'DO':'DOMINICAN REPUBLIC', 
 74  'EC':'ECUADOR', 
 75  'EG':'EGYPT', 
 76  'SV':'EL SALVADOR', 
 77  'GQ':'EQUATORIAL GUINEA', 
 78  'ER':'ERITREA', 
 79  'EE':'ESTONIA', 
 80  'ET':'ETHIOPIA', 
 81  'FK':'FALKLAND ISLANDS (MALVINAS)', 
 82  'FO':'FAROE ISLANDS', 
 83  'FJ':'FIJI', 
 84  'FI':'FINLAND', 
 85  'FR':'FRANCE', 
 86  'GF':'FRENCH GUIANA', 
 87  'PF':'FRENCH POLYNESIA', 
 88  'TF':'FRENCH SOUTHERN TERRITORIES', 
 89  'GA':'GABON', 
 90  'GM':'GAMBIA', 
 91  'GE':'GEORGIA', 
 92  'DE':'GERMANY', 
 93  'GH':'GHANA', 
 94  'GI':'GIBRALTAR', 
 95  'GR':'GREECE', 
 96  'GL':'GREENLAND', 
 97  'GD':'GRENADA', 
 98  'GP':'GUADELOUPE', 
 99  'GU':'GUAM', 
100  'GT':'GUATEMALA', 
101  'GG':'GUERNSEY', 
102  'GN':'GUINEA', 
103  'GW':'GUINEA-BISSAU', 
104  'GY':'GUYANA', 
105  'HT':'HAITI', 
106  'HM':'HEARD ISLAND AND MCDONALD ISLANDS', 
107  'VA':'HOLY SEE (VATICAN CITY STATE)', 
108  'HN':'HONDURAS', 
109  'HK':'HONG KONG', 
110  'HU':'HUNGARY', 
111  'IS':'ICELAND', 
112  'IN':'INDIA', 
113  'ID':'INDONESIA', 
114  'IR':'IRAN, ISLAMIC REPUBLIC OF', 
115  'IQ':'IRAQ', 
116  'IE':'IRELAND', 
117  'IM':'ISLE OF MAN', 
118  'IL':'ISRAEL', 
119  'IT':'ITALY', 
120  'JM':'JAMAICA', 
121  'JP':'JAPAN', 
122  'JE':'JERSEY', 
123  'JO':'JORDAN', 
124  'KZ':'KAZAKHSTAN', 
125  'KE':'KENYA', 
126  'KI':'KIRIBATI', 
127  'KP':'KOREA, DEMOCRATIC PEOPLE\'S REPUBLIC OF', 
128  'KR':'KOREA, REPUBLIC OF', 
129  'KW':'KUWAIT', 
130  'KG':'KYRGYZSTAN', 
131  'LA':'LAO PEOPLE\'S DEMOCRATIC REPUBLIC', 
132  'LV':'LATVIA', 
133  'LB':'LEBANON', 
134  'LS':'LESOTHO', 
135  'LR':'LIBERIA', 
136  'LY':'LIBYAN ARAB JAMAHIRIYA', 
137  'LI':'LIECHTENSTEIN', 
138  'LT':'LITHUANIA', 
139  'LU':'LUXEMBOURG', 
140  'MO':'MACAO', 
141  'MK':'MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF', 
142  'MG':'MADAGASCAR', 
143  'MW':'MALAWI', 
144  'MY':'MALAYSIA', 
145  'MV':'MALDIVES', 
146  'ML':'MALI', 
147  'MT':'MALTA', 
148  'MH':'MARSHALL ISLANDS', 
149  'MQ':'MARTINIQUE', 
150  'MR':'MAURITANIA', 
151  'MU':'MAURITIUS', 
152  'YT':'MAYOTTE', 
153  'MX':'MEXICO', 
154  'FM':'MICRONESIA, FEDERATED STATES OF', 
155  'MD':'MOLDOVA, REPUBLIC OF', 
156  'MC':'MONACO', 
157  'MN':'MONGOLIA', 
158  'ME':'MONTENEGRO', 
159  'MS':'MONTSERRAT', 
160  'MA':'MOROCCO', 
161  'MZ':'MOZAMBIQUE', 
162  'MM':'MYANMAR', 
163  'NA':'NAMIBIA', 
164  'NR':'NAURU', 
165  'NP':'NEPAL', 
166  'NL':'NETHERLANDS', 
167  'AN':'NETHERLANDS ANTILLES', 
168  'NC':'NEW CALEDONIA', 
169  'NZ':'NEW ZEALAND', 
170  'NI':'NICARAGUA', 
171  'NE':'NIGER', 
172  'NG':'NIGERIA', 
173  'NU':'NIUE', 
174  'NF':'NORFOLK ISLAND', 
175  'MP':'NORTHERN MARIANA ISLANDS', 
176  'NO':'NORWAY', 
177  'OM':'OMAN', 
178  'PK':'PAKISTAN', 
179  'PW':'PALAU', 
180  'PS':'PALESTINIAN TERRITORY, OCCUPIED', 
181  'PA':'PANAMA', 
182  'PG':'PAPUA NEW GUINEA', 
183  'PY':'PARAGUAY', 
184  'PE':'PERU', 
185  'PH':'PHILIPPINES', 
186  'PN':'PITCAIRN', 
187  'PL':'POLAND', 
188  'PT':'PORTUGAL', 
189  'PR':'PUERTO RICO', 
190  'QA':'QATAR', 
191  'RE':'RÉUNION', 
192  'RO':'ROMANIA', 
193  'RU':'RUSSIAN FEDERATION', 
194  'RW':'RWANDA', 
195  'SH':'SAINT HELENA', 
196  'KN':'SAINT KITTS AND NEVIS', 
197  'LC':'SAINT LUCIA', 
198  'PM':'SAINT PIERRE AND MIQUELON', 
199  'VC':'SAINT VINCENT AND THE GRENADINES', 
200  'WS':'SAMOA', 
201  'SM':'SAN MARINO', 
202  'ST':'SAO TOME AND PRINCIPE', 
203  'SA':'SAUDI ARABIA', 
204  'SN':'SENEGAL', 
205  'RS':'SERBIA', 
206  'SC':'SEYCHELLES', 
207  'SL':'SIERRA LEONE', 
208  'SG':'SINGAPORE', 
209  'SK':'SLOVAKIA', 
210  'SI':'SLOVENIA', 
211  'SB':'SOLOMON ISLANDS', 
212  'SO':'SOMALIA', 
213  'ZA':'SOUTH AFRICA', 
214  'GS':'SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS', 
215  'ES':'SPAIN', 
216  'LK':'SRI LANKA', 
217  'SD':'SUDAN', 
218  'SR':'SURINAME', 
219  'SJ':'SVALBARD AND JAN MAYEN', 
220  'SZ':'SWAZILAND', 
221  'SE':'SWEDEN', 
222  'CH':'SWITZERLAND', 
223  'SY':'SYRIAN ARAB REPUBLIC', 
224  'TW':'TAIWAN, PROVINCE OF CHINA', 
225  'TJ':'TAJIKISTAN', 
226  'TZ':'TANZANIA, UNITED REPUBLIC OF', 
227  'TH':'THAILAND', 
228  'TL':'TIMOR-LESTE', 
229  'TG':'TOGO', 
230  'TK':'TOKELAU', 
231  'TO':'TONGA', 
232  'TT':'TRINIDAD AND TOBAGO', 
233  'TN':'TUNISIA', 
234  'TR':'TURKEY', 
235  'TM':'TURKMENISTAN', 
236  'TC':'TURKS AND CAICOS ISLANDS', 
237  'TV':'TUVALU', 
238  'UG':'UGANDA', 
239  'UA':'UKRAINE', 
240  'AE':'UNITED ARAB EMIRATES', 
241  'GB':'UNITED KINGDOM', 
242  'US':'UNITED STATES', 
243  'UM':'UNITED STATES MINOR OUTLYING ISLANDS', 
244  'UY':'URUGUAY', 
245  'UZ':'UZBEKISTAN', 
246  'VU':'VANUATU', 
247  'VE':'VENEZUELA', 
248  'VN':'VIET NAM', 
249  'VG':'VIRGIN ISLANDS, BRITISH', 
250  'VI':'VIRGIN ISLANDS, U.S.', 
251  'WF':'WALLIS AND FUTUNA', 
252  'EH':'WESTERN SAHARA', 
253  'YE':'YEMEN', 
254  'ZM':'ZAMBIA', 
255  'ZW':'ZIMBABWE', 
256  } 
257   
258   
259 -class CountryCode(String):
260 from gchecky.gxml import apply_parent_validation 261 @apply_parent_validation(String, "Country Code: ")
262 - def validate(self, data):
263 if not COUNTRY_CODES.has_key(self.data2str(data)): 264 return "Unknown country code." 265 return True
266 - def data2str(self, data):
267 return str(data).upper()
268 - def str2data(self, text):
269 return COUNTRY_CODES.has_key(text.upper()) and text or None
270 271
272 -class PresentOrNot(String):
273 from gchecky.gxml import apply_parent_validation 274 @apply_parent_validation(String, "PresentOrNot: ")
275 - def validate(self, data):
276 if (data is not None) and (data is not True): 277 return "PresentOrNot could only be equal to True/None." 278 return True
279 - def data2str(self, data):
280 return None
281 - def str2data(self, text):
282 return True
283