Mercurial > repos > guerler > hhblits
comparison lib/python3.8/site-packages/wheel/pkginfo.py @ 0:9e54283cc701 draft
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
author | guerler |
---|---|
date | Mon, 27 Jul 2020 03:47:31 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:9e54283cc701 |
---|---|
1 """Tools for reading and writing PKG-INFO / METADATA without caring | |
2 about the encoding.""" | |
3 | |
4 from email.parser import Parser | |
5 | |
6 try: | |
7 unicode | |
8 _PY3 = False | |
9 except NameError: | |
10 _PY3 = True | |
11 | |
12 if not _PY3: | |
13 from email.generator import Generator | |
14 | |
15 def read_pkg_info_bytes(bytestr): | |
16 return Parser().parsestr(bytestr) | |
17 | |
18 def read_pkg_info(path): | |
19 with open(path, "r") as headers: | |
20 message = Parser().parse(headers) | |
21 return message | |
22 | |
23 def write_pkg_info(path, message): | |
24 with open(path, 'w') as metadata: | |
25 Generator(metadata, mangle_from_=False, maxheaderlen=0).flatten(message) | |
26 else: | |
27 from email.generator import BytesGenerator | |
28 | |
29 def read_pkg_info_bytes(bytestr): | |
30 headers = bytestr.decode(encoding="ascii", errors="surrogateescape") | |
31 message = Parser().parsestr(headers) | |
32 return message | |
33 | |
34 def read_pkg_info(path): | |
35 with open(path, "r", | |
36 encoding="ascii", | |
37 errors="surrogateescape") as headers: | |
38 message = Parser().parse(headers) | |
39 return message | |
40 | |
41 def write_pkg_info(path, message): | |
42 with open(path, "wb") as out: | |
43 BytesGenerator(out, mangle_from_=False, maxheaderlen=0).flatten(message) |