|  | 
| 3 | 3 | 
 | 
| 4 | 4 | http://xml.coverpages.org/country3166.html | 
| 5 | 5 | 
 | 
| 6 |  | -A tuple of tuples of country codes and their full names. There are a few helper  | 
| 7 |  | -functions provided if you'd rather not use the dict directly. Examples provided  | 
|  | 6 | +A tuple of tuples of country codes and their full names. There are a few helper | 
|  | 7 | +functions provided if you'd rather not use the dict directly. Examples provided | 
| 8 | 8 | in the test_countries.py unit tests. | 
| 9 | 9 | """ | 
| 10 | 10 | 
 | 
| @@ -254,37 +254,37 @@ def is_valid_country_abbrev(abbrev, case_sensitive=False): | 
| 254 | 254 |     """ | 
| 255 | 255 |     Given a country code abbreviation, check to see if it matches the | 
| 256 | 256 |     country table. | 
| 257 |  | -     | 
|  | 257 | +
 | 
| 258 | 258 |     abbrev: (str) Country code to evaluate. | 
| 259 | 259 |     case_sensitive: (bool) When True, enforce case sensitivity. | 
| 260 |  | -     | 
|  | 260 | +
 | 
| 261 | 261 |     Returns True if valid, False if not. | 
| 262 | 262 |     """ | 
| 263 | 263 |     if case_sensitive: | 
| 264 | 264 |         country_code = abbrev | 
| 265 | 265 |     else: | 
| 266 | 266 |         country_code = abbrev.upper() | 
| 267 |  | -         | 
|  | 267 | + | 
| 268 | 268 |     for code, full_name in COUNTRY_TUPLES: | 
| 269 | 269 |         if country_code == code: | 
| 270 | 270 |             return True | 
| 271 |  | -         | 
|  | 271 | + | 
| 272 | 272 |     return False | 
| 273 | 273 | 
 | 
| 274 | 274 | def get_name_from_abbrev(abbrev, case_sensitive=False): | 
| 275 | 275 |     """ | 
| 276 | 276 |     Given a country code abbreviation, get the full name from the table. | 
| 277 |  | -     | 
|  | 277 | +
 | 
| 278 | 278 |     abbrev: (str) Country code to retrieve the full name of. | 
| 279 | 279 |     case_sensitive: (bool) When True, enforce case sensitivity. | 
| 280 | 280 |     """ | 
| 281 | 281 |     if case_sensitive: | 
| 282 | 282 |         country_code = abbrev | 
| 283 | 283 |     else: | 
| 284 | 284 |         country_code = abbrev.upper() | 
| 285 |  | -         | 
|  | 285 | + | 
| 286 | 286 |     for code, full_name in COUNTRY_TUPLES: | 
| 287 | 287 |         if country_code == code: | 
| 288 | 288 |             return full_name | 
| 289 |  | -         | 
|  | 289 | + | 
| 290 | 290 |     raise KeyError('No country with that country code.') | 
0 commit comments