PageRenderTime 81ms CodeModel.GetById 1ms app.highlight 61ms RepoModel.GetById 15ms app.codeStats 0ms

/django/contrib/localflavor/us/us_states.py

https://code.google.com/p/mango-py/
Python | 326 lines | 316 code | 0 blank | 10 comment | 0 complexity | 980d39ad4a9f712821faa3d05204474c MD5 | raw file
  1"""
  2A mapping of state misspellings/abbreviations to normalized
  3abbreviations, and alphabetical lists of US states, territories,
  4military mail regions and non-US states to which the US provides
  5postal service.
  6
  7This exists in this standalone file so that it's only imported into memory
  8when explicitly needed.
  9"""
 10
 11# The 48 contiguous states, plus the District of Columbia.
 12CONTIGUOUS_STATES = (
 13    ('AL', 'Alabama'),
 14    ('AZ', 'Arizona'),
 15    ('AR', 'Arkansas'),
 16    ('CA', 'California'),
 17    ('CO', 'Colorado'),
 18    ('CT', 'Connecticut'),
 19    ('DE', 'Delaware'),
 20    ('DC', 'District of Columbia'),
 21    ('FL', 'Florida'),
 22    ('GA', 'Georgia'),
 23    ('ID', 'Idaho'),
 24    ('IL', 'Illinois'),
 25    ('IN', 'Indiana'),
 26    ('IA', 'Iowa'),
 27    ('KS', 'Kansas'),
 28    ('KY', 'Kentucky'),
 29    ('LA', 'Louisiana'),
 30    ('ME', 'Maine'),
 31    ('MD', 'Maryland'),
 32    ('MA', 'Massachusetts'),
 33    ('MI', 'Michigan'),
 34    ('MN', 'Minnesota'),
 35    ('MS', 'Mississippi'),
 36    ('MO', 'Missouri'),
 37    ('MT', 'Montana'),
 38    ('NE', 'Nebraska'),
 39    ('NV', 'Nevada'),
 40    ('NH', 'New Hampshire'),
 41    ('NJ', 'New Jersey'),
 42    ('NM', 'New Mexico'),
 43    ('NY', 'New York'),
 44    ('NC', 'North Carolina'),
 45    ('ND', 'North Dakota'),
 46    ('OH', 'Ohio'),
 47    ('OK', 'Oklahoma'),
 48    ('OR', 'Oregon'),
 49    ('PA', 'Pennsylvania'),
 50    ('RI', 'Rhode Island'),
 51    ('SC', 'South Carolina'),
 52    ('SD', 'South Dakota'),
 53    ('TN', 'Tennessee'),
 54    ('TX', 'Texas'),
 55    ('UT', 'Utah'),
 56    ('VT', 'Vermont'),
 57    ('VA', 'Virginia'),
 58    ('WA', 'Washington'),
 59    ('WV', 'West Virginia'),
 60    ('WI', 'Wisconsin'),
 61    ('WY', 'Wyoming'),
 62)
 63
 64# All 50 states, plus the District of Columbia.
 65US_STATES = (
 66    ('AL', 'Alabama'),
 67    ('AK', 'Alaska'),
 68    ('AZ', 'Arizona'),
 69    ('AR', 'Arkansas'),
 70    ('CA', 'California'),
 71    ('CO', 'Colorado'),
 72    ('CT', 'Connecticut'),
 73    ('DE', 'Delaware'),
 74    ('DC', 'District of Columbia'),
 75    ('FL', 'Florida'),
 76    ('GA', 'Georgia'),
 77    ('HI', 'Hawaii'),
 78    ('ID', 'Idaho'),
 79    ('IL', 'Illinois'),
 80    ('IN', 'Indiana'),
 81    ('IA', 'Iowa'),
 82    ('KS', 'Kansas'),
 83    ('KY', 'Kentucky'),
 84    ('LA', 'Louisiana'),
 85    ('ME', 'Maine'),
 86    ('MD', 'Maryland'),
 87    ('MA', 'Massachusetts'),
 88    ('MI', 'Michigan'),
 89    ('MN', 'Minnesota'),
 90    ('MS', 'Mississippi'),
 91    ('MO', 'Missouri'),
 92    ('MT', 'Montana'),
 93    ('NE', 'Nebraska'),
 94    ('NV', 'Nevada'),
 95    ('NH', 'New Hampshire'),
 96    ('NJ', 'New Jersey'),
 97    ('NM', 'New Mexico'),
 98    ('NY', 'New York'),
 99    ('NC', 'North Carolina'),
100    ('ND', 'North Dakota'),
101    ('OH', 'Ohio'),
102    ('OK', 'Oklahoma'),
103    ('OR', 'Oregon'),
104    ('PA', 'Pennsylvania'),
105    ('RI', 'Rhode Island'),
106    ('SC', 'South Carolina'),
107    ('SD', 'South Dakota'),
108    ('TN', 'Tennessee'),
109    ('TX', 'Texas'),
110    ('UT', 'Utah'),
111    ('VT', 'Vermont'),
112    ('VA', 'Virginia'),
113    ('WA', 'Washington'),
114    ('WV', 'West Virginia'),
115    ('WI', 'Wisconsin'),
116    ('WY', 'Wyoming'),
117)
118
119# Non-state territories.
120US_TERRITORIES = (
121    ('AS', 'American Samoa'),
122    ('GU', 'Guam'),
123    ('MP', 'Northern Mariana Islands'),
124    ('PR', 'Puerto Rico'),
125    ('VI', 'Virgin Islands'),
126)
127
128# Military postal "states". Note that 'AE' actually encompasses
129# Europe, Canada, Africa and the Middle East.
130ARMED_FORCES_STATES = (
131    ('AA', 'Armed Forces Americas'),
132    ('AE', 'Armed Forces Europe'),
133    ('AP', 'Armed Forces Pacific'),
134)
135
136# Non-US locations serviced by USPS (under Compact of Free
137# Association).
138COFA_STATES = (
139    ('FM', 'Federated States of Micronesia'),
140    ('MH', 'Marshall Islands'),
141    ('PW', 'Palau'),
142)
143
144# Obsolete abbreviations (no longer US territories/USPS service, or
145# code changed).
146OBSOLETE_STATES = (
147    ('CM', 'Commonwealth of the Northern Mariana Islands'), # Is now 'MP'
148    ('CZ', 'Panama Canal Zone'),                            # Reverted to Panama 1979
149    ('PI', 'Philippine Islands'),                           # Philippine independence 1946
150    ('TT', 'Trust Territory of the Pacific Islands'),       # Became the independent COFA states + Northern Mariana Islands 1979-1994
151)
152
153
154# All US states and territories plus DC and military mail.
155STATE_CHOICES = tuple(sorted(US_STATES + US_TERRITORIES + ARMED_FORCES_STATES, key=lambda obj: obj[1]))
156
157# All US Postal Service locations.
158USPS_CHOICES = tuple(sorted(US_STATES + US_TERRITORIES + ARMED_FORCES_STATES + COFA_STATES, key=lambda obj: obj[1]))
159
160STATES_NORMALIZED = {
161    'ak': 'AK',
162    'al': 'AL',
163    'ala': 'AL',
164    'alabama': 'AL',
165    'alaska': 'AK',
166    'american samao': 'AS',
167    'american samoa': 'AS',
168    'ar': 'AR',
169    'ariz': 'AZ',
170    'arizona': 'AZ',
171    'ark': 'AR',
172    'arkansas': 'AR',
173    'as': 'AS',
174    'az': 'AZ',
175    'ca': 'CA',
176    'calf': 'CA',
177    'calif': 'CA',
178    'california': 'CA',
179    'co': 'CO',
180    'colo': 'CO',
181    'colorado': 'CO',
182    'conn': 'CT',
183    'connecticut': 'CT',
184    'ct': 'CT',
185    'dc': 'DC',
186    'de': 'DE',
187    'del': 'DE',
188    'delaware': 'DE',
189    'deleware': 'DE',
190    'district of columbia': 'DC',
191    'fl': 'FL',
192    'fla': 'FL',
193    'florida': 'FL',
194    'ga': 'GA',
195    'georgia': 'GA',
196    'gu': 'GU',
197    'guam': 'GU',
198    'hawaii': 'HI',
199    'hi': 'HI',
200    'ia': 'IA',
201    'id': 'ID',
202    'idaho': 'ID',
203    'il': 'IL',
204    'ill': 'IL',
205    'illinois': 'IL',
206    'in': 'IN',
207    'ind': 'IN',
208    'indiana': 'IN',
209    'iowa': 'IA',
210    'kan': 'KS',
211    'kans': 'KS',
212    'kansas': 'KS',
213    'kentucky': 'KY',
214    'ks': 'KS',
215    'ky': 'KY',
216    'la': 'LA',
217    'louisiana': 'LA',
218    'ma': 'MA',
219    'maine': 'ME',
220    'marianas islands': 'MP',
221    'marianas islands of the pacific': 'MP',
222    'marinas islands of the pacific': 'MP',
223    'maryland': 'MD',
224    'mass': 'MA',
225    'massachusetts': 'MA',
226    'massachussetts': 'MA',
227    'md': 'MD',
228    'me': 'ME',
229    'mi': 'MI',
230    'mich': 'MI',
231    'michigan': 'MI',
232    'minn': 'MN',
233    'minnesota': 'MN',
234    'miss': 'MS',
235    'mississippi': 'MS',
236    'missouri': 'MO',
237    'mn': 'MN',
238    'mo': 'MO',
239    'mont': 'MT',
240    'montana': 'MT',
241    'mp': 'MP',
242    'ms': 'MS',
243    'mt': 'MT',
244    'n d': 'ND',
245    'n dak': 'ND',
246    'n h': 'NH',
247    'n j': 'NJ',
248    'n m': 'NM',
249    'n mex': 'NM',
250    'nc': 'NC',
251    'nd': 'ND',
252    'ne': 'NE',
253    'neb': 'NE',
254    'nebr': 'NE',
255    'nebraska': 'NE',
256    'nev': 'NV',
257    'nevada': 'NV',
258    'new hampshire': 'NH',
259    'new jersey': 'NJ',
260    'new mexico': 'NM',
261    'new york': 'NY',
262    'nh': 'NH',
263    'nj': 'NJ',
264    'nm': 'NM',
265    'nmex': 'NM',
266    'north carolina': 'NC',
267    'north dakota': 'ND',
268    'northern mariana islands': 'MP',
269    'nv': 'NV',
270    'ny': 'NY',
271    'oh': 'OH',
272    'ohio': 'OH',
273    'ok': 'OK',
274    'okla': 'OK',
275    'oklahoma': 'OK',
276    'or': 'OR',
277    'ore': 'OR',
278    'oreg': 'OR',
279    'oregon': 'OR',
280    'pa': 'PA',
281    'penn': 'PA',
282    'pennsylvania': 'PA',
283    'pr': 'PR',
284    'puerto rico': 'PR',
285    'rhode island': 'RI',
286    'ri': 'RI',
287    's dak': 'SD',
288    'sc': 'SC',
289    'sd': 'SD',
290    'sdak': 'SD',
291    'south carolina': 'SC',
292    'south dakota': 'SD',
293    'tenn': 'TN',
294    'tennessee': 'TN',
295    'territory of hawaii': 'HI',
296    'tex': 'TX',
297    'texas': 'TX',
298    'tn': 'TN',
299    'tx': 'TX',
300    'us virgin islands': 'VI',
301    'usvi': 'VI',
302    'ut': 'UT',
303    'utah': 'UT',
304    'va': 'VA',
305    'vermont': 'VT',
306    'vi': 'VI',
307    'viginia': 'VA',
308    'virgin islands': 'VI',
309    'virgina': 'VA',
310    'virginia': 'VA',
311    'vt': 'VT',
312    'w va': 'WV',
313    'wa': 'WA',
314    'wash': 'WA',
315    'washington': 'WA',
316    'west virginia': 'WV',
317    'wi': 'WI',
318    'wis': 'WI',
319    'wisc': 'WI',
320    'wisconsin': 'WI',
321    'wv': 'WV',
322    'wva': 'WV',
323    'wy': 'WY',
324    'wyo': 'WY',
325    'wyoming': 'WY',
326}