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

Public Member Functions

 __init__ (self, module)
 
 get_resource_filename (self, manager, resource_name)
 
 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

 module_path
 

Static Public Attributes

 egg_name = None
 
 egg_info = None
 
 loader = None
 

Protected Member Functions

 _get_metadata_path (self, name)
 
 _has (self, path)
 
 _isdir (self, path)
 
 _listdir (self, path)
 
 _fn (self, base, resource_name)
 
 _get (self, path)
 

Static Protected Member Functions

 _validate_resource_path (path)
 

Detailed Description

Try to implement resources and metadata for arbitrary PEP 302 loaders

Definition at line 1482 of file __init__.py.

Constructor & Destructor Documentation

◆ __init__()

__init__ (   self,
  module 
)

Reimplemented in EmptyProvider, EggMetadata, EggProvider, ZipProvider, FileMetadata, and PathMetadata.

Definition at line 1489 of file __init__.py.

1489 def __init__(self, module):
1490 self.loader = getattr(module, '__loader__', None)
1491 self.module_path = os.path.dirname(getattr(module, '__file__', ''))
1492
for i

Referenced by Protocol.__init_subclass__().

Here is the caller graph for this function:

Member Function Documentation

◆ _fn()

_fn (   self,
  base,
  resource_name 
)
protected

Definition at line 1589 of file __init__.py.

1589 def _fn(self, base, resource_name):
1590 self._validate_resource_path(resource_name)
1591 if resource_name:
1592 return os.path.join(base, *resource_name.split('/'))
1593 return base
1594

Referenced by _FileCacheMixin._delete(), _FileCacheMixin.get(), SeparateBodyFileCache.get_body(), _FileCacheMixin.set(), and SeparateBodyFileCache.set_body().

Here is the caller graph for this function:

◆ _get()

_get (   self,
  path 
)
protected

Reimplemented in DefaultProvider, and EmptyProvider.

Definition at line 1669 of file __init__.py.

1669 def _get(self, path):
1670 if hasattr(self.loader, 'get_data'):
1671 return self.loader.get_data(path)
1672 raise NotImplementedError(
1673 "Can't perform this operation for loaders without 'get_data()'"
1674 )
1675
1676

◆ _get_metadata_path()

_get_metadata_path (   self,
  name 
)
protected

Reimplemented in FileMetadata.

Definition at line 1505 of file __init__.py.

1505 def _get_metadata_path(self, name):
1506 return self._fn(self.egg_info, name)
1507

◆ _has()

_has (   self,
  path 
)
protected

Reimplemented in ZipProvider, and DefaultProvider.

Definition at line 1574 of file __init__.py.

1574 def _has(self, path):
1575 raise NotImplementedError(
1576 "Can't perform this operation for unregistered loader type"
1577 )
1578

◆ _isdir()

_isdir (   self,
  path 
)
protected

Reimplemented in ZipProvider, and DefaultProvider.

Definition at line 1579 of file __init__.py.

1579 def _isdir(self, path):
1580 raise NotImplementedError(
1581 "Can't perform this operation for unregistered loader type"
1582 )
1583

◆ _listdir()

_listdir (   self,
  path 
)
protected

Reimplemented in ZipProvider, DefaultProvider, and EmptyProvider.

Definition at line 1584 of file __init__.py.

1584 def _listdir(self, path):
1585 raise NotImplementedError(
1586 "Can't perform this operation for unregistered loader type"
1587 )
1588

◆ _validate_resource_path()

_validate_resource_path (   path)
staticprotected
Validate the resource paths according to the docs.
https://setuptools.pypa.io/en/latest/pkg_resources.html#basic-resource-access

>>> warned = getfixture('recwarn')
>>> warnings.simplefilter('always')
>>> vrp = NullProvider._validate_resource_path
>>> vrp('foo/bar.txt')
>>> bool(warned)
False
>>> vrp('../foo/bar.txt')
>>> bool(warned)
True
>>> warned.clear()
>>> vrp('/foo/bar.txt')
>>> bool(warned)
True
>>> vrp('foo/../../bar.txt')
>>> bool(warned)
True
>>> warned.clear()
>>> vrp('foo/f../bar.txt')
>>> bool(warned)
False

