pymetadata-core 0.1.0__tar.gz → 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/Cargo.lock +3 -3
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/Cargo.toml +1 -1
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/PKG-INFO +1 -1
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/README.md +3 -3
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/src/archive.rs +85 -1
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/src/lib.rs +1 -1
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/src/manifest.rs +12 -1
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/tests/archive.rs +183 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/python/Cargo.toml +1 -1
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/python/src/archive.rs +38 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/python/pymetadata_core/_core.pyi +42 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/LICENSE +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/Cargo.toml +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/examples/omex_timing.rs +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/src/error.rs +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/src/formats.rs +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/src/formats_table.rs +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/src/location.rs +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/src/wire.rs +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/src/zip/central.rs +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/src/zip/crypto.rs +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/src/zip/eocd.rs +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/src/zip/local.rs +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/src/zip/mod.rs +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/src/zip/reader.rs +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/src/zip/spec.rs +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/src/zip/writer.rs +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/tests/data/formats.json +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/tests/data/manifests/BIOMD0000000001.xml +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/tests/data/manifests/CombineArchiveShowCase.xml +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/tests/data/manifests/CompModels.xml +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/tests/data/manifests/iCGB21FR.xml +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/tests/data/manifests.json +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/tests/data/members.json +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/tests/data/omex/BIOMD0000000001.omex +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/tests/data/omex/CombineArchiveShowCase.omex +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/tests/data/omex/CompModels.omex +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/tests/data/omex/iCGB21FR.omex +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/tests/data/zip/aes.zip +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/tests/data/zip/bad_crc.zip +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/tests/data/zip/bad_offset.zip +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/tests/data/zip/bzip2.zip +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/tests/data/zip/descriptors.zip +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/tests/data/zip/empty_deflate.zip +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/tests/data/zip/encrypted.zip +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/tests/data/zip/encrypted_descriptor.zip +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/tests/data/zip/encrypted_omex.zip +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/tests/data/zip/encrypted_stored.zip +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/tests/data/zip/oversized.zip +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/tests/data/zip/prepended.zip +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/tests/data/zip/prepended_zip64.zip +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/tests/data/zip/stored.zip +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/tests/data/zip/truncated.zip +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/tests/data/zip/understated.zip +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/tests/data/zip/zip64.zip +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/tests/formats_parity.rs +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/tests/manifest_parity.rs +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/tests/write.rs +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/tests/zip_crypto.rs +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/tests/zip_reader.rs +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/python/README.md +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/python/src/errors.rs +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/python/src/lib.rs +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/pyproject.toml +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/python/README.md +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/python/pymetadata_core/__init__.py +0 -0
- {pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/python/pymetadata_core/py.typed +0 -0
|
@@ -121,7 +121,7 @@ dependencies = [
|
|
|
121
121
|
|
|
122
122
|
[[package]]
|
|
123
123
|
name = "pymetadata-core"
|
|
124
|
-
version = "0.
|
|
124
|
+
version = "0.2.0"
|
|
125
125
|
dependencies = [
|
|
126
126
|
"crc32fast",
|
|
127
127
|
"flate2",
|
|
@@ -134,7 +134,7 @@ dependencies = [
|
|
|
134
134
|
|
|
135
135
|
[[package]]
|
|
136
136
|
name = "pymetadata-python"
|
|
137
|
-
version = "0.
|
|
137
|
+
version = "0.2.0"
|
|
138
138
|
dependencies = [
|
|
139
139
|
"pymetadata-core",
|
|
140
140
|
"pyo3",
|
|
@@ -142,7 +142,7 @@ dependencies = [
|
|
|
142
142
|
|
|
143
143
|
[[package]]
|
|
144
144
|
name = "pymetadata-wasm"
|
|
145
|
-
version = "0.
|
|
145
|
+
version = "0.2.0"
|
|
146
146
|
dependencies = [
|
|
147
147
|
"pymetadata-core",
|
|
148
148
|
"serde_json",
|
|
@@ -36,12 +36,12 @@ node js/build.mjs
|
|
|
36
36
|
(cd js && npm test && node prepack.mjs && npm pack --dry-run)
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
-
The python binding is not a default member of the workspace, so it has gates of its own. `uv.lock` pins the development environment, as it does in `pymetadata`: `uv sync --locked` creates it from the lock (and fails instead of re-resolving when the lock no longer matches `pyproject.toml`), builds the extension into it and installs `pytest`, `pymetadata` (the tests cross-check against it) and `ruff`. `uv lock --check` verifies the lock alone. The compiled extension lands in `python/pymetadata_core/` and is gitignored.
|
|
39
|
+
The python binding is not a default member of the workspace, so it has gates of its own. `uv.lock` pins the development environment, as it does in `pymetadata`: `uv sync --locked` creates it from the lock (and fails instead of re-resolving when the lock no longer matches `pyproject.toml`), builds the extension into it and installs `pytest`, `pymetadata` (the tests cross-check against it) and `ruff`. `uv lock --check` verifies the lock alone. The compiled extension lands in `python/pymetadata_core/` and is gitignored. `--reinstall-package pymetadata-core` is there because a plain `uv sync --locked` does not always rebuild the extension, so a local run can pass against a stale `_core` built from older code; a fresh environment, as in continuous integration, needs no such flag.
|
|
40
40
|
|
|
41
41
|
```bash
|
|
42
42
|
cargo clippy -p pymetadata-python --locked --all-targets -- -D warnings
|
|
43
43
|
cargo test -p pymetadata-python --locked
|
|
44
|
-
uv sync --locked
|
|
44
|
+
uv sync --locked --reinstall-package pymetadata-core
|
|
45
45
|
uv run --no-sync ruff check
|
|
46
46
|
uv run --no-sync ruff format --check
|
|
47
47
|
uvx ty@0.0.108 check
|
|
@@ -59,7 +59,7 @@ uv run --no-sync --with 'maturin>=1.16,<2' maturin build --release --sdist -o ta
|
|
|
59
59
|
|
|
60
60
|
The last line builds the source distribution of the release; it takes no `--locked`, since the workspace of an sdist is not the one `Cargo.lock` was resolved for.
|
|
61
61
|
|
|
62
|
-
Continuous integration (`.github/workflows/ci.yml`) runs
|
|
62
|
+
Continuous integration (`.github/workflows/ci.yml`) runs these lists as the jobs `checks`, `wasm`, `js`, `python`, `ruff` and `ty`, which are the required checks of `.github/rulesets/develop.json`, except that its python job runs a plain `uv sync --locked`: a fresh environment needs no `--reinstall-package`. How a release is made is in `docs/release.md`.
|
|
63
63
|
|
|
64
64
|
`crates/core/src/formats_table.rs` and `crates/core/tests/data/formats.json` are generated from `pymetadata.omex` by `scripts/formats_table.py`; run it from a pymetadata checkout with `uv run python`. `crates/core/src/formats.rs` is the hand-written logic over that table.
|
|
65
65
|
|
|
@@ -39,6 +39,21 @@ enum Content {
|
|
|
39
39
|
Replaced(Vec<u8>),
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
/// A member of the source container of an archive, as its central directory describes it.
|
|
43
|
+
///
|
|
44
|
+
/// See [`Archive::members`].
|
|
45
|
+
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
46
|
+
pub struct MemberInfo {
|
|
47
|
+
/// The normalized location of the member, `./` and its name.
|
|
48
|
+
pub location: String,
|
|
49
|
+
/// The number of bytes the member occupies in the container.
|
|
50
|
+
pub compressed_size: u64,
|
|
51
|
+
/// The number of bytes the member holds uncompressed.
|
|
52
|
+
pub uncompressed_size: u64,
|
|
53
|
+
/// The raw zip compression method: 0 stored, 8 deflate.
|
|
54
|
+
pub method: u16,
|
|
55
|
+
}
|
|
56
|
+
|
|
42
57
|
/// A COMBINE archive which reads lazily and edits in memory.
|
|
43
58
|
///
|
|
44
59
|
/// Opening an archive reads the central directory of the zip and inflates the
|
|
@@ -50,6 +65,8 @@ pub struct Archive {
|
|
|
50
65
|
reader: Option<Reader>,
|
|
51
66
|
/// The entries in order.
|
|
52
67
|
manifest: Manifest,
|
|
68
|
+
/// The entries the `manifest.xml` of the container declared, as parsed on opening.
|
|
69
|
+
declared: Vec<Entry>,
|
|
53
70
|
/// The bytes of every entry which has some, by normalized location.
|
|
54
71
|
content: HashMap<String, Content>,
|
|
55
72
|
/// How many members were inflated, which a test reads to see that nothing inflates twice.
|
|
@@ -80,6 +97,7 @@ impl Archive {
|
|
|
80
97
|
Self {
|
|
81
98
|
reader: None,
|
|
82
99
|
manifest: Manifest::default(),
|
|
100
|
+
declared: Vec::new(),
|
|
83
101
|
content: HashMap::new(),
|
|
84
102
|
#[cfg(test)]
|
|
85
103
|
inflations: 0,
|
|
@@ -132,6 +150,7 @@ impl Archive {
|
|
|
132
150
|
let mut archive = Self {
|
|
133
151
|
reader: Some(reader),
|
|
134
152
|
manifest: Manifest::default(),
|
|
153
|
+
declared: Vec::new(),
|
|
135
154
|
content,
|
|
136
155
|
#[cfg(test)]
|
|
137
156
|
inflations: 0,
|
|
@@ -144,7 +163,8 @@ impl Archive {
|
|
|
144
163
|
let xml = archive.inflate_member(index)?;
|
|
145
164
|
let xml = std::str::from_utf8(&xml)
|
|
146
165
|
.map_err(|e| OmexError::Malformed(format!("manifest.xml is not UTF-8: {e}")))?;
|
|
147
|
-
archive.
|
|
166
|
+
archive.declared = Manifest::parse_declared(xml)?;
|
|
167
|
+
archive.manifest = Manifest::from_declared(archive.declared.clone());
|
|
148
168
|
let mut unlisted: Vec<&String> = archive
|
|
149
169
|
.content
|
|
150
170
|
.keys()
|
|
@@ -228,6 +248,70 @@ impl Archive {
|
|
|
228
248
|
}
|
|
229
249
|
}
|
|
230
250
|
|
|
251
|
+
/// The entries the `manifest.xml` of the source container declared, exactly as it did.
|
|
252
|
+
///
|
|
253
|
+
/// One per `content` element in document order. Unlike [`Archive::manifest`] there is no
|
|
254
|
+
/// entry invented for a member the manifest does not list, no required entry prepended
|
|
255
|
+
/// when the document lacks it, and an entry without a member is still there. It is fixed
|
|
256
|
+
/// when the archive is opened: [`Archive::set_entry`] and [`Archive::remove_entry`] do not
|
|
257
|
+
/// change it. A location the manifest declares twice is declared twice here, as parsed,
|
|
258
|
+
/// while [`Archive::manifest`] holds it once, the last declaration winning. Empty for an
|
|
259
|
+
/// archive built with [`Archive::new`].
|
|
260
|
+
pub fn declared_entries(&self) -> &[Entry] {
|
|
261
|
+
&self.declared
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/// The members of the source container, in the order of its central directory.
|
|
265
|
+
///
|
|
266
|
+
/// This describes the container the archive was opened from and nothing else: it is
|
|
267
|
+
/// empty for an archive built with [`Archive::new`], and it does not grow when
|
|
268
|
+
/// [`Archive::set_entry`] stages content, nor shrink on [`Archive::remove_entry`]. Use
|
|
269
|
+
/// [`Archive::has_bytes`] to ask about the content as it is now. A member the manifest
|
|
270
|
+
/// does not list is in here, `./manifest.xml` is, and a directory member and `.` are not.
|
|
271
|
+
/// A name which occurs twice in the container appears once per member, in zip order, while
|
|
272
|
+
/// the archive holds the bytes of the later one.
|
|
273
|
+
///
|
|
274
|
+
/// Nothing is inflated and no member bytes are copied: the central directory was parsed
|
|
275
|
+
/// when the archive was opened, and the one allocation is the returned `Vec`.
|
|
276
|
+
pub fn members(&self) -> Vec<MemberInfo> {
|
|
277
|
+
let Some(reader) = self.reader.as_ref() else {
|
|
278
|
+
return Vec::new();
|
|
279
|
+
};
|
|
280
|
+
reader
|
|
281
|
+
.members()
|
|
282
|
+
.iter()
|
|
283
|
+
.filter(|member| !member.name.ends_with('/'))
|
|
284
|
+
.filter_map(|member| {
|
|
285
|
+
let location = normalize_location(&member.name)
|
|
286
|
+
.expect("from_bytes rejected every member name which does not normalize");
|
|
287
|
+
(location != ARCHIVE_LOCATION).then_some(MemberInfo {
|
|
288
|
+
location,
|
|
289
|
+
compressed_size: member.compressed_size,
|
|
290
|
+
uncompressed_size: member.uncompressed_size,
|
|
291
|
+
method: member.method,
|
|
292
|
+
})
|
|
293
|
+
})
|
|
294
|
+
.collect()
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/// Whether the location has bytes, in the source container or from [`Archive::set_entry`],
|
|
298
|
+
/// without inflating anything.
|
|
299
|
+
///
|
|
300
|
+
/// This is `false` for an entry the manifest lists and no member provides, and for `.` and
|
|
301
|
+
/// `./manifest.xml`, which hold no content in this core. It follows [`Archive::remove_entry`]:
|
|
302
|
+
/// a removed entry has no bytes, although [`Archive::members`] still lists its member. A
|
|
303
|
+
/// member the manifest did not list was added to the manifest when the archive was opened,
|
|
304
|
+
/// so removing it is the same.
|
|
305
|
+
///
|
|
306
|
+
/// # Errors
|
|
307
|
+
///
|
|
308
|
+
/// [`OmexError::Refused`] for a location which cannot be normalized, as for
|
|
309
|
+
/// [`Archive::entry_bytes`] and [`Archive::set_entry`].
|
|
310
|
+
pub fn has_bytes(&self, location: &str) -> Result<bool, OmexError> {
|
|
311
|
+
let key = normalize_location(location)?;
|
|
312
|
+
Ok(self.content.contains_key(&key))
|
|
313
|
+
}
|
|
314
|
+
|
|
231
315
|
/// Add an entry with its bytes, or replace the entry of the same location.
|
|
232
316
|
///
|
|
233
317
|
/// The location is normalized. The bytes of `.` and of `./manifest.xml` are not set: the
|
|
@@ -141,6 +141,12 @@ impl Manifest {
|
|
|
141
141
|
/// a `content` element lacks its `location` or `format` or has a `master` which is not a
|
|
142
142
|
/// boolean; [`OmexError::Refused`] for a location outside of the archive.
|
|
143
143
|
pub fn parse(xml: &str) -> Result<Self, OmexError> {
|
|
144
|
+
Ok(Self::from_declared(Self::parse_declared(xml)?))
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/// The entries of a `manifest.xml` as the document declares them, one per `content`
|
|
148
|
+
/// element in document order, with the errors of [`Manifest::parse`].
|
|
149
|
+
pub(crate) fn parse_declared(xml: &str) -> Result<Vec<Entry>, OmexError> {
|
|
144
150
|
let document = roxmltree::Document::parse(xml)
|
|
145
151
|
.map_err(|e| OmexError::Malformed(format!("manifest is not valid XML: {e}")))?;
|
|
146
152
|
let root = document.root_element();
|
|
@@ -168,6 +174,11 @@ impl Manifest {
|
|
|
168
174
|
.map_or(Ok(false), parse_master)?,
|
|
169
175
|
)?);
|
|
170
176
|
}
|
|
177
|
+
Ok(parsed)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/// The manifest of declared entries, with the two required ones first when they are missing.
|
|
181
|
+
pub(crate) fn from_declared(parsed: Vec<Entry>) -> Self {
|
|
171
182
|
let mut manifest = Manifest {
|
|
172
183
|
entries: Vec::new(),
|
|
173
184
|
index: HashMap::new(),
|
|
@@ -183,7 +194,7 @@ impl Manifest {
|
|
|
183
194
|
for entry in parsed {
|
|
184
195
|
manifest.insert(entry);
|
|
185
196
|
}
|
|
186
|
-
|
|
197
|
+
manifest
|
|
187
198
|
}
|
|
188
199
|
|
|
189
200
|
/// Serialize the manifest to the content of a `manifest.xml`.
|
|
@@ -356,3 +356,186 @@ fn set_max_inflated_size_limits_a_member() {
|
|
|
356
356
|
archive.set_max_inflated_size(100);
|
|
357
357
|
assert_eq!(archive.entry_bytes("./extra.txt").unwrap(), b"extra");
|
|
358
358
|
}
|
|
359
|
+
|
|
360
|
+
#[test]
|
|
361
|
+
fn members_are_the_zip_members_in_order_with_their_sizes() {
|
|
362
|
+
let archive = Archive::from_bytes(&fixture("iCGB21FR.omex")).unwrap();
|
|
363
|
+
let members = archive.members();
|
|
364
|
+
assert_eq!(members.len(), 22);
|
|
365
|
+
assert_eq!(members[0].location, "./manifest.xml");
|
|
366
|
+
assert!(members.iter().all(|m| m.location.starts_with("./")));
|
|
367
|
+
assert!(
|
|
368
|
+
members
|
|
369
|
+
.iter()
|
|
370
|
+
.any(|m| m.location == "./__MACOSX/._manifest.xml")
|
|
371
|
+
);
|
|
372
|
+
assert!(
|
|
373
|
+
members
|
|
374
|
+
.iter()
|
|
375
|
+
.filter(|m| m.method == 8)
|
|
376
|
+
.all(|m| m.compressed_size > 0)
|
|
377
|
+
);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
#[test]
|
|
381
|
+
fn members_of_an_archive_built_from_nothing_are_empty() {
|
|
382
|
+
assert!(Archive::new().members().is_empty());
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
#[test]
|
|
386
|
+
fn has_bytes_is_false_for_a_manifest_entry_without_a_member() {
|
|
387
|
+
let archive = Archive::from_bytes(&fixture("iCGB21FR.omex")).unwrap();
|
|
388
|
+
assert!(archive.entry("./iCGB21FR_memote.html").is_some());
|
|
389
|
+
assert!(!archive.has_bytes("./iCGB21FR_memote.html").unwrap());
|
|
390
|
+
assert!(archive.has_bytes("iCGB21FR.xml").unwrap());
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
#[test]
|
|
394
|
+
fn has_bytes_is_true_after_set_entry_on_an_archive_built_from_nothing() {
|
|
395
|
+
let mut archive = Archive::new();
|
|
396
|
+
let entry = Entry {
|
|
397
|
+
location: "./a.txt".to_string(),
|
|
398
|
+
format: guess_format("txt", &[]).to_string(),
|
|
399
|
+
master: false,
|
|
400
|
+
};
|
|
401
|
+
archive.set_entry(entry, b"x".to_vec()).unwrap();
|
|
402
|
+
assert!(archive.has_bytes("a.txt").unwrap());
|
|
403
|
+
assert!(archive.members().is_empty());
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
#[test]
|
|
407
|
+
fn has_bytes_refuses_a_location_outside_of_the_archive() {
|
|
408
|
+
assert!(matches!(
|
|
409
|
+
Archive::new().has_bytes("../x"),
|
|
410
|
+
Err(OmexError::Refused(_))
|
|
411
|
+
));
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
#[test]
|
|
415
|
+
fn has_bytes_is_false_for_the_derived_locations() {
|
|
416
|
+
let archive = Archive::from_bytes(&fixture("iCGB21FR.omex")).unwrap();
|
|
417
|
+
assert!(!archive.has_bytes(".").unwrap());
|
|
418
|
+
assert!(!archive.has_bytes("./manifest.xml").unwrap());
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
#[test]
|
|
422
|
+
fn a_duplicate_member_name_appears_once_per_member() {
|
|
423
|
+
let bytes = stored_zip(&[
|
|
424
|
+
("manifest.xml", MANIFEST),
|
|
425
|
+
("a.txt", b"one"),
|
|
426
|
+
("a.txt", b"two"),
|
|
427
|
+
]);
|
|
428
|
+
let mut archive = Archive::from_bytes(&bytes).unwrap();
|
|
429
|
+
let members = archive.members();
|
|
430
|
+
let a: Vec<_> = members.iter().filter(|m| m.location == "./a.txt").collect();
|
|
431
|
+
assert_eq!(a.len(), 2);
|
|
432
|
+
assert!(archive.has_bytes("a.txt").unwrap());
|
|
433
|
+
assert_eq!(archive.entry_bytes("a.txt").unwrap(), b"two");
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
#[test]
|
|
437
|
+
fn has_bytes_follows_remove_entry_while_members_does_not_shrink() {
|
|
438
|
+
let mut archive = Archive::from_bytes(&fixture("iCGB21FR.omex")).unwrap();
|
|
439
|
+
let before = archive.members();
|
|
440
|
+
assert!(archive.has_bytes("./iCGB21FR.xml").unwrap());
|
|
441
|
+
archive.remove_entry("./iCGB21FR.xml").unwrap();
|
|
442
|
+
assert!(!archive.has_bytes("./iCGB21FR.xml").unwrap());
|
|
443
|
+
assert_eq!(archive.members(), before);
|
|
444
|
+
// a member the manifest did not list was added to it on opening, so it is the same
|
|
445
|
+
let unlisted = "./__MACOSX/._manifest.xml";
|
|
446
|
+
assert!(archive.has_bytes(unlisted).unwrap());
|
|
447
|
+
archive.remove_entry(unlisted).unwrap();
|
|
448
|
+
assert!(!archive.has_bytes(unlisted).unwrap());
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
#[test]
|
|
452
|
+
fn declared_entries_are_the_manifest_of_the_container_without_the_invented_ones() {
|
|
453
|
+
let bytes = fixture("iCGB21FR.omex");
|
|
454
|
+
let archive = Archive::from_bytes(&bytes).unwrap();
|
|
455
|
+
let declared: Vec<&str> = archive
|
|
456
|
+
.declared_entries()
|
|
457
|
+
.iter()
|
|
458
|
+
.map(|e| e.location.as_str())
|
|
459
|
+
.collect();
|
|
460
|
+
// the expectation is read from the manifest text with a crude split, deliberately not with
|
|
461
|
+
// `Manifest::parse`, which would check the parser against itself
|
|
462
|
+
let zip = zip_manifest(&bytes);
|
|
463
|
+
let expected: Vec<String> = zip
|
|
464
|
+
.split("location=\"")
|
|
465
|
+
.skip(1)
|
|
466
|
+
.map(|rest| {
|
|
467
|
+
let location = rest.split('"').next().unwrap();
|
|
468
|
+
pymetadata_core::normalize_location(location).unwrap()
|
|
469
|
+
})
|
|
470
|
+
.collect();
|
|
471
|
+
assert_eq!(declared, expected);
|
|
472
|
+
assert!(declared.contains(&"./iCGB21FR_memote.html"));
|
|
473
|
+
assert!(!declared.contains(&"./__MACOSX/._manifest.xml"));
|
|
474
|
+
assert!(declared.len() < archive.manifest().entries().len());
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
/// The text of the `manifest.xml` of an archive, read through the zip reader.
|
|
478
|
+
fn zip_manifest(bytes: &[u8]) -> String {
|
|
479
|
+
let reader = pymetadata_core::zip::Reader::new(bytes.to_vec()).unwrap();
|
|
480
|
+
let member = reader
|
|
481
|
+
.members()
|
|
482
|
+
.iter()
|
|
483
|
+
.find(|m| m.name == "manifest.xml")
|
|
484
|
+
.unwrap();
|
|
485
|
+
String::from_utf8(reader.inflate(member).unwrap()).unwrap()
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
#[test]
|
|
489
|
+
fn declared_entries_do_not_prepend_the_required_entries() {
|
|
490
|
+
let archive = Archive::from_bytes(&fixture("BIOMD0000000001.omex")).unwrap();
|
|
491
|
+
let declared = archive.declared_entries();
|
|
492
|
+
assert!(
|
|
493
|
+
declared
|
|
494
|
+
.iter()
|
|
495
|
+
.all(|e| e.location != "." && e.location != "./manifest.xml")
|
|
496
|
+
);
|
|
497
|
+
let text = zip_manifest(&fixture("BIOMD0000000001.omex"));
|
|
498
|
+
assert_eq!(declared.len(), text.matches("<content ").count());
|
|
499
|
+
let entries = archive.manifest().entries();
|
|
500
|
+
assert!(entries.iter().any(|e| e.location == "."));
|
|
501
|
+
assert!(entries.iter().any(|e| e.location == "./manifest.xml"));
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
#[test]
|
|
505
|
+
fn declared_entries_are_unchanged_by_set_entry_and_remove_entry() {
|
|
506
|
+
let mut archive = Archive::from_bytes(&fixture("iCGB21FR.omex")).unwrap();
|
|
507
|
+
let before = archive.declared_entries().to_vec();
|
|
508
|
+
let entry = Entry {
|
|
509
|
+
location: "./new.txt".to_string(),
|
|
510
|
+
format: guess_format("txt", &[]).to_string(),
|
|
511
|
+
master: false,
|
|
512
|
+
};
|
|
513
|
+
archive.set_entry(entry, b"x".to_vec()).unwrap();
|
|
514
|
+
archive.remove_entry("./iCGB21FR.xml").unwrap();
|
|
515
|
+
assert_eq!(archive.declared_entries(), before.as_slice());
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
#[test]
|
|
519
|
+
fn declared_entries_of_an_archive_built_from_nothing_are_empty() {
|
|
520
|
+
assert!(Archive::new().declared_entries().is_empty());
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
#[test]
|
|
524
|
+
fn a_location_declared_twice_is_declared_twice_and_listed_once() {
|
|
525
|
+
let manifest = br#"<?xml version="1.0"?>
|
|
526
|
+
<omexManifest xmlns="http://identifiers.org/combine.specifications/omex-manifest">
|
|
527
|
+
<content location="./model.xml" format="http://identifiers.org/combine.specifications/sbml" master="false"/>
|
|
528
|
+
<content location="model.xml" format="http://identifiers.org/combine.specifications/sbml" master="true"/>
|
|
529
|
+
</omexManifest>"#;
|
|
530
|
+
let bytes = stored_zip(&[("manifest.xml", manifest), ("model.xml", b"<sbml/>")]);
|
|
531
|
+
let archive = Archive::from_bytes(&bytes).unwrap();
|
|
532
|
+
assert_eq!(archive.declared_entries().len(), 2);
|
|
533
|
+
let effective: Vec<_> = archive
|
|
534
|
+
.manifest()
|
|
535
|
+
.entries()
|
|
536
|
+
.iter()
|
|
537
|
+
.filter(|e| e.location == "./model.xml")
|
|
538
|
+
.collect();
|
|
539
|
+
assert_eq!(effective.len(), 1);
|
|
540
|
+
assert!(effective[0].master);
|
|
541
|
+
}
|
|
@@ -24,7 +24,7 @@ crate-type = ["cdylib", "rlib"]
|
|
|
24
24
|
extension-module = ["pyo3/extension-module"]
|
|
25
25
|
|
|
26
26
|
[dependencies]
|
|
27
|
-
pymetadata-core = { path = "../core", version = "0.
|
|
27
|
+
pymetadata-core = { path = "../core", version = "0.2.0" }
|
|
28
28
|
pyo3.workspace = true
|
|
29
29
|
|
|
30
30
|
[lints]
|
|
@@ -86,6 +86,44 @@ impl Archive {
|
|
|
86
86
|
.collect())
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
+
/// The entries the `manifest.xml` of the source container declared, as
|
|
90
|
+
/// `(location, format, master)` in document order, without the entries invented for
|
|
91
|
+
/// unlisted members. A location declared twice is listed twice. Fixed on opening, so
|
|
92
|
+
/// `set_entry` and `remove_entry` do not change it; empty for an archive built from
|
|
93
|
+
/// nothing.
|
|
94
|
+
#[getter]
|
|
95
|
+
fn declared_entries(slf: &Bound<'_, Self>) -> PyResult<Vec<(String, String, bool)>> {
|
|
96
|
+
let this = slf.try_borrow().map_err(busy)?;
|
|
97
|
+
Ok(this
|
|
98
|
+
.inner
|
|
99
|
+
.declared_entries()
|
|
100
|
+
.iter()
|
|
101
|
+
.map(|entry| (entry.location.clone(), entry.format.clone(), entry.master))
|
|
102
|
+
.collect())
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/// The members of the source container as
|
|
106
|
+
/// `(location, compressed size, uncompressed size, method)`, in zip order.
|
|
107
|
+
///
|
|
108
|
+
/// Nothing is inflated. It is empty for an archive built from nothing and does not change
|
|
109
|
+
/// with `set_entry`.
|
|
110
|
+
#[getter]
|
|
111
|
+
fn members(slf: &Bound<'_, Self>) -> PyResult<Vec<(String, u64, u64, u16)>> {
|
|
112
|
+
let this = slf.try_borrow().map_err(busy)?;
|
|
113
|
+
Ok(this
|
|
114
|
+
.inner
|
|
115
|
+
.members()
|
|
116
|
+
.into_iter()
|
|
117
|
+
.map(|m| (m.location, m.compressed_size, m.uncompressed_size, m.method))
|
|
118
|
+
.collect())
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/// Whether the location has bytes, in the source container or from `set_entry`.
|
|
122
|
+
fn has_bytes(slf: &Bound<'_, Self>, location: &str) -> PyResult<bool> {
|
|
123
|
+
let this = slf.try_borrow().map_err(busy)?;
|
|
124
|
+
this.inner.has_bytes(location).map_err(to_py_err)
|
|
125
|
+
}
|
|
126
|
+
|
|
89
127
|
/// The `manifest.xml` the archive is written with.
|
|
90
128
|
fn manifest_xml(slf: &Bound<'_, Self>) -> PyResult<String> {
|
|
91
129
|
let this = slf.try_borrow().map_err(busy)?;
|
|
@@ -60,6 +60,48 @@ class Archive:
|
|
|
60
60
|
ArchiveBusyError: if another thread is using this archive.
|
|
61
61
|
"""
|
|
62
62
|
|
|
63
|
+
@property
|
|
64
|
+
def declared_entries(self) -> list[tuple[str, str, bool]]:
|
|
65
|
+
"""The entries the `manifest.xml` of the source container declared.
|
|
66
|
+
|
|
67
|
+
Each is `(location, format, master)`, in document order, exactly as declared: no
|
|
68
|
+
entry for a member the manifest does not list, no required entry added, and an
|
|
69
|
+
entry without a member is kept. It is fixed when the archive is opened and does not
|
|
70
|
+
change with `set_entry` or `remove_entry`. A location the manifest declares twice
|
|
71
|
+
is listed twice, as parsed, while `entries` holds it once, the last declaration
|
|
72
|
+
winning. It is empty for `Archive()`.
|
|
73
|
+
|
|
74
|
+
Raises:
|
|
75
|
+
ArchiveBusyError: if another thread is using this archive.
|
|
76
|
+
"""
|
|
77
|
+
|
|
78
|
+
@property
|
|
79
|
+
def members(self) -> list[tuple[str, int, int, int]]:
|
|
80
|
+
"""The members of the source container, in zip order.
|
|
81
|
+
|
|
82
|
+
Each is `(location, compressed size, uncompressed size, method)`, with the raw zip
|
|
83
|
+
method number (0 stored, 8 deflate). Nothing is inflated. This describes the
|
|
84
|
+
container the archive was opened from: it is empty for `Archive()` and does not
|
|
85
|
+
change with `set_entry`. Use `has_bytes` for the content as it is now.
|
|
86
|
+
|
|
87
|
+
Raises:
|
|
88
|
+
ArchiveBusyError: if another thread is using this archive.
|
|
89
|
+
"""
|
|
90
|
+
|
|
91
|
+
def has_bytes(self, location: str) -> bool:
|
|
92
|
+
"""Return whether the location has bytes, from the container or `set_entry`.
|
|
93
|
+
|
|
94
|
+
Nothing is inflated. It is `False` for a listed entry no member provides, and for
|
|
95
|
+
`.` and `./manifest.xml`.
|
|
96
|
+
|
|
97
|
+
Args:
|
|
98
|
+
location: the location, in any spelling `normalize_location` accepts.
|
|
99
|
+
|
|
100
|
+
Raises:
|
|
101
|
+
OmexError: if the location is outside of the archive.
|
|
102
|
+
ArchiveBusyError: if another thread is using this archive.
|
|
103
|
+
"""
|
|
104
|
+
|
|
63
105
|
def __repr__(self) -> str:
|
|
64
106
|
"""Return the number of entries, e.g. `Archive(2 entries)`.
|
|
65
107
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/tests/data/manifests/BIOMD0000000001.xml
RENAMED
|
File without changes
|
|
File without changes
|
{pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/tests/data/manifests/CompModels.xml
RENAMED
|
File without changes
|
{pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/tests/data/manifests/iCGB21FR.xml
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/tests/data/omex/BIOMD0000000001.omex
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/tests/data/zip/empty_deflate.zip
RENAMED
|
File without changes
|
|
File without changes
|
{pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/tests/data/zip/encrypted_descriptor.zip
RENAMED
|
File without changes
|
{pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/tests/data/zip/encrypted_omex.zip
RENAMED
|
File without changes
|
{pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/tests/data/zip/encrypted_stored.zip
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pymetadata_core-0.1.0 → pymetadata_core-0.2.0}/crates/core/tests/data/zip/prepended_zip64.zip
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|