lists.arthurdejong.org
RSS feed

python-stdnum branch master updated. 1.18-36-g7761e42

[Date Prev][Date Next] [Thread Prev][Thread Next]

python-stdnum branch master updated. 1.18-36-g7761e42



This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "python-stdnum".

The branch, master has been updated
       via  7761e42764b4730335943b7b43779446ad459db4 (commit)
      from  f6edcc55927134344809005569d1416c86ab1909 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://arthurdejong.org/git/python-stdnum/commit/?id=7761e42764b4730335943b7b43779446ad459db4

commit 7761e42764b4730335943b7b43779446ad459db4
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Sun Aug 20 14:43:57 2023 +0200

    Use importlib.resource in place of deprecated pkg_resources
    
    Closes https://github.com/arthurdejong/python-stdnum/issues/412
    Closes https://github.com/arthurdejong/python-stdnum/pull/413

diff --git a/stdnum/numdb.py b/stdnum/numdb.py
index 8d4f286..c9c7283 100644
--- a/stdnum/numdb.py
+++ b/stdnum/numdb.py
@@ -1,6 +1,6 @@
 # numdb.py - module for handling hierarchically organised numbers
 #
-# Copyright (C) 2010-2021 Arthur de Jong
+# Copyright (C) 2010-2023 Arthur de Jong
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -61,8 +61,6 @@ To split the number and get properties for each part:
 
 import re
 
-from pkg_resources import resource_stream
-
 
 _line_re = re.compile(
     r'^(?P<indent> *)'
@@ -160,11 +158,21 @@ def read(fp):
     return db
 
 
+def _get_resource_stream(name):
+    """Return a readable file-like object for the resource."""
+    try:  # pragma: no cover (Python 3.9 and newer)
+        import importlib.resources
+        return importlib.resources.files(__package__).joinpath(name).open('rb')
+    except (ImportError, AttributeError):  # pragma: no cover (older Python 
versions)
+        import pkg_resources
+        return pkg_resources.resource_stream(__name__, name)
+
+
 def get(name):
     """Open a database with the specified name to perform queries on."""
     if name not in _open_databases:
         import codecs
         reader = codecs.getreader('utf-8')
-        with reader(resource_stream(__name__, name + '.dat')) as fp:
+        with reader(_get_resource_stream(name + '.dat')) as fp:
             _open_databases[name] = read(fp)
     return _open_databases[name]

-----------------------------------------------------------------------

Summary of changes:
 stdnum/numdb.py | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)


hooks/post-receive
-- 
python-stdnum