Skip to content

Commit

Permalink
Import the part of PEP 566 about transforming core metadata to JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanas committed Dec 22, 2023
1 parent e2c2ffa commit 1fe7485
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions source/specifications/core-metadata.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ definition, the practical standard is set by what the standard library
Whenever metadata is serialised to a byte stream (for example, to save
to a file), strings must be serialised using the UTF-8 encoding.

Although :pep:`566` defined a way to transform metadata into a JSON-compatible
dictionary, this is not yet used as a standard interchange format. The need for
tools to work with years worth of existing packages makes it difficult to shift
to a new format.

.. note:: *Interpreting old metadata:* In :pep:`566`, the version specifier
field format specification was relaxed to accept the syntax used by popular
publishing tools (namely to remove the requirement that version specifiers
Expand Down Expand Up @@ -848,6 +843,27 @@ Example::
Obsoletes: Gorgon


Transforming core metadata to JSON
==================================

It may be necessary to store metadata in a data structure which does not allow
for multiple repeated keys, such as JSON. This specification defines a way to
transform metadata into a JSON-compatible dictionary [#json-not-interchange]_.

#. The original key-value format should be read with
``email.parser.HeaderParser``.
#. All transformed keys should be reduced to lower case. Hyphens should be
replaced with underscores, but otherwise should retain all other characters.
#. The transformed value for any field marked with "(multiple use)" should be a
single list containing all the original values for the given key.
#. The ``Keywords`` field should be converted to a list by splitting the
original value on commas.
#. The message body, if present, should be set to the value of the
``description`` key.
#. The result should be stored as a string-keyed dictionary.



----

.. [1] reStructuredText markup:
Expand All @@ -857,3 +873,7 @@ Example::

.. [2] RFC 822 Long Header Fields:
:rfc:`822#section-3.1.1`
.. [#json-not-interchange] This is not yet used as a standard interchange
format; the need for tools to work with years worth of existing packages
makes it difficult to shift to a new format.)

0 comments on commit 1fe7485

Please sign in to comment.