"pkgutil" --- パッケージ拡張ユーティリティ
******************************************

**ソースコード:** Lib/pkgutil.py

======================================================================

このモジュールはインポートシステムの、特にパッケージサポートに関するユ
ーティリティです。

class pkgutil.ModuleInfo(module_finder, name, ispkg)

   モジュールの概要情報を格納する namedtuple

   Added in version 3.6.

pkgutil.extend_path(path, name)

   パッケージを構成するモジュールの検索パスを拡張します。パッケージの
   "__init__.py" で次のように書くことを意図したものです:

      from pkgutil import extend_path
      __path__ = extend_path(__path__, __name__)

   For each directory on "sys.path" that has a subdirectory that
   matches the package name, add the subdirectory to the package's
   "__path__". This is useful if one wants to distribute different
   parts of a single logical package as multiple directories.

   It also looks for "*.pkg" files beginning where "*" matches the
   *name* argument.  This feature is similar to "*.pth" files (see the
   "site" module for more information), except that it doesn't
   special-case lines starting with "import".  A "*.pkg" file is
   trusted at face value: apart from skipping blank lines and ignoring
   comments, all entries found in a "*.pkg" file are added to the
   path, regardless of whether they exist on the filesystem (this is a
   feature).

   入力パスがリストでない場合(フリーズされたパッケージのとき)は何もせ
   ずにリターンします。入力パスが変更されていなければ、アイテムを末尾
   に追加しただけのコピーを返します。

   "sys.path" はシーケンスであることが前提になっています。 "sys.path"
   の要素の内、実在するディレクトリを指す文字列となっていないものは無
   視されます。ファイル名として使ったときにエラーが発生する "sys.path"
   の Unicode要素がある場合、この関数("os.path.isdir()" を実行している
   行) で例外が発生する可能性があります。

pkgutil.get_importer(path_item)

   指定された *path_item* に対する *finder* を取得します。

   path hook により新しい finder が作成された場合は、それは
   "sys.path_importer_cache" にキャッシュされます。

   キャッシュ (やその一部) は、 "sys.path_hooks" のリスキャンが必要に
   なった場合は手動でクリアすることができます。

   バージョン 3.3 で変更: パッケージ内部の **PEP 302** エミュレーショ
   ンに依存するのではなく直接的に "importlib" に基くように更新されまし
   た。

pkgutil.iter_importers(fullname='')

   Yield *finder* objects for the given module name.

   If *fullname* contains a "'.'", the finders will be for the package
   containing *fullname*, otherwise they will be all registered top
   level finders (i.e. those on both "sys.meta_path" and
   "sys.path_hooks").

   その名前のついたモジュールがパッケージ内に含まれている場合、この関
   数を実行した副作用としてそのパッケージが import されます。

   モジュール名が指定されない場合は全てのトップレベルの finder が生成
   されます。

   バージョン 3.3 で変更: パッケージ内部の **PEP 302** エミュレーショ
   ンに依存するのではなく直接的に "importlib" に基くように更新されまし
   た。

pkgutil.iter_modules(path=None, prefix='')

   *path* を指定すればそのすべてのサブモジュールに対して、 *path* が
   "None" なら "sys.path" のすべてのトップレベルモジュールに対して、
   "ModuleInfo" を yield します。

   *path* は "None" か、モジュールを検索する path のリストのどちらかで
   なければなりません。

   *prefix* は出力の全てのモジュール名の頭に出力する文字列です。

   注釈:

     これは "iter_modules()" メソッドを定義している *finder* に対して
     のみ動作します。このインターフェイスは非標準なので、モジュールは
     "importlib.machinery.FileFinder" と "zipimport.zipimporter" の実
     装も提供します。

   バージョン 3.3 で変更: パッケージ内部の **PEP 302** エミュレーショ
   ンに依存するのではなく直接的に "importlib" に基くように更新されまし
   た。

pkgutil.walk_packages(path=None, prefix='', onerror=None)

   *path* を指定すれば再帰的にその中のモジュールすべてに対して、
   *path* が "None" ならばアクセスできるすべてのモジュールに対して、
   "ModuleInfo" を yield します。

   *path* は "None" か、モジュールを検索する path のリストのどちらかで
   なければなりません。

   *prefix* は出力の全てのモジュール名の頭に出力する文字列です。

   この関数は与えられた *path* 上の全ての *パッケージ* (全てのモジュー
   ル *ではない*) を、サブモジュールを検索するのに必要な "__path__" 属
   性にアクセスするために import します。

   *onerror* は、パッケージを import しようとしたときに何かの例外が発
   生した場合に、 1つの引数 (import しようとしていたパッケージの名前)
   で呼び出される関数です。 *onerror* 関数が提供されない場合、
   "ImportError" は補足され無視されます。それ以外の全ての例外は伝播し
   、検索を停止させます。

   例:

      # list all modules python can access
      walk_packages()

      # list all submodules of ctypes
      walk_packages(ctypes.__path__, ctypes.__name__ + '.')

   注釈:

     これは "iter_modules()" メソッドを定義している *finder* に対して
     のみ動作します。このインターフェイスは非標準なので、モジュールは
     "importlib.machinery.FileFinder" と "zipimport.zipimporter" の実
     装も提供します。

   バージョン 3.3 で変更: パッケージ内部の **PEP 302** エミュレーショ
   ンに依存するのではなく直接的に "importlib" に基くように更新されまし
   た。

pkgutil.get_data(package, resource)

   パッケージからリソースを取得します。

   This is a wrapper for the *loader* "get_data" API.  The *package*
   argument should be the name of a package, in standard module format
   ("foo.bar").  The *resource* argument should be in the form of a
   relative filename, using "/" as the path separator.

   この関数が返すのは指定されたリソースの内容であるバイナリ文字列です
   。

   This function uses the *loader* method "get_data()" to support
   modules installed in the filesystem, but also in zip files,
   databases, or elsewhere.

   ファイルシステム中に位置するパッケージで既にインポートされているも
   のに対しては、次と大体同じです:

      d = os.path.dirname(sys.modules[package].__file__)
      data = open(os.path.join(d, resource), 'rb').read()

   Like the "open()" function, "get_data()" can follow parent
   directories ("../") and absolute paths (starting with "/" or "C:/",
   for example). It can open compilation/installation artifacts like
   ".py" and ".pyc" files or files with "reserved filenames". To be
   compatible with non-filesystem loaders, avoid using these features.

   警告:

     This function is intended for trusted input. It does not verify
     that *resource* "belongs" to *package*.

   If you use a user-provided *resource* path, consider verifying it.
   For example, require an alphanumeric filename with a known
   extension, or install and check a list of known resources.

   If the package cannot be located or loaded, or it uses a *loader*
   which does not support "get_data", then "None" is returned.  In
   particular, the *loader* for *namespace packages* does not support
   "get_data".

   参考:

     The "importlib.resources" module provides structured access to
     module resources.

pkgutil.resolve_name(name, *, strict=False)

   Resolve a name to an object.

   This functionality is used in numerous places in the standard
   library (see bpo-12915) - and equivalent functionality is also in
   widely used third-party packages such as setuptools, Django and
   Pyramid.

   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)*)?"

   * "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 first two forms are accepted when "strict=False" (the default).

   The third form requires both the module name and callable,
   separated by a colon. Only this form is accepted when
   "strict=True".

   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.

   Added in version 3.9.

   バージョン 3.15 で変更: The optional keyword-only "strict" flag was
   added.
