rs-parsepatch 0.4.6__tar.gz → 0.4.7__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.
- {rs_parsepatch-0.4.6 → rs_parsepatch-0.4.7}/Cargo.lock +29 -30
- {rs_parsepatch-0.4.6 → rs_parsepatch-0.4.7}/Cargo.toml +2 -2
- {rs_parsepatch-0.4.6 → rs_parsepatch-0.4.7}/PKG-INFO +1 -1
- {rs_parsepatch-0.4.6 → rs_parsepatch-0.4.7}/pyproject.toml +1 -1
- rs_parsepatch-0.4.7/requirements-dev.txt +3 -0
- {rs_parsepatch-0.4.6 → rs_parsepatch-0.4.7}/src/common.rs +16 -5
- {rs_parsepatch-0.4.6 → rs_parsepatch-0.4.7}/src/init.rs +5 -5
- {rs_parsepatch-0.4.6 → rs_parsepatch-0.4.7}/tests/test_parsepatch.py +36 -0
- rs_parsepatch-0.4.6/requirements-dev.txt +0 -3
- {rs_parsepatch-0.4.6 → rs_parsepatch-0.4.7}/README.md +0 -0
- {rs_parsepatch-0.4.6 → rs_parsepatch-0.4.7}/src/counts.rs +0 -0
- {rs_parsepatch-0.4.6 → rs_parsepatch-0.4.7}/src/diffs.rs +0 -0
- {rs_parsepatch-0.4.6 → rs_parsepatch-0.4.7}/src/lib.rs +0 -0
- {rs_parsepatch-0.4.6 → rs_parsepatch-0.4.7}/src/lines.rs +0 -0
- {rs_parsepatch-0.4.6 → rs_parsepatch-0.4.7}/tests/__init__.py +0 -0
- {rs_parsepatch-0.4.6 → rs_parsepatch-0.4.7}/tests/patches/77ec8a41ee73.patch +0 -0
- {rs_parsepatch-0.4.6 → rs_parsepatch-0.4.7}/tests/patches/7dabae5e261a.patch +0 -0
- {rs_parsepatch-0.4.6 → rs_parsepatch-0.4.7}/tests/patches/7e60ad275b73.patch +0 -0
- {rs_parsepatch-0.4.6 → rs_parsepatch-0.4.7}/tests/patches/81d3e4a2f3f3.patch +0 -0
- {rs_parsepatch-0.4.6 → rs_parsepatch-0.4.7}/tests/patches/b184c87f7606.patch +0 -0
- {rs_parsepatch-0.4.6 → rs_parsepatch-0.4.7}/tests/patches/c4c0ad8b3eaa.patch +0 -0
- {rs_parsepatch-0.4.6 → rs_parsepatch-0.4.7}/tests/patches/c58e9e70f971.patch +0 -0
- {rs_parsepatch-0.4.6 → rs_parsepatch-0.4.7}/tests/patches/c6f9187b0b2e.patch +0 -0
- {rs_parsepatch-0.4.6 → rs_parsepatch-0.4.7}/tests/patches/d4f80c4ba719.patch +0 -0
- {rs_parsepatch-0.4.6 → rs_parsepatch-0.4.7}/tests/patches/d7a700707ddb.patch +0 -0
- {rs_parsepatch-0.4.6 → rs_parsepatch-0.4.7}/tests/patches/f045ac9f76cf.patch +0 -0
- {rs_parsepatch-0.4.6 → rs_parsepatch-0.4.7}/tests/patches/no_git_header.patch +0 -0
|
@@ -10,21 +10,21 @@ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
|
|
10
10
|
|
|
11
11
|
[[package]]
|
|
12
12
|
name = "libc"
|
|
13
|
-
version = "0.2.
|
|
13
|
+
version = "0.2.191"
|
|
14
14
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
15
|
-
checksum = "
|
|
15
|
+
checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"
|
|
16
16
|
|
|
17
17
|
[[package]]
|
|
18
18
|
name = "log"
|
|
19
|
-
version = "0.4.
|
|
19
|
+
version = "0.4.35"
|
|
20
20
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
21
|
-
checksum = "
|
|
21
|
+
checksum = "5d15f86d12da44cd8d4ec3c73984537eb7f4cadcb9776a575a0a8a05ca11005c"
|
|
22
22
|
|
|
23
23
|
[[package]]
|
|
24
24
|
name = "once_cell"
|
|
25
|
-
version = "1.21.
|
|
25
|
+
version = "1.21.4"
|
|
26
26
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
27
|
-
checksum = "
|
|
27
|
+
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
|
28
28
|
|
|
29
29
|
[[package]]
|
|
30
30
|
name = "parsepatch"
|
|
@@ -37,24 +37,24 @@ dependencies = [
|
|
|
37
37
|
|
|
38
38
|
[[package]]
|
|
39
39
|
name = "portable-atomic"
|
|
40
|
-
version = "1.
|
|
40
|
+
version = "1.15.0"
|
|
41
41
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
42
|
-
checksum = "
|
|
42
|
+
checksum = "05c8b63e8d9609db387f0324918f81d68fe27748f084ef092fb35954d0539a85"
|
|
43
43
|
|
|
44
44
|
[[package]]
|
|
45
45
|
name = "proc-macro2"
|
|
46
|
-
version = "1.0.
|
|
46
|
+
version = "1.0.107"
|
|
47
47
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
48
|
-
checksum = "
|
|
48
|
+
checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
|
|
49
49
|
dependencies = [
|
|
50
50
|
"unicode-ident",
|
|
51
51
|
]
|
|
52
52
|
|
|
53
53
|
[[package]]
|
|
54
54
|
name = "pyo3"
|
|
55
|
-
version = "0.
|
|
55
|
+
version = "0.30.1"
|
|
56
56
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
57
|
-
checksum = "
|
|
57
|
+
checksum = "229ca13b8a15bb0d1487b81ab975bfcd97513416499a8312011b6036e42e0de4"
|
|
58
58
|
dependencies = [
|
|
59
59
|
"libc",
|
|
60
60
|
"once_cell",
|
|
@@ -66,18 +66,18 @@ dependencies = [
|
|
|
66
66
|
|
|
67
67
|
[[package]]
|
|
68
68
|
name = "pyo3-build-config"
|
|
69
|
-
version = "0.
|
|
69
|
+
version = "0.30.1"
|
|
70
70
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
71
|
-
checksum = "
|
|
71
|
+
checksum = "70130e2b6dd1ee589a8788026a429561ca5c40fa7a2fa7914c2282eddae24700"
|
|
72
72
|
dependencies = [
|
|
73
73
|
"target-lexicon",
|
|
74
74
|
]
|
|
75
75
|
|
|
76
76
|
[[package]]
|
|
77
77
|
name = "pyo3-ffi"
|
|
78
|
-
version = "0.
|
|
78
|
+
version = "0.30.1"
|
|
79
79
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
80
|
-
checksum = "
|
|
80
|
+
checksum = "5e7ff73c555c286d212d4ce7e5fbda845a973c4f61bd5f160f5f2c3c2a04d1c4"
|
|
81
81
|
dependencies = [
|
|
82
82
|
"libc",
|
|
83
83
|
"pyo3-build-config",
|
|
@@ -85,9 +85,9 @@ dependencies = [
|
|
|
85
85
|
|
|
86
86
|
[[package]]
|
|
87
87
|
name = "pyo3-macros"
|
|
88
|
-
version = "0.
|
|
88
|
+
version = "0.30.1"
|
|
89
89
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
90
|
-
checksum = "
|
|
90
|
+
checksum = "c46d2e5862c7bb8207e3b639f713dda3c499933444784154c11d013c5a691b60"
|
|
91
91
|
dependencies = [
|
|
92
92
|
"proc-macro2",
|
|
93
93
|
"pyo3-macros-backend",
|
|
@@ -97,29 +97,28 @@ dependencies = [
|
|
|
97
97
|
|
|
98
98
|
[[package]]
|
|
99
99
|
name = "pyo3-macros-backend"
|
|
100
|
-
version = "0.
|
|
100
|
+
version = "0.30.1"
|
|
101
101
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
102
|
-
checksum = "
|
|
102
|
+
checksum = "38b89f066f2ae72a2aef52d1537ca2fcd104440ebfadee06e97aa90738a25b9b"
|
|
103
103
|
dependencies = [
|
|
104
104
|
"heck",
|
|
105
105
|
"proc-macro2",
|
|
106
|
-
"pyo3-build-config",
|
|
107
106
|
"quote",
|
|
108
107
|
"syn",
|
|
109
108
|
]
|
|
110
109
|
|
|
111
110
|
[[package]]
|
|
112
111
|
name = "quote"
|
|
113
|
-
version = "1.0.
|
|
112
|
+
version = "1.0.47"
|
|
114
113
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
115
|
-
checksum = "
|
|
114
|
+
checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
|
|
116
115
|
dependencies = [
|
|
117
116
|
"proc-macro2",
|
|
118
117
|
]
|
|
119
118
|
|
|
120
119
|
[[package]]
|
|
121
120
|
name = "rs_parsepatch"
|
|
122
|
-
version = "0.4.
|
|
121
|
+
version = "0.4.7"
|
|
123
122
|
dependencies = [
|
|
124
123
|
"parsepatch",
|
|
125
124
|
"pyo3",
|
|
@@ -127,9 +126,9 @@ dependencies = [
|
|
|
127
126
|
|
|
128
127
|
[[package]]
|
|
129
128
|
name = "syn"
|
|
130
|
-
version = "
|
|
129
|
+
version = "3.0.10"
|
|
131
130
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
132
|
-
checksum = "
|
|
131
|
+
checksum = "4ae9ccbea3a7b0b09443036490c8f34a8b1b760fd345e5c0dae0aac718faea79"
|
|
133
132
|
dependencies = [
|
|
134
133
|
"proc-macro2",
|
|
135
134
|
"quote",
|
|
@@ -138,12 +137,12 @@ dependencies = [
|
|
|
138
137
|
|
|
139
138
|
[[package]]
|
|
140
139
|
name = "target-lexicon"
|
|
141
|
-
version = "0.13.
|
|
140
|
+
version = "0.13.6"
|
|
142
141
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
143
|
-
checksum = "
|
|
142
|
+
checksum = "8c447be3a2abfa84b2d91680c56600bd6b2873866de27b36ec911be705e291da"
|
|
144
143
|
|
|
145
144
|
[[package]]
|
|
146
145
|
name = "unicode-ident"
|
|
147
|
-
version = "1.0.
|
|
146
|
+
version = "1.0.27"
|
|
148
147
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
149
|
-
checksum = "
|
|
148
|
+
checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "rs_parsepatch"
|
|
3
|
-
version = "0.4.
|
|
3
|
+
version = "0.4.7"
|
|
4
4
|
authors = ["calixteman <cdenizet@mozilla.com>"]
|
|
5
5
|
edition = "2018"
|
|
6
6
|
license = "MPL-2.0"
|
|
@@ -17,5 +17,5 @@ crate-type = ["cdylib"]
|
|
|
17
17
|
parsepatch = "0.3"
|
|
18
18
|
|
|
19
19
|
[dependencies.pyo3]
|
|
20
|
-
version = "0.
|
|
20
|
+
version = "0.30"
|
|
21
21
|
features = ["extension-module"]
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
use parsepatch::{BinaryHunk, FileMode, FileOp};
|
|
2
|
+
use pyo3::intern;
|
|
2
3
|
use pyo3::prelude::*;
|
|
3
4
|
use pyo3::types::PyDict;
|
|
4
5
|
use pyo3::types::{PyByteArray, PyBytes, PyString};
|
|
@@ -111,15 +112,25 @@ pub fn set_info(
|
|
|
111
112
|
}
|
|
112
113
|
|
|
113
114
|
#[inline(always)]
|
|
114
|
-
pub(crate) fn get_bytes<'a>(py: Python<'a>, bytes: &'a Py<PyAny>) -> Option<Bytes<'a
|
|
115
|
+
pub(crate) fn get_bytes<'a>(py: Python<'a>, bytes: &'a Py<PyAny>) -> PyResult<Option<Bytes<'a>>> {
|
|
115
116
|
let bytes = bytes.bind(py);
|
|
116
|
-
if let Ok(bytes) = bytes.cast::<PyBytes>() {
|
|
117
|
+
Ok(if let Ok(bytes) = bytes.cast::<PyBytes>() {
|
|
117
118
|
Some(Bytes::Slice(bytes.as_bytes()))
|
|
118
|
-
} else if let Ok(
|
|
119
|
-
|
|
119
|
+
} else if let Ok(string) = bytes.cast::<PyString>() {
|
|
120
|
+
match string.to_str() {
|
|
121
|
+
Ok(s) => Some(Bytes::Slice(s.as_bytes())),
|
|
122
|
+
Err(_) => {
|
|
123
|
+
// The string isn't valid UTF-8: it likely contains lone surrogates
|
|
124
|
+
// see (bug 2056454). Any other invalid string raises an
|
|
125
|
+
// UnicodeEncodeError.
|
|
126
|
+
let encoded =
|
|
127
|
+
string.call_method1(intern!(py, "encode"), ("utf-8", "surrogateescape"))?;
|
|
128
|
+
Some(Bytes::Vec(encoded.cast::<PyBytes>()?.as_bytes().to_vec()))
|
|
129
|
+
}
|
|
130
|
+
}
|
|
120
131
|
} else if let Ok(bytes) = bytes.cast::<PyByteArray>() {
|
|
121
132
|
Some(Bytes::Vec(bytes.to_vec()))
|
|
122
133
|
} else {
|
|
123
134
|
None
|
|
124
|
-
}
|
|
135
|
+
})
|
|
125
136
|
}
|
|
@@ -16,7 +16,7 @@ macro_rules! parse_patch {
|
|
|
16
16
|
($py:path, $bytes:path, $v:ident) => {{
|
|
17
17
|
let mut patch = crate::$v::PyPatch::new($py);
|
|
18
18
|
|
|
19
|
-
if let Some(bytes) = crate::common::get_bytes($py, &$bytes) {
|
|
19
|
+
if let Some(bytes) = crate::common::get_bytes($py, &$bytes)? {
|
|
20
20
|
match bytes {
|
|
21
21
|
crate::common::Bytes::Slice(bytes) => {
|
|
22
22
|
PatchReader::by_buf(bytes, &mut patch).map_err(|e| PPError(e))?
|
|
@@ -46,16 +46,16 @@ fn get_diffs(
|
|
|
46
46
|
kwargs: Option<&Bound<'_, PyDict>>,
|
|
47
47
|
) -> PyResult<Py<PyAny>> {
|
|
48
48
|
let hunks = if let Some(kwargs) = kwargs {
|
|
49
|
-
kwargs
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
kwargs
|
|
50
|
+
.get_item("hunks")?
|
|
51
|
+
.is_some_and(|h| h.cast::<PyBool>().is_ok_and(|h| h.is_true()))
|
|
52
52
|
} else {
|
|
53
53
|
false
|
|
54
54
|
};
|
|
55
55
|
|
|
56
56
|
let mut patch = crate::diffs::PyPatch::new(py, hunks);
|
|
57
57
|
|
|
58
|
-
if let Some(bytes) = crate::common::get_bytes(py, &bytes) {
|
|
58
|
+
if let Some(bytes) = crate::common::get_bytes(py, &bytes)? {
|
|
59
59
|
match bytes {
|
|
60
60
|
crate::common::Bytes::Slice(bytes) => {
|
|
61
61
|
PatchReader::by_buf(bytes, &mut patch).map_err(PPError)?
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import copy
|
|
6
6
|
import os
|
|
7
|
+
import pytest
|
|
7
8
|
import rs_parsepatch as pp
|
|
8
9
|
import whatthepatch as wp
|
|
9
10
|
|
|
@@ -74,6 +75,11 @@ def read(patch):
|
|
|
74
75
|
else:
|
|
75
76
|
assert ppd["renamed_from"] is None
|
|
76
77
|
|
|
78
|
+
if ppd["binary"]:
|
|
79
|
+
# whatthepatch decodes the binary hunks but we only report their sizes
|
|
80
|
+
assert not ppd["lines"]
|
|
81
|
+
continue
|
|
82
|
+
|
|
77
83
|
if not wpd.changes:
|
|
78
84
|
assert not ppd["lines"]
|
|
79
85
|
continue
|
|
@@ -102,3 +108,33 @@ def test_pp():
|
|
|
102
108
|
for patch in get_patch():
|
|
103
109
|
patch = bytearray(patch)
|
|
104
110
|
read(patch)
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def test_non_utf8_str():
|
|
114
|
+
# Bug 2056454: a patch with non UTF-8 data decoded with `surrogateescape`
|
|
115
|
+
# contains lone surrogates.
|
|
116
|
+
patch = (
|
|
117
|
+
b"diff --git a/f.der b/f.der\n"
|
|
118
|
+
b"new file mode 100644\n"
|
|
119
|
+
b"--- /dev/null\n"
|
|
120
|
+
b"+++ b/f.der\n"
|
|
121
|
+
b"@@ -0,0 +1 @@\n"
|
|
122
|
+
b"+\x06\x07*\x86H\xce=\x02\x01\n"
|
|
123
|
+
)
|
|
124
|
+
escaped = patch.decode("utf-8", errors="surrogateescape")
|
|
125
|
+
|
|
126
|
+
assert pp.get_diffs(escaped) == pp.get_diffs(patch)
|
|
127
|
+
assert pp.get_diffs(escaped, hunks=True) == pp.get_diffs(patch, hunks=True)
|
|
128
|
+
assert pp.get_counts(escaped) == pp.get_counts(patch)
|
|
129
|
+
assert pp.get_lines(escaped) == pp.get_lines(patch)
|
|
130
|
+
|
|
131
|
+
diffs = pp.get_diffs(escaped)
|
|
132
|
+
assert diffs[0]["lines"] == [(None, 1, b"\x06\x07*\x86H\xce=\x02\x01")]
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def test_invalid_str():
|
|
136
|
+
# A lone surrogate which can't come from "surrogateescape" must raise an
|
|
137
|
+
# exception, not a panic.
|
|
138
|
+
patch = "diff --git a/f b/f\n--- a/f\n+++ b/f\n@@ -1 +1 @@\n-a\n+\ud800\n"
|
|
139
|
+
with pytest.raises(UnicodeEncodeError):
|
|
140
|
+
pp.get_diffs(patch)
|
|
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
|
|
File without changes
|