java-manifest-py
Encode/decode Java's META-INF/MANIFEST.MF in Python.
Installation
To install the latest release on PyPI, run:
$ pip install java-manifest
Usage
A MANIFEST is represented by a list of dictionaries, where each dictionary
corresponds to an empty-line delimited section of the MANIFEST and each
dictionary has str keys and either str or bool values.
java_manifest.loads takes a string containing MANIFEST-formatted data and
returns a list of dictionaries, where each dictionary is a section in the
MANIFEST. java_manifest.load does the same, using any typing.TextIO
readable object.
>>> import java_manifest
>>> manifest_str = """
... Name: README-Example-1
... Long-Line: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
... aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
...
... Name: README-Example-2
... Foo: Bar
... """
>>> manifest = java_manifest.loads(manifest_str)
>>> print(manifest)
[{'Name': 'README-Example-1', 'Long-Line': 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'}, {'Name': 'README-Example-2', 'Foo': 'Bar'}]
Similarly, java_manifest.dumps returns a string of MANIFEST-formatted data
from a list of dictionaries, where each dictionary is a section in the
MANIFEST. java_manifest.dump does the same, writing into any typing.TextIO
writable object.
>>> import java_manifest
>>> manifest = [
... {
... "Name": "README-Example",
... "Some-Str": "Some random string",
... },
... ]
>>> manifest_str = java_manifest.dumps(manifest)
>>> print(manifest_str)
Name: README-Example
Some-Str: Some random string
<BLANKLINE>
There is also a from_jar function that finds the META-INF/MANIFEST.MF file
within the jar and java_manifest.loads that.
>>> import java_manifest
>>> manifest = java_manifest.from_jar("test_files/simple.jar")
Custom Encoders/Decoders
Because Java's manifest file format doesn't deal with structured values within
a section, specific uses of the format create ad-hoc encoding/decoding rules
that can convert some structured data into a basic string so it can be encoded
into a manifest and vice versa. The encoder and decoder arguments for
dumping and loading respectively are responsible for handling this. An encoder
and decoder both take in a key-value pair. However, an encoder receives
potentially structured data as the value and returns plain string, while a
decode receives string values and returns potentially structured data.
As we have already see, the default encoder and decoder does no transformation and prevents you from attempting to dump non-string data.
>>> import java_manifest
>>> print(java_manifest.dumps([{"foo": "bar"}]))
foo: bar
>>> print(java_manifest.dumps([{"int": 1}]))
Traceback (most recent call last):
...
ValueError: key 'int' has type <class 'int'> value, expected str
You can however describe more custom encoders that support for example lists of strings.
>>> def encode(key, val):
... if isinstance(val, list):
... return ",".join(val)
... return val
>>> print(java_manifest.dumps([{"foo": "bar", "names": ["alice", "bob", "charlie"]}], encoder=encode))
foo: bar
names: alice,bob,charlie
<BLANKLINE>
Similarly for custom decoders.
>>> import java_manifest
>>> def decode(key, val):
... # In reality you'd probably want to target only specific keys, to avoid
... # messing up random strings containing commas. This is just an example.
... vals = val.split(",")
... if len(vals) == 1:
... return val
... else:
... return vals
>>> manifest = java_manifest.loads("foo: bar\r\nnames: alice,bob,charlie", decoder=decode)
>>> print(manifest)
[{'foo': 'bar', 'names': ['alice', 'bob', 'charlie']}]
Metadata
Release files for java-manifest 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| java-manifest-1.1.0.tar.gz | 5.1 kB | Without provenance | Details for java-manifest-1.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| java_manifest-1.1.0-py3-none-any.whl | Python 3 | none | any | Details for java_manifest-1.1.0-py3-none-any.whl |
Total release size: 9.8 kB
Release files / java-manifest-1.1.0.tar.gz
| Download URL | java-manifest-1.1.0.tar.gz |
|---|---|
| Size | 5.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
98ec8ea6c6677ca2b735de4c2ea0274db910a9876a84e5aacbfc2fef2f35c5ee
|
|
BLAKE2b-256 checksum How to use checksums |
c88b3e4ca8fe744fcf00c6e20c9887e7c2631db2488778cf96167b0f363800d1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.10 CPython/3.8.1 Linux/5.4.0-40-generic
|
Release files / java_manifest-1.1.0-py3-none-any.whl
| Download URL | java_manifest-1.1.0-py3-none-any.whl |
|---|---|
| Size | 4.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c7b11ef34108f93be24f51b9ef22235d9e4d7f19b4dd65ff6bb7a2399da22872
|
|
BLAKE2b-256 checksum How to use checksums |
b66d652a9f0c4f4faf5f0c097d68f1c1bc68466233512ea4531bd6b678537031
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.10 CPython/3.8.1 Linux/5.4.0-40-generic
|
Security for java-manifest 1.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.