summaryrefslogtreecommitdiffstats
path: root/Lib/pkgutil.py
diff options
context:
space:
mode:
authorVinay Sajip <vinay_sajip@yahoo.co.uk>2020-02-28 14:26:27 (GMT)
committerGitHub <noreply@github.com>2020-02-28 14:26:27 (GMT)
commit4f17c5cd9a1ec50fe8de7ef68c39220a01a862cb (patch)
tree627e549365ac1eadeae19e013ec5c218898c0b6a /Lib/pkgutil.py
parente263bb1e97ae8f84fb4f2ab5b0c4f529a2e5696d (diff)
downloadcpython-4f17c5cd9a1ec50fe8de7ef68c39220a01a862cb.zip
cpython-4f17c5cd9a1ec50fe8de7ef68c39220a01a862cb.tar.gz
cpython-4f17c5cd9a1ec50fe8de7ef68c39220a01a862cb.tar.bz2
bpo-12915: Improve Unicode support for package names and attributes. (GH-18517)
Diffstat (limited to 'Lib/pkgutil.py')
-rw-r--r--Lib/pkgutil.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/Lib/pkgutil.py b/Lib/pkgutil.py
index 4bc3083..4c18467 100644
--- a/Lib/pkgutil.py
+++ b/Lib/pkgutil.py
@@ -638,8 +638,8 @@ def get_data(package, resource):
return loader.get_data(resource_name)
-_DOTTED_WORDS = r'[a-z_]\w*(\.[a-z_]\w*)*'
-_NAME_PATTERN = re.compile(f'^({_DOTTED_WORDS})(:({_DOTTED_WORDS})?)?$', re.I)
+_DOTTED_WORDS = r'(?!\d)(\w+)(\.(?!\d)(\w+))*'
+_NAME_PATTERN = re.compile(f'^(?P<pkg>{_DOTTED_WORDS})(?P<cln>:(?P<obj>{_DOTTED_WORDS})?)?$', re.U)
del _DOTTED_WORDS
def resolve_name(name):
@@ -677,11 +677,12 @@ def resolve_name(name):
m = _NAME_PATTERN.match(name)
if not m:
raise ValueError(f'invalid format: {name!r}')
- groups = m.groups()
- if groups[2]:
+ gd = m.groupdict()
+ if gd.get('cln'):
# there is a colon - a one-step import is all that's needed
- mod = importlib.import_module(groups[0])
- parts = groups[3].split('.') if groups[3] else []
+ mod = importlib.import_module(gd['pkg'])
+ parts = gd.get('obj')
+ parts = parts.split('.') if parts else []
else:
# no colon - have to iterate to find the package boundary
parts = name.split('.')