File manager - Edit - /home/newsbmcs.com/public_html/static/img/logo/metadata.tar
Back
__pycache__/gapic_metadata_pb2.cpython-310.pyc 0000644 00000005030 15030146047 0015141 0 ustar 00 o �h � @ s8 d Z ddlmZ ddlmZ ddlmZ ddlm Z e�� Ze�� � d�Ze� Ze �ee� e �ede� ejdkr�d e_d e_d e_de_d e_de_d e_de_ded _ded _ded _ded _ded _ded _ded _ded _ded _ded _ded _ded _ded _ded _d S d S )zGenerated protocol buffer code.� )� descriptor)�descriptor_pool)�symbol_database)�builders� *google/gapic/metadata/gapic_metadata.protogoogle.gapic.metadata"� GapicMetadata schema ( comment ( language ( proto_package ( library_package ( D services (22.google.gapic.metadata.GapicMetadata.ServicesEntryi ServicesEntry key ( G value (28.google.gapic.metadata.GapicMetadata.ServiceForTransport:8� ServiceForTransportV clients (2E.google.gapic.metadata.GapicMetadata.ServiceForTransport.ClientsEntryd ClientsEntry key ( C value (24.google.gapic.metadata.GapicMetadata.ServiceAsClient:8� ServiceAsClient library_client ( L rpcs (2>.google.gapic.metadata.GapicMetadata.ServiceAsClient.RpcsEntry\ RpcsEntry key ( > value (2/.google.gapic.metadata.GapicMetadata.MethodList:8 MethodList methods ( B� com.google.gapic.metadataBGapicMetadataProtoPZ=google.golang.org/genproto/googleapis/gapic/metadata;metadata�Google.Gapic.Metadata�Google\Gapic\Metadata�Google::Gapic::Metadatabproto3z(google.gapic.metadata.gapic_metadata_pb2FNs� com.google.gapic.metadataBGapicMetadataProtoPZ=google.golang.org/genproto/googleapis/gapic/metadata;metadata�Google.Gapic.Metadata�Google\Gapic\Metadata�Google::Gapic::Metadatas 8�F �_GAPICMETADATAi6 � �_GAPICMETADATA_SERVICESENTRYii il �"_GAPICMETADATA_SERVICEFORTRANSPORTi? i� �/_GAPICMETADATA_SERVICEFORTRANSPORT_CLIENTSENTRYiB �_GAPICMETADATA_SERVICEASCLIENTi i� �(_GAPICMETADATA_SERVICEASCLIENT_RPCSENTRYi �_GAPICMETADATA_METHODLIST)�__doc__�google.protobufr �_descriptorr �_descriptor_poolr �_symbol_database�google.protobuf.internalr �_builder�Default�_sym_db�AddSerializedFile� DESCRIPTOR�globals�_globals�BuildMessageAndEnumDescriptors�BuildTopDescriptorsAndMessages�_USE_C_DESCRIPTORS�_options�_serialized_optionsr r r �_serialized_start�_serialized_end� r# r# �^/usr/local/CyberPanel/lib/python3.10/site-packages/google/gapic/metadata/gapic_metadata_pb2.py�<module> sL �� � gapic_metadata_pb2.py 0000644 00000011031 15030146047 0010600 0 ustar 00 # -*- coding: utf-8 -*- # Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # Generated by the protocol buffer compiler. DO NOT EDIT! # source: google/gapic/metadata/gapic_metadata.proto """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool from google.protobuf import symbol_database as _symbol_database from google.protobuf.internal import builder as _builder # @@protoc_insertion_point(imports) _sym_db = _symbol_database.Default() DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile( b'\n*google/gapic/metadata/gapic_metadata.proto\x12\x15google.gapic.metadata"\xf0\x05\n\rGapicMetadata\x12\x0e\n\x06schema\x18\x01 \x01(\t\x12\x0f\n\x07\x63omment\x18\x02 \x01(\t\x12\x10\n\x08language\x18\x03 \x01(\t\x12\x15\n\rproto_package\x18\x04 \x01(\t\x12\x17\n\x0flibrary_package\x18\x05 \x01(\t\x12\x44\n\x08services\x18\x06 \x03(\x0b\x32\x32.google.gapic.metadata.GapicMetadata.ServicesEntry\x1ai\n\rServicesEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12G\n\x05value\x18\x02 \x01(\x0b\x32\x38.google.gapic.metadata.GapicMetadata.ServiceForTransport:\x02\x38\x01\x1a\xd3\x01\n\x13ServiceForTransport\x12V\n\x07\x63lients\x18\x01 \x03(\x0b\x32\x45.google.gapic.metadata.GapicMetadata.ServiceForTransport.ClientsEntry\x1a\x64\n\x0c\x43lientsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\x43\n\x05value\x18\x02 \x01(\x0b\x32\x34.google.gapic.metadata.GapicMetadata.ServiceAsClient:\x02\x38\x01\x1a\xd5\x01\n\x0fServiceAsClient\x12\x16\n\x0elibrary_client\x18\x01 \x01(\t\x12L\n\x04rpcs\x18\x02 \x03(\x0b\x32>.google.gapic.metadata.GapicMetadata.ServiceAsClient.RpcsEntry\x1a\\\n\tRpcsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12>\n\x05value\x18\x02 \x01(\x0b\x32/.google.gapic.metadata.GapicMetadata.MethodList:\x02\x38\x01\x1a\x1d\n\nMethodList\x12\x0f\n\x07methods\x18\x01 \x03(\tB\xba\x01\n\x19\x63om.google.gapic.metadataB\x12GapicMetadataProtoP\x01Z=google.golang.org/genproto/googleapis/gapic/metadata;metadata\xaa\x02\x15Google.Gapic.Metadata\xca\x02\x15Google\\Gapic\\Metadata\xea\x02\x17Google::Gapic::Metadatab\x06proto3' ) _globals = globals() _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) _builder.BuildTopDescriptorsAndMessages( DESCRIPTOR, "google.gapic.metadata.gapic_metadata_pb2", _globals ) if _descriptor._USE_C_DESCRIPTORS == False: DESCRIPTOR._options = None DESCRIPTOR._serialized_options = b"\n\031com.google.gapic.metadataB\022GapicMetadataProtoP\001Z=google.golang.org/genproto/googleapis/gapic/metadata;metadata\252\002\025Google.Gapic.Metadata\312\002\025Google\\Gapic\\Metadata\352\002\027Google::Gapic::Metadata" _GAPICMETADATA_SERVICESENTRY._options = None _GAPICMETADATA_SERVICESENTRY._serialized_options = b"8\001" _GAPICMETADATA_SERVICEFORTRANSPORT_CLIENTSENTRY._options = None _GAPICMETADATA_SERVICEFORTRANSPORT_CLIENTSENTRY._serialized_options = b"8\001" _GAPICMETADATA_SERVICEASCLIENT_RPCSENTRY._options = None _GAPICMETADATA_SERVICEASCLIENT_RPCSENTRY._serialized_options = b"8\001" _globals["_GAPICMETADATA"]._serialized_start = 70 _globals["_GAPICMETADATA"]._serialized_end = 822 _globals["_GAPICMETADATA_SERVICESENTRY"]._serialized_start = 256 _globals["_GAPICMETADATA_SERVICESENTRY"]._serialized_end = 361 _globals["_GAPICMETADATA_SERVICEFORTRANSPORT"]._serialized_start = 364 _globals["_GAPICMETADATA_SERVICEFORTRANSPORT"]._serialized_end = 575 _globals["_GAPICMETADATA_SERVICEFORTRANSPORT_CLIENTSENTRY"]._serialized_start = 475 _globals["_GAPICMETADATA_SERVICEFORTRANSPORT_CLIENTSENTRY"]._serialized_end = 575 _globals["_GAPICMETADATA_SERVICEASCLIENT"]._serialized_start = 578 _globals["_GAPICMETADATA_SERVICEASCLIENT"]._serialized_end = 791 _globals["_GAPICMETADATA_SERVICEASCLIENT_RPCSENTRY"]._serialized_start = 699 _globals["_GAPICMETADATA_SERVICEASCLIENT_RPCSENTRY"]._serialized_end = 791 _globals["_GAPICMETADATA_METHODLIST"]._serialized_start = 793 _globals["_GAPICMETADATA_METHODLIST"]._serialized_end = 822 # @@protoc_insertion_point(module_scope) gapic_metadata.proto 0000644 00000006501 15030146047 0010556 0 ustar 00 // Copyright 2020 Google LLC. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // syntax = "proto3"; package google.gapic.metadata; option csharp_namespace = "Google.Gapic.Metadata"; option go_package = "google.golang.org/genproto/googleapis/gapic/metadata;metadata"; option java_multiple_files = true; option java_outer_classname = "GapicMetadataProto"; option java_package = "com.google.gapic.metadata"; option php_namespace = "Google\\Gapic\\Metadata"; option ruby_package = "Google::Gapic::Metadata"; // Metadata about a GAPIC library for a specific combination of API, version, // and computer language. message GapicMetadata { // Schema version of this proto. Current value: 1.0 string schema = 1; // Any human-readable comments to be included in this file. string comment = 2; // Computer language of this generated language. This must be // spelled out as it spoken in English, with no capitalization or // separators (e.g. "csharp", "nodejs"). string language = 3; // The proto package containing the API definition for which this // GAPIC library was generated. string proto_package = 4; // The language-specific library package for this GAPIC library. string library_package = 5; // A map from each proto-defined service to ServiceForTransports, // which allows listing information about transport-specific // implementations of the service. // // The key is the name of the service as it appears in the .proto // file. map<string, ServiceForTransport> services = 6; // A map from a transport name to ServiceAsClient, which allows // listing information about the client objects that implement the // parent RPC service for the specified transport. // // The key name is the transport, lower-cased with no separators // (e.g. "grpc", "rest"). message ServiceForTransport { map<string, ServiceAsClient> clients = 1; } // Information about a specific client implementing a proto-defined service. message ServiceAsClient { // The name of the library client formatted as it appears in the source code string library_client = 1; // A mapping from each proto-defined RPC name to the the list of // methods in library_client that implement it. There can be more // than one library_client method for each RPC. RPCs with no // library_client methods need not be included. // // The key name is the name of the RPC as defined and formatted in // the proto file. map<string, MethodList> rpcs = 2; } // List of GAPIC client methods implementing the proto-defined RPC // for the transport and service specified in the containing // structures. message MethodList { // List of methods for a specific proto-service client in the // GAPIC. These names should be formatted as they appear in the // source code. repeated string methods = 1; } } base.py 0000644 00000061322 15030255725 0006040 0 ustar 00 import csv import email.message import functools import json import logging import pathlib import re import zipfile from typing import ( IO, Any, Collection, Container, Dict, Iterable, Iterator, List, NamedTuple, Optional, Protocol, Tuple, Union, ) from pip._vendor.packaging.requirements import Requirement from pip._vendor.packaging.specifiers import InvalidSpecifier, SpecifierSet from pip._vendor.packaging.utils import NormalizedName, canonicalize_name from pip._vendor.packaging.version import Version from pip._internal.exceptions import NoneMetadataError from pip._internal.locations import site_packages, user_site from pip._internal.models.direct_url import ( DIRECT_URL_METADATA_NAME, DirectUrl, DirectUrlValidationError, ) from pip._internal.utils.compat import stdlib_pkgs # TODO: Move definition here. from pip._internal.utils.egg_link import egg_link_path_from_sys_path from pip._internal.utils.misc import is_local, normalize_path from pip._internal.utils.urls import url_to_path from ._json import msg_to_json InfoPath = Union[str, pathlib.PurePath] logger = logging.getLogger(__name__) class BaseEntryPoint(Protocol): @property def name(self) -> str: raise NotImplementedError() @property def value(self) -> str: raise NotImplementedError() @property def group(self) -> str: raise NotImplementedError() def _convert_installed_files_path( entry: Tuple[str, ...], info: Tuple[str, ...], ) -> str: """Convert a legacy installed-files.txt path into modern RECORD path. The legacy format stores paths relative to the info directory, while the modern format stores paths relative to the package root, e.g. the site-packages directory. :param entry: Path parts of the installed-files.txt entry. :param info: Path parts of the egg-info directory relative to package root. :returns: The converted entry. For best compatibility with symlinks, this does not use ``abspath()`` or ``Path.resolve()``, but tries to work with path parts: 1. While ``entry`` starts with ``..``, remove the equal amounts of parts from ``info``; if ``info`` is empty, start appending ``..`` instead. 2. Join the two directly. """ while entry and entry[0] == "..": if not info or info[-1] == "..": info += ("..",) else: info = info[:-1] entry = entry[1:] return str(pathlib.Path(*info, *entry)) class RequiresEntry(NamedTuple): requirement: str extra: str marker: str class BaseDistribution(Protocol): @classmethod def from_directory(cls, directory: str) -> "BaseDistribution": """Load the distribution from a metadata directory. :param directory: Path to a metadata directory, e.g. ``.dist-info``. """ raise NotImplementedError() @classmethod def from_metadata_file_contents( cls, metadata_contents: bytes, filename: str, project_name: str, ) -> "BaseDistribution": """Load the distribution from the contents of a METADATA file. This is used to implement PEP 658 by generating a "shallow" dist object that can be used for resolution without downloading or building the actual dist yet. :param metadata_contents: The contents of a METADATA file. :param filename: File name for the dist with this metadata. :param project_name: Name of the project this dist represents. """ raise NotImplementedError() @classmethod def from_wheel(cls, wheel: "Wheel", name: str) -> "BaseDistribution": """Load the distribution from a given wheel. :param wheel: A concrete wheel definition. :param name: File name of the wheel. :raises InvalidWheel: Whenever loading of the wheel causes a :py:exc:`zipfile.BadZipFile` exception to be thrown. :raises UnsupportedWheel: If the wheel is a valid zip, but malformed internally. """ raise NotImplementedError() def __repr__(self) -> str: return f"{self.raw_name} {self.raw_version} ({self.location})" def __str__(self) -> str: return f"{self.raw_name} {self.raw_version}" @property def location(self) -> Optional[str]: """Where the distribution is loaded from. A string value is not necessarily a filesystem path, since distributions can be loaded from other sources, e.g. arbitrary zip archives. ``None`` means the distribution is created in-memory. Do not canonicalize this value with e.g. ``pathlib.Path.resolve()``. If this is a symbolic link, we want to preserve the relative path between it and files in the distribution. """ raise NotImplementedError() @property def editable_project_location(self) -> Optional[str]: """The project location for editable distributions. This is the directory where pyproject.toml or setup.py is located. None if the distribution is not installed in editable mode. """ # TODO: this property is relatively costly to compute, memoize it ? direct_url = self.direct_url if direct_url: if direct_url.is_local_editable(): return url_to_path(direct_url.url) else: # Search for an .egg-link file by walking sys.path, as it was # done before by dist_is_editable(). egg_link_path = egg_link_path_from_sys_path(self.raw_name) if egg_link_path: # TODO: get project location from second line of egg_link file # (https://github.com/pypa/pip/issues/10243) return self.location return None @property def installed_location(self) -> Optional[str]: """The distribution's "installed" location. This should generally be a ``site-packages`` directory. This is usually ``dist.location``, except for legacy develop-installed packages, where ``dist.location`` is the source code location, and this is where the ``.egg-link`` file is. The returned location is normalized (in particular, with symlinks removed). """ raise NotImplementedError() @property def info_location(self) -> Optional[str]: """Location of the .[egg|dist]-info directory or file. Similarly to ``location``, a string value is not necessarily a filesystem path. ``None`` means the distribution is created in-memory. For a modern .dist-info installation on disk, this should be something like ``{location}/{raw_name}-{version}.dist-info``. Do not canonicalize this value with e.g. ``pathlib.Path.resolve()``. If this is a symbolic link, we want to preserve the relative path between it and other files in the distribution. """ raise NotImplementedError() @property def installed_by_distutils(self) -> bool: """Whether this distribution is installed with legacy distutils format. A distribution installed with "raw" distutils not patched by setuptools uses one single file at ``info_location`` to store metadata. We need to treat this specially on uninstallation. """ info_location = self.info_location if not info_location: return False return pathlib.Path(info_location).is_file() @property def installed_as_egg(self) -> bool: """Whether this distribution is installed as an egg. This usually indicates the distribution was installed by (older versions of) easy_install. """ location = self.location if not location: return False return location.endswith(".egg") @property def installed_with_setuptools_egg_info(self) -> bool: """Whether this distribution is installed with the ``.egg-info`` format. This usually indicates the distribution was installed with setuptools with an old pip version or with ``single-version-externally-managed``. Note that this ensure the metadata store is a directory. distutils can also installs an ``.egg-info``, but as a file, not a directory. This property is *False* for that case. Also see ``installed_by_distutils``. """ info_location = self.info_location if not info_location: return False if not info_location.endswith(".egg-info"): return False return pathlib.Path(info_location).is_dir() @property def installed_with_dist_info(self) -> bool: """Whether this distribution is installed with the "modern format". This indicates a "modern" installation, e.g. storing metadata in the ``.dist-info`` directory. This applies to installations made by setuptools (but through pip, not directly), or anything using the standardized build backend interface (PEP 517). """ info_location = self.info_location if not info_location: return False if not info_location.endswith(".dist-info"): return False return pathlib.Path(info_location).is_dir() @property def canonical_name(self) -> NormalizedName: raise NotImplementedError() @property def version(self) -> Version: raise NotImplementedError() @property def raw_version(self) -> str: raise NotImplementedError() @property def setuptools_filename(self) -> str: """Convert a project name to its setuptools-compatible filename. This is a copy of ``pkg_resources.to_filename()`` for compatibility. """ return self.raw_name.replace("-", "_") @property def direct_url(self) -> Optional[DirectUrl]: """Obtain a DirectUrl from this distribution. Returns None if the distribution has no `direct_url.json` metadata, or if `direct_url.json` is invalid. """ try: content = self.read_text(DIRECT_URL_METADATA_NAME) except FileNotFoundError: return None try: return DirectUrl.from_json(content) except ( UnicodeDecodeError, json.JSONDecodeError, DirectUrlValidationError, ) as e: logger.warning( "Error parsing %s for %s: %s", DIRECT_URL_METADATA_NAME, self.canonical_name, e, ) return None @property def installer(self) -> str: try: installer_text = self.read_text("INSTALLER") except (OSError, ValueError, NoneMetadataError): return "" # Fail silently if the installer file cannot be read. for line in installer_text.splitlines(): cleaned_line = line.strip() if cleaned_line: return cleaned_line return "" @property def requested(self) -> bool: return self.is_file("REQUESTED") @property def editable(self) -> bool: return bool(self.editable_project_location) @property def local(self) -> bool: """If distribution is installed in the current virtual environment. Always True if we're not in a virtualenv. """ if self.installed_location is None: return False return is_local(self.installed_location) @property def in_usersite(self) -> bool: if self.installed_location is None or user_site is None: return False return self.installed_location.startswith(normalize_path(user_site)) @property def in_site_packages(self) -> bool: if self.installed_location is None or site_packages is None: return False return self.installed_location.startswith(normalize_path(site_packages)) def is_file(self, path: InfoPath) -> bool: """Check whether an entry in the info directory is a file.""" raise NotImplementedError() def iter_distutils_script_names(self) -> Iterator[str]: """Find distutils 'scripts' entries metadata. If 'scripts' is supplied in ``setup.py``, distutils records those in the installed distribution's ``scripts`` directory, a file for each script. """ raise NotImplementedError() def read_text(self, path: InfoPath) -> str: """Read a file in the info directory. :raise FileNotFoundError: If ``path`` does not exist in the directory. :raise NoneMetadataError: If ``path`` exists in the info directory, but cannot be read. """ raise NotImplementedError() def iter_entry_points(self) -> Iterable[BaseEntryPoint]: raise NotImplementedError() def _metadata_impl(self) -> email.message.Message: raise NotImplementedError() @functools.cached_property def metadata(self) -> email.message.Message: """Metadata of distribution parsed from e.g. METADATA or PKG-INFO. This should return an empty message if the metadata file is unavailable. :raises NoneMetadataError: If the metadata file is available, but does not contain valid metadata. """ metadata = self._metadata_impl() self._add_egg_info_requires(metadata) return metadata @property def metadata_dict(self) -> Dict[str, Any]: """PEP 566 compliant JSON-serializable representation of METADATA or PKG-INFO. This should return an empty dict if the metadata file is unavailable. :raises NoneMetadataError: If the metadata file is available, but does not contain valid metadata. """ return msg_to_json(self.metadata) @property def metadata_version(self) -> Optional[str]: """Value of "Metadata-Version:" in distribution metadata, if available.""" return self.metadata.get("Metadata-Version") @property def raw_name(self) -> str: """Value of "Name:" in distribution metadata.""" # The metadata should NEVER be missing the Name: key, but if it somehow # does, fall back to the known canonical name. return self.metadata.get("Name", self.canonical_name) @property def requires_python(self) -> SpecifierSet: """Value of "Requires-Python:" in distribution metadata. If the key does not exist or contains an invalid value, an empty SpecifierSet should be returned. """ value = self.metadata.get("Requires-Python") if value is None: return SpecifierSet() try: # Convert to str to satisfy the type checker; this can be a Header object. spec = SpecifierSet(str(value)) except InvalidSpecifier as e: message = "Package %r has an invalid Requires-Python: %s" logger.warning(message, self.raw_name, e) return SpecifierSet() return spec def iter_dependencies(self, extras: Collection[str] = ()) -> Iterable[Requirement]: """Dependencies of this distribution. For modern .dist-info distributions, this is the collection of "Requires-Dist:" entries in distribution metadata. """ raise NotImplementedError() def iter_raw_dependencies(self) -> Iterable[str]: """Raw Requires-Dist metadata.""" return self.metadata.get_all("Requires-Dist", []) def iter_provided_extras(self) -> Iterable[NormalizedName]: """Extras provided by this distribution. For modern .dist-info distributions, this is the collection of "Provides-Extra:" entries in distribution metadata. The return value of this function is expected to be normalised names, per PEP 685, with the returned value being handled appropriately by `iter_dependencies`. """ raise NotImplementedError() def _iter_declared_entries_from_record(self) -> Optional[Iterator[str]]: try: text = self.read_text("RECORD") except FileNotFoundError: return None # This extra Path-str cast normalizes entries. return (str(pathlib.Path(row[0])) for row in csv.reader(text.splitlines())) def _iter_declared_entries_from_legacy(self) -> Optional[Iterator[str]]: try: text = self.read_text("installed-files.txt") except FileNotFoundError: return None paths = (p for p in text.splitlines(keepends=False) if p) root = self.location info = self.info_location if root is None or info is None: return paths try: info_rel = pathlib.Path(info).relative_to(root) except ValueError: # info is not relative to root. return paths if not info_rel.parts: # info *is* root. return paths return ( _convert_installed_files_path(pathlib.Path(p).parts, info_rel.parts) for p in paths ) def iter_declared_entries(self) -> Optional[Iterator[str]]: """Iterate through file entries declared in this distribution. For modern .dist-info distributions, this is the files listed in the ``RECORD`` metadata file. For legacy setuptools distributions, this comes from ``installed-files.txt``, with entries normalized to be compatible with the format used by ``RECORD``. :return: An iterator for listed entries, or None if the distribution contains neither ``RECORD`` nor ``installed-files.txt``. """ return ( self._iter_declared_entries_from_record() or self._iter_declared_entries_from_legacy() ) def _iter_requires_txt_entries(self) -> Iterator[RequiresEntry]: """Parse a ``requires.txt`` in an egg-info directory. This is an INI-ish format where an egg-info stores dependencies. A section name describes extra other environment markers, while each entry is an arbitrary string (not a key-value pair) representing a dependency as a requirement string (no markers). There is a construct in ``importlib.metadata`` called ``Sectioned`` that does mostly the same, but the format is currently considered private. """ try: content = self.read_text("requires.txt") except FileNotFoundError: return extra = marker = "" # Section-less entries don't have markers. for line in content.splitlines(): line = line.strip() if not line or line.startswith("#"): # Comment; ignored. continue if line.startswith("[") and line.endswith("]"): # A section header. extra, _, marker = line.strip("[]").partition(":") continue yield RequiresEntry(requirement=line, extra=extra, marker=marker) def _iter_egg_info_extras(self) -> Iterable[str]: """Get extras from the egg-info directory.""" known_extras = {""} for entry in self._iter_requires_txt_entries(): extra = canonicalize_name(entry.extra) if extra in known_extras: continue known_extras.add(extra) yield extra def _iter_egg_info_dependencies(self) -> Iterable[str]: """Get distribution dependencies from the egg-info directory. To ease parsing, this converts a legacy dependency entry into a PEP 508 requirement string. Like ``_iter_requires_txt_entries()``, there is code in ``importlib.metadata`` that does mostly the same, but not do exactly what we need. Namely, ``importlib.metadata`` does not normalize the extra name before putting it into the requirement string, which causes marker comparison to fail because the dist-info format do normalize. This is consistent in all currently available PEP 517 backends, although not standardized. """ for entry in self._iter_requires_txt_entries(): extra = canonicalize_name(entry.extra) if extra and entry.marker: marker = f'({entry.marker}) and extra == "{extra}"' elif extra: marker = f'extra == "{extra}"' elif entry.marker: marker = entry.marker else: marker = "" if marker: yield f"{entry.requirement} ; {marker}" else: yield entry.requirement def _add_egg_info_requires(self, metadata: email.message.Message) -> None: """Add egg-info requires.txt information to the metadata.""" if not metadata.get_all("Requires-Dist"): for dep in self._iter_egg_info_dependencies(): metadata["Requires-Dist"] = dep if not metadata.get_all("Provides-Extra"): for extra in self._iter_egg_info_extras(): metadata["Provides-Extra"] = extra class BaseEnvironment: """An environment containing distributions to introspect.""" @classmethod def default(cls) -> "BaseEnvironment": raise NotImplementedError() @classmethod def from_paths(cls, paths: Optional[List[str]]) -> "BaseEnvironment": raise NotImplementedError() def get_distribution(self, name: str) -> Optional["BaseDistribution"]: """Given a requirement name, return the installed distributions. The name may not be normalized. The implementation must canonicalize it for lookup. """ raise NotImplementedError() def _iter_distributions(self) -> Iterator["BaseDistribution"]: """Iterate through installed distributions. This function should be implemented by subclass, but never called directly. Use the public ``iter_distribution()`` instead, which implements additional logic to make sure the distributions are valid. """ raise NotImplementedError() def iter_all_distributions(self) -> Iterator[BaseDistribution]: """Iterate through all installed distributions without any filtering.""" for dist in self._iter_distributions(): # Make sure the distribution actually comes from a valid Python # packaging distribution. Pip's AdjacentTempDirectory leaves folders # e.g. ``~atplotlib.dist-info`` if cleanup was interrupted. The # valid project name pattern is taken from PEP 508. project_name_valid = re.match( r"^([A-Z0-9]|[A-Z0-9][A-Z0-9._-]*[A-Z0-9])$", dist.canonical_name, flags=re.IGNORECASE, ) if not project_name_valid: logger.warning( "Ignoring invalid distribution %s (%s)", dist.canonical_name, dist.location, ) continue yield dist def iter_installed_distributions( self, local_only: bool = True, skip: Container[str] = stdlib_pkgs, include_editables: bool = True, editables_only: bool = False, user_only: bool = False, ) -> Iterator[BaseDistribution]: """Return a list of installed distributions. This is based on ``iter_all_distributions()`` with additional filtering options. Note that ``iter_installed_distributions()`` without arguments is *not* equal to ``iter_all_distributions()``, since some of the configurations exclude packages by default. :param local_only: If True (default), only return installations local to the current virtualenv, if in a virtualenv. :param skip: An iterable of canonicalized project names to ignore; defaults to ``stdlib_pkgs``. :param include_editables: If False, don't report editables. :param editables_only: If True, only report editables. :param user_only: If True, only report installations in the user site directory. """ it = self.iter_all_distributions() if local_only: it = (d for d in it if d.local) if not include_editables: it = (d for d in it if not d.editable) if editables_only: it = (d for d in it if d.editable) if user_only: it = (d for d in it if d.in_usersite) return (d for d in it if d.canonical_name not in skip) class Wheel(Protocol): location: str def as_zipfile(self) -> zipfile.ZipFile: raise NotImplementedError() class FilesystemWheel(Wheel): def __init__(self, location: str) -> None: self.location = location def as_zipfile(self) -> zipfile.ZipFile: return zipfile.ZipFile(self.location, allowZip64=True) class MemoryWheel(Wheel): def __init__(self, location: str, stream: IO[bytes]) -> None: self.location = location self.stream = stream def as_zipfile(self) -> zipfile.ZipFile: return zipfile.ZipFile(self.stream, allowZip64=True) pkg_resources.py 0000644 00000024456 15030255725 0010010 0 ustar 00 import email.message import email.parser import logging import os import zipfile from typing import ( Collection, Iterable, Iterator, List, Mapping, NamedTuple, Optional, ) from pip._vendor import pkg_resources from pip._vendor.packaging.requirements import Requirement from pip._vendor.packaging.utils import NormalizedName, canonicalize_name from pip._vendor.packaging.version import Version from pip._vendor.packaging.version import parse as parse_version from pip._internal.exceptions import InvalidWheel, NoneMetadataError, UnsupportedWheel from pip._internal.utils.egg_link import egg_link_path_from_location from pip._internal.utils.misc import display_path, normalize_path from pip._internal.utils.wheel import parse_wheel, read_wheel_metadata_file from .base import ( BaseDistribution, BaseEntryPoint, BaseEnvironment, InfoPath, Wheel, ) __all__ = ["NAME", "Distribution", "Environment"] logger = logging.getLogger(__name__) NAME = "pkg_resources" class EntryPoint(NamedTuple): name: str value: str group: str class InMemoryMetadata: """IMetadataProvider that reads metadata files from a dictionary. This also maps metadata decoding exceptions to our internal exception type. """ def __init__(self, metadata: Mapping[str, bytes], wheel_name: str) -> None: self._metadata = metadata self._wheel_name = wheel_name def has_metadata(self, name: str) -> bool: return name in self._metadata def get_metadata(self, name: str) -> str: try: return self._metadata[name].decode() except UnicodeDecodeError as e: # Augment the default error with the origin of the file. raise UnsupportedWheel( f"Error decoding metadata for {self._wheel_name}: {e} in {name} file" ) def get_metadata_lines(self, name: str) -> Iterable[str]: return pkg_resources.yield_lines(self.get_metadata(name)) def metadata_isdir(self, name: str) -> bool: return False def metadata_listdir(self, name: str) -> List[str]: return [] def run_script(self, script_name: str, namespace: str) -> None: pass class Distribution(BaseDistribution): def __init__(self, dist: pkg_resources.Distribution) -> None: self._dist = dist # This is populated lazily, to avoid loading metadata for all possible # distributions eagerly. self.__extra_mapping: Optional[Mapping[NormalizedName, str]] = None @property def _extra_mapping(self) -> Mapping[NormalizedName, str]: if self.__extra_mapping is None: self.__extra_mapping = { canonicalize_name(extra): extra for extra in self._dist.extras } return self.__extra_mapping @classmethod def from_directory(cls, directory: str) -> BaseDistribution: dist_dir = directory.rstrip(os.sep) # Build a PathMetadata object, from path to metadata. :wink: base_dir, dist_dir_name = os.path.split(dist_dir) metadata = pkg_resources.PathMetadata(base_dir, dist_dir) # Determine the correct Distribution object type. if dist_dir.endswith(".egg-info"): dist_cls = pkg_resources.Distribution dist_name = os.path.splitext(dist_dir_name)[0] else: assert dist_dir.endswith(".dist-info") dist_cls = pkg_resources.DistInfoDistribution dist_name = os.path.splitext(dist_dir_name)[0].split("-")[0] dist = dist_cls(base_dir, project_name=dist_name, metadata=metadata) return cls(dist) @classmethod def from_metadata_file_contents( cls, metadata_contents: bytes, filename: str, project_name: str, ) -> BaseDistribution: metadata_dict = { "METADATA": metadata_contents, } dist = pkg_resources.DistInfoDistribution( location=filename, metadata=InMemoryMetadata(metadata_dict, filename), project_name=project_name, ) return cls(dist) @classmethod def from_wheel(cls, wheel: Wheel, name: str) -> BaseDistribution: try: with wheel.as_zipfile() as zf: info_dir, _ = parse_wheel(zf, name) metadata_dict = { path.split("/", 1)[-1]: read_wheel_metadata_file(zf, path) for path in zf.namelist() if path.startswith(f"{info_dir}/") } except zipfile.BadZipFile as e: raise InvalidWheel(wheel.location, name) from e except UnsupportedWheel as e: raise UnsupportedWheel(f"{name} has an invalid wheel, {e}") dist = pkg_resources.DistInfoDistribution( location=wheel.location, metadata=InMemoryMetadata(metadata_dict, wheel.location), project_name=name, ) return cls(dist) @property def location(self) -> Optional[str]: return self._dist.location @property def installed_location(self) -> Optional[str]: egg_link = egg_link_path_from_location(self.raw_name) if egg_link: location = egg_link elif self.location: location = self.location else: return None return normalize_path(location) @property def info_location(self) -> Optional[str]: return self._dist.egg_info @property def installed_by_distutils(self) -> bool: # A distutils-installed distribution is provided by FileMetadata. This # provider has a "path" attribute not present anywhere else. Not the # best introspection logic, but pip has been doing this for a long time. try: return bool(self._dist._provider.path) except AttributeError: return False @property def canonical_name(self) -> NormalizedName: return canonicalize_name(self._dist.project_name) @property def version(self) -> Version: return parse_version(self._dist.version) @property def raw_version(self) -> str: return self._dist.version def is_file(self, path: InfoPath) -> bool: return self._dist.has_metadata(str(path)) def iter_distutils_script_names(self) -> Iterator[str]: yield from self._dist.metadata_listdir("scripts") def read_text(self, path: InfoPath) -> str: name = str(path) if not self._dist.has_metadata(name): raise FileNotFoundError(name) content = self._dist.get_metadata(name) if content is None: raise NoneMetadataError(self, name) return content def iter_entry_points(self) -> Iterable[BaseEntryPoint]: for group, entries in self._dist.get_entry_map().items(): for name, entry_point in entries.items(): name, _, value = str(entry_point).partition("=") yield EntryPoint(name=name.strip(), value=value.strip(), group=group) def _metadata_impl(self) -> email.message.Message: """ :raises NoneMetadataError: if the distribution reports `has_metadata()` True but `get_metadata()` returns None. """ if isinstance(self._dist, pkg_resources.DistInfoDistribution): metadata_name = "METADATA" else: metadata_name = "PKG-INFO" try: metadata = self.read_text(metadata_name) except FileNotFoundError: if self.location: displaying_path = display_path(self.location) else: displaying_path = repr(self.location) logger.warning("No metadata found in %s", displaying_path) metadata = "" feed_parser = email.parser.FeedParser() feed_parser.feed(metadata) return feed_parser.close() def iter_dependencies(self, extras: Collection[str] = ()) -> Iterable[Requirement]: if extras: relevant_extras = set(self._extra_mapping) & set( map(canonicalize_name, extras) ) extras = [self._extra_mapping[extra] for extra in relevant_extras] return self._dist.requires(extras) def iter_provided_extras(self) -> Iterable[NormalizedName]: return self._extra_mapping.keys() class Environment(BaseEnvironment): def __init__(self, ws: pkg_resources.WorkingSet) -> None: self._ws = ws @classmethod def default(cls) -> BaseEnvironment: return cls(pkg_resources.working_set) @classmethod def from_paths(cls, paths: Optional[List[str]]) -> BaseEnvironment: return cls(pkg_resources.WorkingSet(paths)) def _iter_distributions(self) -> Iterator[BaseDistribution]: for dist in self._ws: yield Distribution(dist) def _search_distribution(self, name: str) -> Optional[BaseDistribution]: """Find a distribution matching the ``name`` in the environment. This searches from *all* distributions available in the environment, to match the behavior of ``pkg_resources.get_distribution()``. """ canonical_name = canonicalize_name(name) for dist in self.iter_all_distributions(): if dist.canonical_name == canonical_name: return dist return None def get_distribution(self, name: str) -> Optional[BaseDistribution]: # Search the distribution by looking through the working set. dist = self._search_distribution(name) if dist: return dist # If distribution could not be found, call working_set.require to # update the working set, and try to find the distribution again. # This might happen for e.g. when you install a package twice, once # using setup.py develop and again using setup.py install. Now when # running pip uninstall twice, the package gets removed from the # working set in the first uninstall, so we have to populate the # working set again so that pip knows about it and the packages gets # picked up and is successfully uninstalled the second time too. try: # We didn't pass in any version specifiers, so this can never # raise pkg_resources.VersionConflict. self._ws.require(name) except pkg_resources.DistributionNotFound: return None return self._search_distribution(name) __pycache__/__init__.cpython-310.pyc 0000644 00000000244 15030255725 0013220 0 ustar 00 o �7]h � @ s d S )N� r r r �G/usr/lib/python3/dist-packages/pip/_vendor/chardet/metadata/__init__.py�<module> s __pycache__/pkg_resources.cpython-310.pyc 0000644 00000025331 15030255725 0014340 0 ustar 00 o �h.) � @ s@ d dl Zd dlZd dlZd dlZd dlZd dlmZmZm Z m Z mZmZm Z d dlmZ d dlmZ d dlmZmZ d dlmZ d dlmZ d dlmZmZmZ d d lmZ d d lm Z m!Z! d dl"m#Z#m$Z$ dd l%m&Z&m'Z'm(Z(m)Z)m*Z* g d�Z+e�,e-�Z.dZ/G dd� de�Z0G dd� d�Z1G dd� de&�Z2G dd� de(�Z3dS )� N)� Collection�Iterable�Iterator�List�Mapping� NamedTuple�Optional)� pkg_resources)�Requirement)�NormalizedName�canonicalize_name)�Version)�parse)�InvalidWheel�NoneMetadataError�UnsupportedWheel)�egg_link_path_from_location)�display_path�normalize_path)�parse_wheel�read_wheel_metadata_file� )�BaseDistribution�BaseEntryPoint�BaseEnvironment�InfoPath�Wheel)�NAME�Distribution�Environmentr c @ s&