Submit
Path:
~
/
/
var
/
opt
/
nydus
/
ops
/
File Content:
pkgutil_resolve_name.py
""" Resolve a name to an object. It is expected that `name` will be a string in one of the following formats, where W is shorthand for a valid Python identifier and dot stands for a literal period in these pseudo-regexes: W(.W)* W(.W)*:(W(.W)*)? The first form is intended for backward compatibility only. It assumes that some part of the dotted name is a package, and the rest is an object somewhere within that package, possibly nested inside other objects. Because the place where the package stops and the object hierarchy starts can't be inferred by inspection, repeated attempts to import must be done with this form. In the second form, the caller makes the division point clear through the provision of a single colon: the dotted name to the left of the colon is a package to be imported, and the dotted name to the right is the object hierarchy within that package. Only one import is needed in this form. If it ends with the colon, then a module object is returned. The function will return an object (which might be a module), or raise one of the following exceptions: ValueError - if `name` isn't in a recognised format ImportError - if an import failed when it shouldn't have AttributeError - if a failure occurred when traversing the object hierarchy within the imported package to get to the desired object) """ import importlib import re __version__ = "1.3.10" _NAME_PATTERN = None def resolve_name(name): """ Resolve a name to an object. It is expected that `name` will be a string in one of the following formats, where W is shorthand for a valid Python identifier and dot stands for a literal period in these pseudo-regexes: W(.W)* W(.W)*:(W(.W)*)? The first form is intended for backward compatibility only. It assumes that some part of the dotted name is a package, and the rest is an object somewhere within that package, possibly nested inside other objects. Because the place where the package stops and the object hierarchy starts can't be inferred by inspection, repeated attempts to import must be done with this form. In the second form, the caller makes the division point clear through the provision of a single colon: the dotted name to the left of the colon is a package to be imported, and the dotted name to the right is the object hierarchy within that package. Only one import is needed in this form. If it ends with the colon, then a module object is returned. The function will return an object (which might be a module), or raise one of the following exceptions: ValueError - if `name` isn't in a recognised format ImportError - if an import failed when it shouldn't have AttributeError - if a failure occurred when traversing the object hierarchy within the imported package to get to the desired object) """ global _NAME_PATTERN if _NAME_PATTERN is None: # Lazy import to speedup Python startup time import re dotted_words = r'(?!\d)(\w+)(\.(?!\d)(\w+))*' _NAME_PATTERN = re.compile(f'^(?P<pkg>{dotted_words})' f'(?P<cln>:(?P<obj>{dotted_words})?)?$', re.UNICODE) m = _NAME_PATTERN.match(name) if not m: raise ValueError(f'invalid format: {name!r}') gd = m.groupdict() if gd.get('cln'): # there is a colon - a one-step import is all that's needed 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('.') modname = parts.pop(0) # first part *must* be a module/package. mod = importlib.import_module(modname) while parts: p = parts[0] s = f'{modname}.{p}' try: mod = importlib.import_module(s) parts.pop(0) modname = s except ImportError: break # if we reach this point, mod is the module, already imported, and # parts is the list of parts in the object hierarchy to be traversed, or # an empty list if just the module is wanted. result = mod for p in parts: result = getattr(result, p) return result
Submit
FILE
FOLDER
Name
Size
Permission
Action
PyYAML-5.4.1.dist-info
---
0755
__pycache__
---
0755
_yaml
---
0755
asn1crypto
---
0755
asn1crypto-1.5.1.dist-info
---
0755
attr
---
0755
attrs
---
0755
attrs-24.2.0.dist-info
---
0755
bin
---
0755
cffi
---
0755
cffi-1.16.0.dist-info
---
0755
cffi-1.17.1.dist-info
---
0755
cryptography
---
0755
cryptography-37.0.4.dist-info
---
0755
cryptography-39.0.2.dist-info
---
0755
customer_local_ops
---
0755
customer_local_ops-20.0.2.dist-info
---
0755
customer_local_ops-3.62.0.dist-info
---
0755
customer_local_ops-6.4.1.dist-info
---
0755
customer_local_ops-7.2.0.dist-info
---
0755
google
---
0755
importlib_resources
---
0755
importlib_resources-1.5.0.dist-info
---
0755
importlib_resources-5.13.0.dist-info
---
0755
jsonschema
---
0755
jsonschema-4.23.0.dist-info
---
0755
jsonschema_specifications
---
0755
jsonschema_specifications-2023.12.1.dist-info
---
0755
mysql
---
0755
mysql_connector_python-8.0.14.dist-info
---
0755
mysql_connector_python-8.4.0.dist-info
---
0755
mysqlx
---
0755
oscrypto
---
0755
oscrypto-1.3.0.1.dist-info
---
0755
pkgutil_resolve_name-1.3.10.dist-info
---
0755
primordial
---
0755
primordial-3.6.0.dist-info
---
0755
protobuf-4.21.12.dist-info
---
0755
pycparser
---
0755
pycparser-2.22.dist-info
---
0755
pycparser-2.23.dist-info
---
0755
referencing
---
0755
referencing-0.35.1.dist-info
---
0755
rpds
---
0755
rpds_py-0.20.0.dist-info
---
0755
shortuuid
---
0755
shortuuid-1.0.13.dist-info
---
0755
yaml
---
0755
zipp
---
0755
zipp-3.18.2.dist-info
---
0755
zipp-3.20.2.dist-info
---
0755
COPYING
1484 bytes
0644
_cffi_backend.cpython-38-x86_64-linux-gnu.so
998968 bytes
0755
pkgutil_resolve_name.py
4391 bytes
0644
N4ST4R_ID | Naxtarrr