Let us walk on the 3-isogeny graph
Loading...
Searching...
No Matches
pip._internal.metadata._json Namespace Reference

Functions

str json_name (str field)
 
Dict[str, Any] msg_to_json (Message msg)
 

Variables

list METADATA_FIELDS
 

Function Documentation

◆ json_name()

str json_name ( str  field)

Definition at line 37 of file _json.py.

37def json_name(field: str) -> str:
38 return field.lower().replace("-", "_")
39
40
for i

References i.

Referenced by pip._internal.metadata._json.msg_to_json().

Here is the caller graph for this function:

◆ msg_to_json()

Dict[str, Any] msg_to_json ( Message  msg)
Convert a Message object into a JSON-compatible dictionary.

Definition at line 41 of file _json.py.

41def msg_to_json(msg: Message) -> Dict[str, Any]:
42 """Convert a Message object into a JSON-compatible dictionary."""
43
44 def sanitise_header(h: Union[Header, str]) -> str:
45 if isinstance(h, Header):
46 chunks = []
47 for bytes, encoding in decode_header(h):
48 if encoding == "unknown-8bit":
49 try:
50 # See if UTF-8 works
51 bytes.decode("utf-8")
52 encoding = "utf-8"
53 except UnicodeDecodeError:
54 # If not, latin1 at least won't fail
55 encoding = "latin1"
56 chunks.append((bytes, encoding))
57 return str(make_header(chunks))
58 return str(h)
59
60 result = {}
61 for field, multi in METADATA_FIELDS:
62 if field not in msg:
63 continue
64 key = json_name(field)
65 if multi:
66 value: Union[str, List[str]] = [
67 sanitise_header(v) for v in msg.get_all(field)
68 ]
69 else:
70 value = sanitise_header(msg.get(field))
71 if key == "keywords":
72 # Accept both comma-separated and space-separated
73 # forms, for better compatibility with old data.
74 if "," in value:
75 value = [v.strip() for v in value.split(",")]
76 else:
77 value = value.split()
78 result[key] = value
79
80 payload = msg.get_payload()
81 if payload:
82 result["description"] = payload
83
84 return result

References i, and pip._internal.metadata._json.json_name().

Here is the call graph for this function:

Variable Documentation

◆ METADATA_FIELDS

list METADATA_FIELDS
Initial value:
1= [
2 # Name, Multiple-Use
3 ("Metadata-Version", False),
4 ("Name", False),
5 ("Version", False),
6 ("Dynamic", True),
7 ("Platform", True),
8 ("Supported-Platform", True),
9 ("Summary", False),
10 ("Description", False),
11 ("Description-Content-Type", False),
12 ("Keywords", False),
13 ("Home-page", False),
14 ("Download-URL", False),
15 ("Author", False),
16 ("Author-email", False),
17 ("Maintainer", False),
18 ("Maintainer-email", False),
19 ("License", False),
20 ("Classifier", True),
21 ("Requires-Dist", True),
22 ("Requires-Python", False),
23 ("Requires-External", True),
24 ("Project-URL", True),
25 ("Provides-Extra", True),
26 ("Provides-Dist", True),
27 ("Obsoletes-Dist", True),
28]

Definition at line 7 of file _json.py.