Windows path separators are straight-up disallowed.
>>> vrp(r'\\foo/bar.txt')
Traceback (most recent call last):
...
ValueError: Use of .. or absolute path in a resource path \
is not allowed.

>>> vrp(r'C:\\foo/bar.txt')
Traceback (most recent call last):
...
ValueError: Use of .. or absolute path in a resource path \
is not allowed.

Blank values are allowed

>>> vrp('')
>>> bool(warned)
False

Non-string values are not.

>>> vrp(None)
Traceback (most recent call last):
...
AttributeError: ...

Definition at line 1596 of file __init__.py.

1596 def _validate_resource_path(path):
1597 """
1598 Validate the resource paths according to the docs.
1599 https://setuptools.pypa.io/en/latest/pkg_resources.html#basic-resource-access
1600
1601 >>> warned = getfixture('recwarn')
1602 >>> warnings.simplefilter('always')
1603 >>> vrp = NullProvider._validate_resource_path
1604 >>> vrp('foo/bar.txt')
1605 >>> bool(warned)
1606 False
1607 >>> vrp('../foo/bar.txt')
1608 >>> bool(warned)
1609 True
1610 >>> warned.clear()
1611 >>> vrp('/foo/bar.txt')
1612 >>> bool(warned)
1613 True
1614 >>> vrp('foo/../../bar.txt')
1615 >>> bool(warned)
1616 True
1617 >>> warned.clear()
1618 >>> vrp('foo/f../bar.txt')
1619 >>> bool(warned)
1620 False
1621
1622 Windows path separators are straight-up disallowed.
1623 >>> vrp(r'\\foo/bar.txt')
1624 Traceback (most recent call last):
1625 ...
1626 ValueError: Use of .. or absolute path in a resource path \
1627is not allowed.
1628
1629 >>> vrp(r'C:\\foo/bar.txt')
1630 Traceback (most recent call last):
1631 ...
1632 ValueError: Use of .. or absolute path in a resource path \
1633is not allowed.
1634
1635 Blank values are allowed
1636
1637 >>> vrp('')
1638 >>> bool(warned)
1639 False
1640
1641 Non-string values are not.
1642
1643 >>> vrp(None)
1644 Traceback (most recent call last):
1645 ...
1646 AttributeError: ...
1647 """
1648 invalid = (
1650 or posixpath.isabs(path)
1651 or ntpath.isabs(path)
1652 )
1653 if not invalid:
1654 return
1655
1656 msg = "Use of .. or absolute path in a resource path is not allowed."
1657
1658 # Aggressively disallow Windows absolute paths
1659 if ntpath.isabs(path) and not posixpath.isabs(path):
1660 raise ValueError(msg)
1661
1662 # for compatibility, warn; in future
1663 # raise ValueError(msg)
1664 issue_warning(
1665 msg[:-1] + " and will raise exceptions in a future release.",
1666 DeprecationWarning,
1667 )
1668

◆ get_metadata()

get_metadata (   self,
  name 
)

Reimplemented in FileMetadata.

Definition at line 1515 of file __init__.py.

1515 def get_metadata(self, name):
1516 if not self.egg_info:
1517 return ""
1518 path = self._get_metadata_path(name)
1519 value = self._get(path)
1520 try:
1521 return value.decode('utf-8')
1522 except UnicodeDecodeError as exc:
1523 # Include the path in the error message to simplify
1524 # troubleshooting, and without changing the exception type.
1525 exc.reason += ' in {} file at path: {}'.format(name, path)
1526 raise
1527

Referenced by InMemoryMetadata.get_metadata_lines().

Here is the caller graph for this function:

◆ get_metadata_lines()

get_metadata_lines (   self,
  name 
)

Reimplemented in FileMetadata.

Definition at line 1528 of file __init__.py.

1528 def get_metadata_lines(self, name):
1529 return yield_lines(self.get_metadata(name))
1530

◆ get_resource_filename()

get_resource_filename (   self,
  manager,
  resource_name 
)

Reimplemented in ZipProvider.

Definition at line 1493 of file __init__.py.

1493 def get_resource_filename(self, manager, resource_name):
1494 return self._fn(self.module_path, resource_name)
1495

◆ get_resource_stream()

get_resource_stream (   self,
  manager,
  resource_name 
)

Reimplemented in DefaultProvider.

Definition at line 1496 of file __init__.py.

1496 def get_resource_stream(self, manager, resource_name):
1497 return io.BytesIO(self.get_resource_string(manager, resource_name))
1498

◆ get_resource_string()

get_resource_string (   self,
  manager,
  resource_name 
)

Definition at line 1499 of file __init__.py.

1499 def get_resource_string(self, manager, resource_name):
1500 return self._get(self._fn(self.module_path, resource_name))
1501

◆ has_metadata()

has_metadata (   self,
  name 
)

Reimplemented in FileMetadata.

Definition at line 1508 of file __init__.py.

1508 def has_metadata(self, name):
1509 if not self.egg_info:
1510 return self.egg_info
1511
1512 path = self._get_metadata_path(name)
1513 return self._has(path)
1514

◆ has_resource()

has_resource (   self,
  resource_name 
)

Definition at line 1502 of file __init__.py.

1502 def has_resource(self, resource_name):
1503 return self._has(self._fn(self.module_path, resource_name))
1504

◆ metadata_isdir()

metadata_isdir (   self,
  name 
)

Definition at line 1534 of file __init__.py.

1534 def metadata_isdir(self, name):
1535 return self.egg_info and self._isdir(self._fn(self.egg_info, name))
1536

◆ metadata_listdir()

metadata_listdir (   self,
  name 
)

Definition at line 1540 of file __init__.py.

1540 def metadata_listdir(self, name):
1541 if self.egg_info:
1542 return self._listdir(self._fn(self.egg_info, name))
1543 return []
1544

◆ resource_isdir()

resource_isdir (   self,
  resource_name 
)

Definition at line 1531 of file __init__.py.

1531 def resource_isdir(self, resource_name):
1532 return self._isdir(self._fn(self.module_path, resource_name))
1533

◆ resource_listdir()

resource_listdir (   self,
  resource_name 
)

Definition at line 1537 of file __init__.py.

1537 def resource_listdir(self, resource_name):
1538 return self._listdir(self._fn(self.module_path, resource_name))
1539

◆ run_script()

run_script (   self,
  script_name,
  namespace 
)

Definition at line 1545 of file __init__.py.

1545 def run_script(self, script_name, namespace):
1546 script = 'scripts/' + script_name
1547 if not self.has_metadata(script):
1548 raise ResolutionError(
1549 "Script {script!r} not found in metadata at {self.egg_info!r}".format(
1550 **locals()
1551 ),
1552 )
1553 script_text = self.get_metadata(script).replace('\r\n', '\n')
1554 script_text = script_text.replace('\r', '\n')
1555 script_filename = self._fn(self.egg_info, script)
1556 namespace['__file__'] = script_filename
1557 if os.path.exists(script_filename):
1558 with open(script_filename) as fid:
1559 source = fid.read()
1560 code = compile(source, script_filename, 'exec')
1561 exec(code, namespace, namespace)
1562 else:
1563 from linecache import cache
1564
1565 cache[script_filename] = (
1566 len(script_text),
1567 0,
1568 script_text.split('\n'),
1569 script_filename,
1570 )
1571 script_code = compile(script_text, script_filename, 'exec')
1572 exec(script_code, namespace, namespace)
1573

Field Documentation

◆ egg_info

egg_info = None
static

Definition at line 1486 of file __init__.py.

◆ egg_name

egg_name = None
static

Definition at line 1485 of file __init__.py.

◆ loader

◆ module_path

module_path

Definition at line 1491 of file __init__.py.


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