Let us walk on the 3-isogeny graph
Loading...
Searching...
No Matches
ZipProvider Class Reference
Inheritance diagram for ZipProvider:
Collaboration diagram for ZipProvider:

Public Member Functions

 __init__ (self, module)
 
 zipinfo (self)
 
 get_resource_filename (self, manager, resource_name)
 
- Public Member Functions inherited from NullProvider
 get_resource_stream (self, manager, resource_name)
 
 get_resource_string (self, manager, resource_name)
 
 has_resource (self, resource_name)
 
 has_metadata (self, name)
 
 get_metadata (self, name)
 
 get_metadata_lines (self, name)
 
 resource_isdir (self, resource_name)
 
 metadata_isdir (self, name)
 
 resource_listdir (self, resource_name)
 
 metadata_listdir (self, name)
 
 run_script (self, script_name, namespace)
 

Data Fields

 zip_pre
 
 egg_root
 
 module_path
 
- Data Fields inherited from EggProvider
 egg_name
 
 egg_info
 
 egg_root
 
- Data Fields inherited from NullProvider
 module_path
 

Static Public Attributes

 eagers = None
 
- Static Public Attributes inherited from NullProvider
 egg_name = None
 
 egg_info = None
 
 loader = None
 

Protected Member Functions

 _zipinfo_name (self, fspath)
 
 _parts (self, zip_path)
 
 _extract_resource (self, manager, zip_path)
 
 _is_current (self, file_path, zip_path)
 
 _get_eager_resources (self)
 
 _index (self)
 
 _has (self, fspath)
 
 _isdir (self, fspath)
 
 _listdir (self, fspath)
 
 _eager_to_zip (self, resource_name)
 
 _resource_to_zip (self, resource_name)
 
- Protected Member Functions inherited from EggProvider
 _setup_prefix (self)
 
 _set_egg (self, path)
 
- Protected Member Functions inherited from NullProvider
 _get_metadata_path (self, name)
 
 _fn (self, base, resource_name)
 
 _get (self, path)
 

Static Protected Member Functions

 _get_date_and_size (zip_stat)
 
- Static Protected Member Functions inherited from NullProvider
 _validate_resource_path (path)
 

Protected Attributes

 _dirindex
 

Static Protected Attributes

 _zip_manifests = MemoizedZipManifests()
 

Detailed Description

Resource support for zips and eggs

Definition at line 1812 of file __init__.py.

Constructor & Destructor Documentation

◆ __init__()

__init__ (   self,
  module 
)

Reimplemented from EggProvider.

Reimplemented in EggMetadata.

Definition at line 1818 of file __init__.py.

1818 def __init__(self, module):
1819 super().__init__(module)
1820 self.zip_pre = self.loader.archive + os.sep
1821
for i

Referenced by Protocol.__init_subclass__().

Here is the caller graph for this function:

Member Function Documentation

◆ _eager_to_zip()

_eager_to_zip (   self,
  resource_name 
)
protected

Definition at line 1969 of file __init__.py.

1969 def _eager_to_zip(self, resource_name):
1970 return self._zipinfo_name(self._fn(self.egg_root, resource_name))
1971

◆ _extract_resource()

_extract_resource (   self,
  manager,
  zip_path 
)
protected

Definition at line 1867 of file __init__.py.

1867 def _extract_resource(self, manager, zip_path): # noqa: C901
1868 if zip_path in self._index():
1869 for name in self._index()[zip_path]:
1870 last = self._extract_resource(manager, os.path.join(zip_path, name))
1871 # return the extracted directory name
1872 return os.path.dirname(last)
1873
1874 timestamp, size = self._get_date_and_size(self.zipinfo[zip_path])
1875
1876 if not WRITE_SUPPORT:
1877 raise IOError(
1878 '"os.rename" and "os.unlink" are not supported ' 'on this platform'
1879 )
1880 try:
1881 real_path = manager.get_cache_path(self.egg_name, self._parts(zip_path))
1882
1883 if self._is_current(real_path, zip_path):
1884 return real_path
1885
1886 outf, tmpnam = _mkstemp(
1887 ".$extract",
1888 dir=os.path.dirname(real_path),
1889 )
1890 os.write(outf, self.loader.get_data(zip_path))
1891 os.close(outf)
1892 utime(tmpnam, (timestamp, timestamp))
1893 manager.postprocess(tmpnam, real_path)
1894
1895 try:
1896 rename(tmpnam, real_path)
1897
1898 except os.error:
1899 if os.path.isfile(real_path):
1900 if self._is_current(real_path, zip_path):
1901 # the file became current since it was checked above,
1902 # so proceed.
1903 return real_path
1904 # Windows, del old file and retry
1905 elif os.name == 'nt':
1906 unlink(real_path)
1907 rename(tmpnam, real_path)
1908 return real_path
1909 raise
1910
1911 except os.error:
1912 # report a user-friendly error
1914
1915 return real_path
1916

◆ _get_date_and_size()

_get_date_and_size (   zip_stat)
staticprotected

Definition at line 1858 of file __init__.py.

1858 def _get_date_and_size(zip_stat):
1859 size = zip_stat.file_size
1860 # ymdhms+wday, yday, dst
1861 date_time = zip_stat.date_time + (0, 0, -1)
1862 # 1980 offset already done
1863 timestamp = time.mktime(date_time)
1864 return timestamp, size
1865

◆ _get_eager_resources()

_get_eager_resources (   self)
protected

Definition at line 1933 of file __init__.py.

1933 def _get_eager_resources(self):
1934 if self.eagers is None:
1935 eagers = []
1936 for name in ('native_libs.txt', 'eager_resources.txt'):
1937 if self.has_metadata(name):
1938 eagers.extend(self.get_metadata_lines(name))
1939 self.eagers = eagers
1940 return self.eagers
1941

◆ _has()

_has (   self,
  fspath 
)
protected

Reimplemented from NullProvider.

Definition at line 1959 of file __init__.py.

1959 def _has(self, fspath):
1960 zip_path = self._zipinfo_name(fspath)
1961 return zip_path in self.zipinfo or zip_path in self._index()
1962

◆ _index()

_index (   self)
protected

Definition at line 1942 of file __init__.py.

1942 def _index(self):
1943 try:
1944 return self._dirindex
1945 except AttributeError:
1946 ind = {}
1947 for path in self.zipinfo:
1948 parts = path.split(os.sep)
1949 while parts:
1950 parent = os.sep.join(parts[:-1])
1951 if parent in ind:
1952 ind[parent].append(parts[-1])
1953 break
1954 else:
1955 ind[parent] = [parts.pop()]
1956 self._dirindex = ind
1957 return ind
1958

◆ _is_current()

_is_current (   self,
  file_path,
  zip_path 
)
protected
Return True if the file_path is current for this zip_path

Definition at line 1917 of file __init__.py.

1917 def _is_current(self, file_path, zip_path):
1918 """
1919 Return True if the file_path is current for this zip_path
1920 """
1921 timestamp, size = self._get_date_and_size(self.zipinfo[zip_path])
1922 if not os.path.isfile(file_path):
1923 return False
1924 stat = os.stat(file_path)
1925 if stat.st_size != size or stat.st_mtime != timestamp:
1926 return False
1927 # check that the contents match
1928 zip_contents = self.loader.get_data(zip_path)
1929 with open(file_path, 'rb') as f:
1930 file_contents = f.read()
1931 return zip_contents == file_contents
1932

◆ _isdir()

_isdir (   self,
  fspath 
)
protected

Reimplemented from NullProvider.

Definition at line 1963 of file __init__.py.

1963 def _isdir(self, fspath):
1964 return self._zipinfo_name(fspath) in self._index()
1965

◆ _listdir()

_listdir (   self,
  fspath 
)
protected

Reimplemented from NullProvider.

Definition at line 1966 of file __init__.py.

1966 def _listdir(self, fspath):
1967 return list(self._index().get(self._zipinfo_name(fspath), ()))
1968

◆ _parts()

_parts (   self,
  zip_path 
)
protected

Definition at line 1832 of file __init__.py.

1832 def _parts(self, zip_path):
1833 # Convert a zipfile subpath into an egg-relative path part list.
1834 # pseudo-fs path
1835 fspath = self.zip_pre + zip_path
1836 if fspath.startswith(self.egg_root + os.sep):
1837 return fspath[len(self.egg_root) + 1 :].split(os.sep)
1838 raise AssertionError("%s is not a subpath of %s" % (fspath, self.egg_root))
1839

Referenced by Version.__eq__(), Matcher.__eq__(), Version.__hash__(), Matcher.__hash__(), Version.__lt__(), Matcher.exact_version(), NormalizedVersion.is_prerelease(), LegacyVersion.is_prerelease(), SemanticVersion.is_prerelease(), and Matcher.match().

Here is the caller graph for this function:

◆ _resource_to_zip()

_resource_to_zip (   self,
  resource_name 
)
protected

Definition at line 1972 of file __init__.py.

1972 def _resource_to_zip(self, resource_name):
1973 return self._zipinfo_name(self._fn(self.module_path, resource_name))
1974
1975

◆ _zipinfo_name()

_zipinfo_name (   self,
  fspath 
)
protected

Definition at line 1822 of file __init__.py.

1822 def _zipinfo_name(self, fspath):
1823 # Convert a virtual filename (full path to file) into a zipfile subpath
1824 # usable with the zipimport directory cache for our target archive
1825 fspath = fspath.rstrip(os.sep)
1826 if fspath == self.loader.archive:
1827 return ''
1828 if fspath.startswith(self.zip_pre):
1829 return fspath[len(self.zip_pre) :]
1830 raise AssertionError("%s is not a subpath of %s" % (fspath, self.zip_pre))
1831

◆ get_resource_filename()

get_resource_filename (   self,
  manager,
  resource_name 
)

Reimplemented from NullProvider.

Definition at line 1844 of file __init__.py.

1844 def get_resource_filename(self, manager, resource_name):
1845 if not self.egg_name:
1846 raise NotImplementedError(
1847 "resource_filename() only supported for .egg, not .zip"
1848 )
1849 # no need to lock for extraction, since we use temp names
1850 zip_path = self._resource_to_zip(resource_name)
1851 eagers = self._get_eager_resources()
1852 if '/'.join(self._parts(zip_path)) in eagers:
1853 for name in eagers:
1854 self._extract_resource(manager, self._eager_to_zip(name))
1855 return self._extract_resource(manager, zip_path)
1856

◆ zipinfo()

zipinfo (   self)

Definition at line 1841 of file __init__.py.

1841 def zipinfo(self):
1842 return self._zip_manifests.load(self.loader.archive)
1843

Field Documentation

◆ _dirindex

_dirindex
protected

Definition at line 1956 of file __init__.py.

◆ _zip_manifests

_zip_manifests = MemoizedZipManifests()
staticprotected

Definition at line 1816 of file __init__.py.

◆ eagers

eagers = None
static

Definition at line 1815 of file __init__.py.

◆ egg_root

egg_root

Definition at line 1837 of file __init__.py.

◆ module_path

module_path

Definition at line 1973 of file __init__.py.

◆ zip_pre

zip_pre

Definition at line 1820 of file __init__.py.


The documentation for this class was generated from the following file: