-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
67 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (c) 2023 the BabelFish authors. All rights reserved. | ||
# Use of this source code is governed by the 3-clause BSD license | ||
# that can be found in the LICENSE file. | ||
# | ||
from __future__ import unicode_literals | ||
from . import CountryReverseConverter, CaseInsensitiveDict | ||
from ..country import DEMONYMS | ||
from ..exceptions import CountryConvertError, CountryReverseError | ||
|
||
|
||
class CountryDemonymConverter(CountryReverseConverter): | ||
def __init__(self): | ||
self.to_demonym = {} | ||
self.from_demonym = CaseInsensitiveDict() | ||
for alpha2, demonym in DEMONYMS.items(): | ||
self.to_demonym[alpha2] = demonym | ||
self.from_demonym[demonym] = alpha2 | ||
|
||
def convert(self, alpha2): | ||
if alpha2 not in self.to_demonym: | ||
raise CountryConvertError(alpha2) | ||
return self.to_demonym[alpha2] | ||
|
||
def reverse(self, demonym): | ||
if demonym not in self.from_demonym: | ||
raise CountryReverseError(demonym) | ||
return self.from_demonym[demonym] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
BR=Brazilian | ||
CH=Swiss | ||
FR=French | ||
US=American | ||
GB=British |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters