twine.package module

twine.package._safe_name(name: str) str[source]

Convert an arbitrary string to a standard distribution name.

Any runs of non-alphanumeric/. characters are replaced with a single ‘-‘.

Copied from pkg_resources.safe_name for compatibility with warehouse. See https://github.com/pypa/twine/issues/743.

class twine.package.PackageFile[source]
__init__(filename: str, comment: Optional[str], metadata: pkginfo.distribution.Distribution, python_version: Optional[str], filetype: Optional[str]) None[source]
classmethod from_filename(filename: str, comment: Optional[str]) twine.package.PackageFile[source]
metadata_dictionary() Dict[str, Union[str, Sequence[str]]][source]
add_gpg_signature(signature_filepath: str, signature_filename: str) None[source]
sign(sign_with: str, identity: Optional[str]) None[source]
classmethod run_gpg(gpg_args: Tuple[str, ...]) None[source]
class twine.package.Hexdigest[source]

Hexdigest(md5, sha2, blake2)

property md5

Alias for field number 0

property sha2

Alias for field number 1

property blake2

Alias for field number 2

static __new__(_cls, md5: Optional[str], sha2: Optional[str], blake2: Optional[str])

Create new instance of Hexdigest(md5, sha2, blake2)

_asdict()

Return a new OrderedDict which maps field names to their values.

_field_defaults = {}
_field_types = {'blake2': typing.Union[str, NoneType], 'md5': typing.Union[str, NoneType], 'sha2': typing.Union[str, NoneType]}
_fields = ('md5', 'sha2', 'blake2')
classmethod _make(iterable, new=<built-in method __new__ of type object>, len=<built-in function len>)

Make a new Hexdigest object from a sequence or iterable

_replace(**kwds)

Return a new Hexdigest object replacing specified fields with new values

_source = "from builtins import property as _property, tuple as _tuple\nfrom operator import itemgetter as _itemgetter\nfrom collections import OrderedDict\n\nclass Hexdigest(tuple):\n    'Hexdigest(md5, sha2, blake2)'\n\n    __slots__ = ()\n\n    _fields = ('md5', 'sha2', 'blake2')\n\n    def __new__(_cls, md5, sha2, blake2):\n        'Create new instance of Hexdigest(md5, sha2, blake2)'\n        return _tuple.__new__(_cls, (md5, sha2, blake2))\n\n    @classmethod\n    def _make(cls, iterable, new=tuple.__new__, len=len):\n        'Make a new Hexdigest object from a sequence or iterable'\n        result = new(cls, iterable)\n        if len(result) != 3:\n            raise TypeError('Expected 3 arguments, got %d' % len(result))\n        return result\n\n    def _replace(_self, **kwds):\n        'Return a new Hexdigest object replacing specified fields with new values'\n        result = _self._make(map(kwds.pop, ('md5', 'sha2', 'blake2'), _self))\n        if kwds:\n            raise ValueError('Got unexpected field names: %r' % list(kwds))\n        return result\n\n    def __repr__(self):\n        'Return a nicely formatted representation string'\n        return self.__class__.__name__ + '(md5=%r, sha2=%r, blake2=%r)' % self\n\n    def _asdict(self):\n        'Return a new OrderedDict which maps field names to their values.'\n        return OrderedDict(zip(self._fields, self))\n\n    def __getnewargs__(self):\n        'Return self as a plain tuple.  Used by copy and pickle.'\n        return tuple(self)\n\n    md5 = _property(_itemgetter(0), doc='Alias for field number 0')\n\n    sha2 = _property(_itemgetter(1), doc='Alias for field number 1')\n\n    blake2 = _property(_itemgetter(2), doc='Alias for field number 2')\n\n"
class twine.package.HashManager[source]

Manage our hashing objects for simplicity.

This will also allow us to better test this logic.

__init__(filename: str) None[source]

Initialize our manager and hasher objects.

_md5_update(content: bytes) None[source]
_md5_hexdigest() Optional[str][source]
_sha2_update(content: bytes) None[source]
_sha2_hexdigest() Optional[str][source]
_blake_update(content: bytes) None[source]
_blake_hexdigest() Optional[str][source]
hash() None[source]

Hash the file contents.

hexdigest() twine.package.Hexdigest[source]

Return the hexdigest for the file.