Skip to content

Commit bbd4ee9

Browse files
committed
Generated prefix data __init__.py files
Now with explicit .db suffix and atexit closer
1 parent 3a79159 commit bbd4ee9

6 files changed

Lines changed: 18 additions & 6 deletions

File tree

python/phonenumbers/carrierdata/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import atexit
1516
import os
1617
import shelve
1718
from ..util import u
1819

1920
_DIR, _ = os.path.split(__file__)
2021
CARRIER_LONGEST_PREFIX = 9
21-
CARRIER_DATA = shelve.open(os.path.join(_DIR, "carrierdata"), "r")
22+
CARRIER_DATA = shelve.open(os.path.join(_DIR, "carrierdata.db"), "r")
23+
atexit.register(lambda: CARRIER_DATA.close())

python/phonenumbers/geodata/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import atexit
1516
import os
1617
import shelve
1718
from ..util import u
1819

1920
_DIR, _ = os.path.split(__file__)
2021
GEOCODE_LONGEST_PREFIX = 9
21-
GEOCODE_DATA = shelve.open(os.path.join(_DIR, "geodata"), "r")
22+
GEOCODE_DATA = shelve.open(os.path.join(_DIR, "geodata.db"), "r")
23+
atexit.register(lambda: GEOCODE_DATA.close())

python/phonenumbers/tzdata/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import atexit
1516
import os
1617
import shelve
1718
from ..util import u
1819

1920
_DIR, _ = os.path.split(__file__)
2021
TIMEZONE_LONGEST_PREFIX = 7
21-
TIMEZONE_DATA = shelve.open(os.path.join(_DIR, "tzdata"), "r")
22+
TIMEZONE_DATA = shelve.open(os.path.join(_DIR, "tzdata.db"), "r")
23+
atexit.register(lambda: TIMEZONE_DATA.close())

python/tests/testcarrierdata/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import atexit
1516
import os
1617
import shelve
1718
from phonenumbers.util import u
1819

1920
_DIR, _ = os.path.split(__file__)
2021
CARRIER_LONGEST_PREFIX = 7
21-
CARRIER_DATA = shelve.open(os.path.join(_DIR, "carrierdata"), "r")
22+
CARRIER_DATA = shelve.open(os.path.join(_DIR, "carrierdata.db"), "r")
23+
atexit.register(lambda: CARRIER_DATA.close())

python/tests/testgeodata/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import atexit
1516
import os
1617
import shelve
1718
from phonenumbers.util import u
1819

1920
_DIR, _ = os.path.split(__file__)
2021
GEOCODE_LONGEST_PREFIX = 7
21-
GEOCODE_DATA = shelve.open(os.path.join(_DIR, "geodata"), "r")
22+
GEOCODE_DATA = shelve.open(os.path.join(_DIR, "geodata.db"), "r")
23+
atexit.register(lambda: GEOCODE_DATA.close())

python/tests/testtzdata/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import atexit
1516
import os
1617
import shelve
1718
from phonenumbers.util import u
1819

1920
_DIR, _ = os.path.split(__file__)
2021
TIMEZONE_LONGEST_PREFIX = 7
21-
TIMEZONE_DATA = shelve.open(os.path.join(_DIR, "tzdata"), "r")
22+
TIMEZONE_DATA = shelve.open(os.path.join(_DIR, "tzdata.db"), "r")
23+
atexit.register(lambda: TIMEZONE_DATA.close())

0 commit comments

Comments
 (0)