gef-file-to-map 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.
@@ -13,43 +13,49 @@ jobs:
13
13
  runs-on: ubuntu-latest
14
14
  steps:
15
15
  - uses: actions/checkout@v3
16
+
16
17
  - uses: PyO3/maturin-action@v1
17
18
  with:
18
19
  manylinux: auto
19
20
  command: build
20
- args: --release --sdist -o dist --find-interpreter
21
+ args: --release --sdist -o dist
22
+
21
23
  - name: Upload wheels
22
- uses: actions/upload-artifact@v3
24
+ uses: actions/upload-artifact@v4
23
25
  with:
24
- name: wheels
26
+ name: wheels-linux
25
27
  path: dist
26
28
 
27
29
  windows:
28
30
  runs-on: windows-latest
29
31
  steps:
30
32
  - uses: actions/checkout@v3
33
+
31
34
  - uses: PyO3/maturin-action@v1
32
35
  with:
33
36
  command: build
34
- args: --release -o dist --find-interpreter
37
+ args: --release -o dist
38
+
35
39
  - name: Upload wheels
36
- uses: actions/upload-artifact@v3
40
+ uses: actions/upload-artifact@v4
37
41
  with:
38
- name: wheels
42
+ name: wheels-windows
39
43
  path: dist
40
44
 
41
45
  macos:
42
46
  runs-on: macos-latest
43
47
  steps:
44
48
  - uses: actions/checkout@v3
49
+
45
50
  - uses: PyO3/maturin-action@v1
46
51
  with:
47
52
  command: build
48
- args: --release -o dist --universal2 --find-interpreter
53
+ args: --release -o dist
54
+
49
55
  - name: Upload wheels
50
- uses: actions/upload-artifact@v3
56
+ uses: actions/upload-artifact@v4
51
57
  with:
52
- name: wheels
58
+ name: wheels-macos
53
59
  path: dist
54
60
 
55
61
  release:
@@ -60,15 +66,24 @@ jobs:
60
66
  - windows
61
67
  - linux
62
68
  if: "startsWith(github.ref, 'refs/tags/')"
69
+ permissions:
70
+ # Use to sign the release artifacts
71
+ id-token: write
72
+ # Used to upload release artifacts
73
+ contents: write
74
+ # Used to generate artifact attestation
75
+ attestations: write
63
76
  steps:
64
- - uses: actions/download-artifact@v2
77
+ - uses: actions/download-artifact@v4
78
+
79
+ - name: Generate artifact attestation
80
+ uses: actions/attest-build-provenance@v1
81
+ with:
82
+ subject-path: "wheels-*/*"
83
+
84
+ - name: Publish to PyPI
85
+ if: ${{ startsWith(github.ref, 'refs/tags/') }}
86
+ uses: PyO3/maturin-action@v1
65
87
  with:
66
- name: wheels
67
- - uses: actions/setup-python@v2
68
- - name: Publish to PyPi
69
- env:
70
- TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
71
- TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
72
- run: |
73
- pip install --upgrade twine
74
- twine upload --skip-existing *
88
+ command: upload
89
+ args: --non-interactive --skip-existing wheels-*/*
@@ -0,0 +1,57 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ ## [0.2.0] - 2025-03-10
6
+
7
+ ### Bug Fixes
8
+
9
+ #### Deps
10
+
11
+ - Update nom to 8
12
+
13
+
14
+ ### Refactor
15
+
16
+ #### Deps
17
+
18
+ - Migrate nom to winnow 0.3
19
+
20
+ #### Parsing
21
+
22
+ - [**breaking**] Improve parsing of headers and add better error reporting
23
+
24
+
25
+ ## [0.1.1] - 2025-03-10
26
+
27
+ ### Bug Fixes
28
+
29
+ #### Ci
30
+
31
+ - Fix publishing CI
32
+
33
+
34
+ ### Documentation
35
+
36
+
37
+ ### Miscellaneous Tasks
38
+
39
+ #### Ci
40
+
41
+ - Only run release CI on tags
42
+
43
+
44
+ ## [0.1.0] - 2023-02-22
45
+
46
+ ### Bug Fixes
47
+
48
+ #### Ci
49
+
50
+ - Copy wheel generation from @messense
51
+ - Require minimum Python version of 3.8
52
+
53
+
54
+ ### Refactor
55
+
56
+
57
+ <!-- CEMS BV. -->
@@ -0,0 +1,224 @@
1
+ # This file is automatically @generated by Cargo.
2
+ # It is not intended for manual editing.
3
+ version = 4
4
+
5
+ [[package]]
6
+ name = "autocfg"
7
+ version = "1.4.0"
8
+ source = "registry+https://github.com/rust-lang/crates.io-index"
9
+ checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26"
10
+
11
+ [[package]]
12
+ name = "cfg-if"
13
+ version = "1.0.0"
14
+ source = "registry+https://github.com/rust-lang/crates.io-index"
15
+ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
16
+
17
+ [[package]]
18
+ name = "either"
19
+ version = "1.15.0"
20
+ source = "registry+https://github.com/rust-lang/crates.io-index"
21
+ checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719"
22
+
23
+ [[package]]
24
+ name = "gef-file-to-map"
25
+ version = "0.2.0"
26
+ dependencies = [
27
+ "itertools",
28
+ "pyo3",
29
+ "thiserror",
30
+ "winnow",
31
+ ]
32
+
33
+ [[package]]
34
+ name = "heck"
35
+ version = "0.5.0"
36
+ source = "registry+https://github.com/rust-lang/crates.io-index"
37
+ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
38
+
39
+ [[package]]
40
+ name = "indoc"
41
+ version = "2.0.6"
42
+ source = "registry+https://github.com/rust-lang/crates.io-index"
43
+ checksum = "f4c7245a08504955605670dbf141fceab975f15ca21570696aebe9d2e71576bd"
44
+
45
+ [[package]]
46
+ name = "itertools"
47
+ version = "0.14.0"
48
+ source = "registry+https://github.com/rust-lang/crates.io-index"
49
+ checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285"
50
+ dependencies = [
51
+ "either",
52
+ ]
53
+
54
+ [[package]]
55
+ name = "libc"
56
+ version = "0.2.170"
57
+ source = "registry+https://github.com/rust-lang/crates.io-index"
58
+ checksum = "875b3680cb2f8f71bdcf9a30f38d48282f5d3c95cbf9b3fa57269bb5d5c06828"
59
+
60
+ [[package]]
61
+ name = "memchr"
62
+ version = "2.7.4"
63
+ source = "registry+https://github.com/rust-lang/crates.io-index"
64
+ checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
65
+
66
+ [[package]]
67
+ name = "memoffset"
68
+ version = "0.9.1"
69
+ source = "registry+https://github.com/rust-lang/crates.io-index"
70
+ checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a"
71
+ dependencies = [
72
+ "autocfg",
73
+ ]
74
+
75
+ [[package]]
76
+ name = "once_cell"
77
+ version = "1.20.3"
78
+ source = "registry+https://github.com/rust-lang/crates.io-index"
79
+ checksum = "945462a4b81e43c4e3ba96bd7b49d834c6f61198356aa858733bc4acf3cbe62e"
80
+
81
+ [[package]]
82
+ name = "portable-atomic"
83
+ version = "1.11.0"
84
+ source = "registry+https://github.com/rust-lang/crates.io-index"
85
+ checksum = "350e9b48cbc6b0e028b0473b114454c6316e57336ee184ceab6e53f72c178b3e"
86
+
87
+ [[package]]
88
+ name = "proc-macro2"
89
+ version = "1.0.94"
90
+ source = "registry+https://github.com/rust-lang/crates.io-index"
91
+ checksum = "a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84"
92
+ dependencies = [
93
+ "unicode-ident",
94
+ ]
95
+
96
+ [[package]]
97
+ name = "pyo3"
98
+ version = "0.24.0"
99
+ source = "registry+https://github.com/rust-lang/crates.io-index"
100
+ checksum = "7f1c6c3591120564d64db2261bec5f910ae454f01def849b9c22835a84695e86"
101
+ dependencies = [
102
+ "cfg-if",
103
+ "indoc",
104
+ "libc",
105
+ "memoffset",
106
+ "once_cell",
107
+ "portable-atomic",
108
+ "pyo3-build-config",
109
+ "pyo3-ffi",
110
+ "pyo3-macros",
111
+ "unindent",
112
+ ]
113
+
114
+ [[package]]
115
+ name = "pyo3-build-config"
116
+ version = "0.24.0"
117
+ source = "registry+https://github.com/rust-lang/crates.io-index"
118
+ checksum = "e9b6c2b34cf71427ea37c7001aefbaeb85886a074795e35f161f5aecc7620a7a"
119
+ dependencies = [
120
+ "once_cell",
121
+ "target-lexicon",
122
+ ]
123
+
124
+ [[package]]
125
+ name = "pyo3-ffi"
126
+ version = "0.24.0"
127
+ source = "registry+https://github.com/rust-lang/crates.io-index"
128
+ checksum = "5507651906a46432cdda02cd02dd0319f6064f1374c9147c45b978621d2c3a9c"
129
+ dependencies = [
130
+ "libc",
131
+ "pyo3-build-config",
132
+ ]
133
+
134
+ [[package]]
135
+ name = "pyo3-macros"
136
+ version = "0.24.0"
137
+ source = "registry+https://github.com/rust-lang/crates.io-index"
138
+ checksum = "b0d394b5b4fd8d97d48336bb0dd2aebabad39f1d294edd6bcd2cccf2eefe6f42"
139
+ dependencies = [
140
+ "proc-macro2",
141
+ "pyo3-macros-backend",
142
+ "quote",
143
+ "syn",
144
+ ]
145
+
146
+ [[package]]
147
+ name = "pyo3-macros-backend"
148
+ version = "0.24.0"
149
+ source = "registry+https://github.com/rust-lang/crates.io-index"
150
+ checksum = "fd72da09cfa943b1080f621f024d2ef7e2773df7badd51aa30a2be1f8caa7c8e"
151
+ dependencies = [
152
+ "heck",
153
+ "proc-macro2",
154
+ "pyo3-build-config",
155
+ "quote",
156
+ "syn",
157
+ ]
158
+
159
+ [[package]]
160
+ name = "quote"
161
+ version = "1.0.39"
162
+ source = "registry+https://github.com/rust-lang/crates.io-index"
163
+ checksum = "c1f1914ce909e1658d9907913b4b91947430c7d9be598b15a1912935b8c04801"
164
+ dependencies = [
165
+ "proc-macro2",
166
+ ]
167
+
168
+ [[package]]
169
+ name = "syn"
170
+ version = "2.0.100"
171
+ source = "registry+https://github.com/rust-lang/crates.io-index"
172
+ checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0"
173
+ dependencies = [
174
+ "proc-macro2",
175
+ "quote",
176
+ "unicode-ident",
177
+ ]
178
+
179
+ [[package]]
180
+ name = "target-lexicon"
181
+ version = "0.13.2"
182
+ source = "registry+https://github.com/rust-lang/crates.io-index"
183
+ checksum = "e502f78cdbb8ba4718f566c418c52bc729126ffd16baee5baa718cf25dd5a69a"
184
+
185
+ [[package]]
186
+ name = "thiserror"
187
+ version = "2.0.12"
188
+ source = "registry+https://github.com/rust-lang/crates.io-index"
189
+ checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708"
190
+ dependencies = [
191
+ "thiserror-impl",
192
+ ]
193
+
194
+ [[package]]
195
+ name = "thiserror-impl"
196
+ version = "2.0.12"
197
+ source = "registry+https://github.com/rust-lang/crates.io-index"
198
+ checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d"
199
+ dependencies = [
200
+ "proc-macro2",
201
+ "quote",
202
+ "syn",
203
+ ]
204
+
205
+ [[package]]
206
+ name = "unicode-ident"
207
+ version = "1.0.18"
208
+ source = "registry+https://github.com/rust-lang/crates.io-index"
209
+ checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
210
+
211
+ [[package]]
212
+ name = "unindent"
213
+ version = "0.2.4"
214
+ source = "registry+https://github.com/rust-lang/crates.io-index"
215
+ checksum = "7264e107f553ccae879d21fbea1d6724ac785e8c3bfc762137959b5802826ef3"
216
+
217
+ [[package]]
218
+ name = "winnow"
219
+ version = "0.7.3"
220
+ source = "registry+https://github.com/rust-lang/crates.io-index"
221
+ checksum = "0e7f4ea97f6f78012141bcdb6a216b2609f0979ada50b20ca5b52dde2eac2bb1"
222
+ dependencies = [
223
+ "memchr",
224
+ ]
@@ -0,0 +1,20 @@
1
+ [package]
2
+ name = "gef-file-to-map"
3
+ version = "0.2.0"
4
+ edition = "2024"
5
+ rust-version = "1.85.0"
6
+
7
+ [lib]
8
+ # Name of the python module
9
+ name = "gef_file_to_map"
10
+ crate-type = ["cdylib"]
11
+
12
+ [dependencies]
13
+ itertools = "0.14.0"
14
+ pyo3 = { version = "0.24.0", features = ["extension-module", "abi3-py37"] }
15
+ thiserror = "2.0.12"
16
+ winnow = "0.7.3"
17
+
18
+ [profile.release]
19
+ lto = true
20
+ codegen-units = 1
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: gef-file-to-map
3
- Version: 0.1.0
3
+ Version: 0.2.0
4
4
  Classifier: Programming Language :: Rust
5
5
  Classifier: Programming Language :: Python :: Implementation :: CPython
6
6
  Classifier: Programming Language :: Python :: Implementation :: PyPy
@@ -14,6 +14,8 @@ Project-URL: repository, https://github.com/cemsbv/gef-file-to-map
14
14
 
15
15
  # gef-file-to-map
16
16
 
17
+ [![PyPI version](https://badge.fury.io/py/gef-file-to-map.svg)](https://pypi.org/project/gef-file-to-map/0.1.0/)
18
+
17
19
  Utility library for parsing of .gef files, written for [pygef](https://github.com/cemsbv/pygef).
18
20
 
19
21
  ### Run locally
@@ -30,7 +32,7 @@ maturin develop
30
32
  # Open a GEF file locally
31
33
  python
32
34
 
33
- >>> from gef_file_to_map import parse
35
+ >>> from gef_file_to_map import gef_to_map
34
36
  >>> gef_to_map(open('./tests/test.gef').read())
35
37
  ```
36
38
 
@@ -1,5 +1,7 @@
1
1
  # gef-file-to-map
2
2
 
3
+ [![PyPI version](https://badge.fury.io/py/gef-file-to-map.svg)](https://pypi.org/project/gef-file-to-map/0.1.0/)
4
+
3
5
  Utility library for parsing of .gef files, written for [pygef](https://github.com/cemsbv/pygef).
4
6
 
5
7
  ### Run locally
@@ -16,6 +18,6 @@ maturin develop
16
18
  # Open a GEF file locally
17
19
  python
18
20
 
19
- >>> from gef_file_to_map import parse
21
+ >>> from gef_file_to_map import gef_to_map
20
22
  >>> gef_to_map(open('./tests/test.gef').read())
21
23
  ```
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "gef-file-to-map"
3
- version = "0.1.0"
3
+ version = "0.2.0"
4
4
  description = "Utility library for parsing .gef files"
5
5
  requires-python = ">=3.7"
6
6
  readme = "README.md"
@@ -17,5 +17,10 @@ classifiers = [
17
17
  repository = "https://github.com/cemsbv/gef-file-to-map"
18
18
 
19
19
  [build-system]
20
- requires = ["maturin>=0.14,<0.15"]
20
+ requires = ["maturin>=1.0,<2.0"]
21
21
  build-backend = "maturin"
22
+
23
+ [tool.maturin]
24
+ features = ["pyo3/extension-module"]
25
+ strip = true
26
+ bindings = "pyo3"
@@ -1,6 +1,6 @@
1
1
  //! Error primitives.
2
2
 
3
- use pyo3::{exceptions::PyException, PyErr};
3
+ use pyo3::{PyErr, exceptions::PyException};
4
4
  use std::convert::From;
5
5
 
6
6
  /// Alias result to always return our own error type.
@@ -1,12 +1,14 @@
1
1
  //! Header parsing.
2
2
 
3
- use crate::{
4
- error::{Error, Result},
5
- nom::IResult,
3
+ use winnow::{
4
+ ascii::*,
5
+ combinator::*,
6
+ error::{StrContext, StrContextValue},
7
+ prelude::*,
8
+ token::*,
6
9
  };
7
10
 
8
- /// Separator used between values in the GEF file.
9
- const VALUE_SEPARATOR: char = ',';
11
+ use crate::error::{Error, Result};
10
12
 
11
13
  /// References to the strings of the file where the header is and it's values.
12
14
  #[derive(Debug, Clone, PartialEq)]
@@ -27,69 +29,71 @@ impl<'a> Header<'a> {
27
29
  ///
28
30
  /// The string shouldn't contain a '#' character at the begin nor a newline
29
31
  /// at the end.
30
- fn from_str(s: &'a str) -> IResult<Self> {
31
- // Get the name of the header, the left hand side
32
- let (s, name) = nom::error::context(
33
- "the name of the header",
34
- nom::character::complete::alphanumeric1,
35
- )(s)?;
36
-
37
- let (s, values) = nom::sequence::preceded(
38
- // Take all whitespace between the column header name and the = symbol
39
- nom::character::complete::space0,
40
- // Get the values between the '=' char and the end of the line
41
- nom::sequence::preceded(
42
- // Take all spaces and = characters
43
- nom::sequence::preceded(
44
- nom::character::complete::char('='),
45
- nom::character::complete::space0,
46
- ),
47
- nom::error::context(
48
- "the header values",
49
- // Get the comma-space separated values
50
- nom::multi::separated_list0(
51
- // Get until the ',' character and trim the spaces
52
- nom::sequence::delimited(
53
- nom::character::complete::space0,
54
- nom::character::complete::char(VALUE_SEPARATOR),
55
- nom::character::complete::space0,
56
- ),
57
- // Take until the end of the line or until a separator is found
58
- nom::bytes::complete::take_till(|c: char| {
59
- c == VALUE_SEPARATOR || c.is_control()
60
- }),
61
- ),
62
- ),
63
- ),
64
- )(s)?;
65
-
66
- // Make empty lists actually empty
67
- let values = if values == [""] { Vec::new() } else { values };
68
-
69
- Ok((s, Self { name, values }))
32
+ fn from_str(input: &mut &'a str) -> winnow::Result<Self> {
33
+ // Take the hash symbol at the beginning and the whitespace
34
+ ('#', space0)
35
+ .context(StrContext::Label("header hash"))
36
+ .parse_next(input)?;
37
+
38
+ // Take the name
39
+ let name = alphanumeric1
40
+ .context(StrContext::Label("header name"))
41
+ .parse_next(input)?;
42
+
43
+ // Ignore the '=' symbol, although it is required
44
+ (space0, '=', space0)
45
+ .context(StrContext::Label("header equality symbol"))
46
+ .parse_next(input)?;
47
+
48
+ // Get the comma-space separated values
49
+ let mut values: Vec<&str> = separated(
50
+ 0..,
51
+ // Get until the ',' character and trim the spaces
52
+ delimited(space0, take_till(1.., (',', '\r', '\n')), space0)
53
+ .context(StrContext::Label("header value")),
54
+ ',',
55
+ )
56
+ .context(StrContext::Label("header values"))
57
+ .context(StrContext::Expected(StrContextValue::Description(
58
+ "comma separated list of values",
59
+ )))
60
+ .parse_next(input)?;
61
+
62
+ // Remove empty values
63
+ if values == [""] {
64
+ values.clear();
65
+ }
66
+
67
+ // Take the newline
68
+ (space0, take_while(0.., ('\n', '\r'))).parse_next(input)?;
69
+
70
+ Ok(Self { name, values })
70
71
  }
71
72
  }
72
73
 
73
74
  /// Parse the headers of the GEF file.
74
75
  ///
75
76
  /// Return the parsed headers and a reference to the rest of the file.
76
- pub(crate) fn parse_headers(gef: &'_ str) -> Result<(&'_ str, Vec<Header<'_>>)> {
77
- nom::sequence::preceded(
78
- // Ignore the whitespace before the first header line
79
- nom::character::complete::multispace0,
80
- // Loop over all sequences starting with # until the newline character
81
- nom::multi::many0(nom::error::context(
82
- "a header line",
83
- nom::sequence::delimited(
84
- nom::character::complete::char('#'),
85
- Header::from_str,
86
- // Allow multiple lines
87
- nom::multi::many1(nom::character::complete::line_ending),
88
- ),
89
- )),
90
- )(gef)
91
- // Convert the nom error to our own error type
92
- .map_err(|err| Error::Parsing(err.to_string()))
77
+ pub(crate) fn parse_headers(mut gef: &'_ str) -> Result<(&'_ str, Vec<Header<'_>>)> {
78
+ parse_headers_impl
79
+ .parse_next(&mut gef)
80
+ // Convert the winnow error to our own error type
81
+ .map_err(|err| Error::Parsing(err.to_string()))
82
+ }
83
+
84
+ /// Parse the list of headers implementation.
85
+ pub(crate) fn parse_headers_impl<'a>(
86
+ input: &mut &'a str,
87
+ ) -> winnow::Result<(&'a str, Vec<Header<'a>>)> {
88
+ // Skip initial whitespace
89
+ multispace0.parse_next(input)?;
90
+
91
+ // Loop over all sequences starting with # until the newline character
92
+ let (values, _) = repeat_till(0.., Header::from_str, not('#'))
93
+ .context(StrContext::Label("headers"))
94
+ .parse_next(input)?;
95
+
96
+ Ok((input, values))
93
97
  }
94
98
 
95
99
  #[cfg(test)]
@@ -99,7 +103,7 @@ mod tests {
99
103
  #[test]
100
104
  fn test_single_header() {
101
105
  assert_eq!(
102
- Header::from_str("A= 1").unwrap().1,
106
+ Header::from_str(&mut "#A= 1").unwrap(),
103
107
  Header {
104
108
  name: "A",
105
109
  values: vec!["1"]
@@ -107,7 +111,7 @@ mod tests {
107
111
  );
108
112
 
109
113
  assert_eq!(
110
- Header::from_str("A = 1").unwrap().1,
114
+ Header::from_str(&mut "#A = 1").unwrap(),
111
115
  Header {
112
116
  name: "A",
113
117
  values: vec!["1"]
@@ -115,7 +119,7 @@ mod tests {
115
119
  );
116
120
 
117
121
  assert_eq!(
118
- Header::from_str("A= 1, 2").unwrap().1,
122
+ Header::from_str(&mut "#A= 1, 2").unwrap(),
119
123
  Header {
120
124
  name: "A",
121
125
  values: vec!["1", "2"]
@@ -126,7 +130,7 @@ mod tests {
126
130
  #[test]
127
131
  fn test_empty_header() {
128
132
  assert_eq!(
129
- Header::from_str("A=").unwrap().1,
133
+ Header::from_str(&mut "#A=").unwrap(),
130
134
  Header {
131
135
  name: "A",
132
136
  values: vec![]
@@ -134,7 +138,6 @@ mod tests {
134
138
  );
135
139
 
136
140
  let (rest, headers) = parse_headers("#A=\nrest").unwrap();
137
- assert_eq!(rest, "rest");
138
141
  assert_eq!(
139
142
  headers,
140
143
  vec![Header {
@@ -142,6 +145,7 @@ mod tests {
142
145
  values: vec![]
143
146
  },]
144
147
  );
148
+ assert_eq!(rest, "rest");
145
149
  }
146
150
 
147
151
  #[test]
@@ -15,13 +15,13 @@
15
15
 
16
16
  pub mod error;
17
17
  mod header;
18
- mod nom;
19
18
 
20
- use crate::{error::Result, header::Header};
21
19
  use itertools::Itertools;
22
- use pyo3::{types::PyModule, PyResult, Python};
20
+ use pyo3::prelude::*;
23
21
  use std::collections::HashMap;
24
22
 
23
+ use crate::{error::Result, header::Header};
24
+
25
25
  /// Type defined for easy use and extra methods.
26
26
  pub type HeaderMap<'a> = HashMap<&'a str, Vec<Vec<&'a str>>>;
27
27
 
@@ -45,15 +45,15 @@ pub fn parse(gef: &'_ str) -> Result<(&'_ str, HeaderMap<'_>)> {
45
45
  }
46
46
 
47
47
  // Python wrapper around the parse function.
48
- #[pyo3::pyfunction]
48
+ #[pyfunction]
49
49
  fn gef_to_map(gef: &'_ str) -> PyResult<(&'_ str, HeaderMap<'_>)> {
50
50
  // Map the error to a python error
51
51
  parse(gef).map_err(|err| err.into())
52
52
  }
53
53
 
54
54
  /// The python module.
55
- #[pyo3::pymodule]
56
- fn gef_file_to_map(_py: Python, module: &PyModule) -> PyResult<()> {
55
+ #[pymodule]
56
+ fn gef_file_to_map(module: &Bound<'_, PyModule>) -> PyResult<()> {
57
57
  module.add_function(pyo3::wrap_pyfunction!(gef_to_map, module)?)?;
58
58
 
59
59
  Ok(())
@@ -1,349 +0,0 @@
1
- # This file is automatically @generated by Cargo.
2
- # It is not intended for manual editing.
3
- version = 3
4
-
5
- [[package]]
6
- name = "autocfg"
7
- version = "1.1.0"
8
- source = "registry+https://github.com/rust-lang/crates.io-index"
9
- checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
10
-
11
- [[package]]
12
- name = "bitflags"
13
- version = "1.3.2"
14
- source = "registry+https://github.com/rust-lang/crates.io-index"
15
- checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
16
-
17
- [[package]]
18
- name = "cargo-husky"
19
- version = "1.5.0"
20
- source = "registry+https://github.com/rust-lang/crates.io-index"
21
- checksum = "7b02b629252fe8ef6460461409564e2c21d0c8e77e0944f3d189ff06c4e932ad"
22
-
23
- [[package]]
24
- name = "cfg-if"
25
- version = "1.0.0"
26
- source = "registry+https://github.com/rust-lang/crates.io-index"
27
- checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
28
-
29
- [[package]]
30
- name = "either"
31
- version = "1.8.1"
32
- source = "registry+https://github.com/rust-lang/crates.io-index"
33
- checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91"
34
-
35
- [[package]]
36
- name = "gef-file-to-map"
37
- version = "0.1.0"
38
- dependencies = [
39
- "cargo-husky",
40
- "itertools",
41
- "nom",
42
- "pyo3",
43
- "thiserror",
44
- ]
45
-
46
- [[package]]
47
- name = "indoc"
48
- version = "1.0.9"
49
- source = "registry+https://github.com/rust-lang/crates.io-index"
50
- checksum = "bfa799dd5ed20a7e349f3b4639aa80d74549c81716d9ec4f994c9b5815598306"
51
-
52
- [[package]]
53
- name = "itertools"
54
- version = "0.10.5"
55
- source = "registry+https://github.com/rust-lang/crates.io-index"
56
- checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473"
57
- dependencies = [
58
- "either",
59
- ]
60
-
61
- [[package]]
62
- name = "libc"
63
- version = "0.2.139"
64
- source = "registry+https://github.com/rust-lang/crates.io-index"
65
- checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79"
66
-
67
- [[package]]
68
- name = "lock_api"
69
- version = "0.4.9"
70
- source = "registry+https://github.com/rust-lang/crates.io-index"
71
- checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df"
72
- dependencies = [
73
- "autocfg",
74
- "scopeguard",
75
- ]
76
-
77
- [[package]]
78
- name = "memchr"
79
- version = "2.5.0"
80
- source = "registry+https://github.com/rust-lang/crates.io-index"
81
- checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
82
-
83
- [[package]]
84
- name = "memoffset"
85
- version = "0.8.0"
86
- source = "registry+https://github.com/rust-lang/crates.io-index"
87
- checksum = "d61c719bcfbcf5d62b3a09efa6088de8c54bc0bfcd3ea7ae39fcc186108b8de1"
88
- dependencies = [
89
- "autocfg",
90
- ]
91
-
92
- [[package]]
93
- name = "minimal-lexical"
94
- version = "0.2.1"
95
- source = "registry+https://github.com/rust-lang/crates.io-index"
96
- checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
97
-
98
- [[package]]
99
- name = "nom"
100
- version = "7.1.3"
101
- source = "registry+https://github.com/rust-lang/crates.io-index"
102
- checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
103
- dependencies = [
104
- "memchr",
105
- "minimal-lexical",
106
- ]
107
-
108
- [[package]]
109
- name = "once_cell"
110
- version = "1.17.1"
111
- source = "registry+https://github.com/rust-lang/crates.io-index"
112
- checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3"
113
-
114
- [[package]]
115
- name = "parking_lot"
116
- version = "0.12.1"
117
- source = "registry+https://github.com/rust-lang/crates.io-index"
118
- checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f"
119
- dependencies = [
120
- "lock_api",
121
- "parking_lot_core",
122
- ]
123
-
124
- [[package]]
125
- name = "parking_lot_core"
126
- version = "0.9.7"
127
- source = "registry+https://github.com/rust-lang/crates.io-index"
128
- checksum = "9069cbb9f99e3a5083476ccb29ceb1de18b9118cafa53e90c9551235de2b9521"
129
- dependencies = [
130
- "cfg-if",
131
- "libc",
132
- "redox_syscall",
133
- "smallvec",
134
- "windows-sys",
135
- ]
136
-
137
- [[package]]
138
- name = "proc-macro2"
139
- version = "1.0.51"
140
- source = "registry+https://github.com/rust-lang/crates.io-index"
141
- checksum = "5d727cae5b39d21da60fa540906919ad737832fe0b1c165da3a34d6548c849d6"
142
- dependencies = [
143
- "unicode-ident",
144
- ]
145
-
146
- [[package]]
147
- name = "pyo3"
148
- version = "0.18.1"
149
- source = "registry+https://github.com/rust-lang/crates.io-index"
150
- checksum = "06a3d8e8a46ab2738109347433cb7b96dffda2e4a218b03ef27090238886b147"
151
- dependencies = [
152
- "cfg-if",
153
- "indoc",
154
- "libc",
155
- "memoffset",
156
- "parking_lot",
157
- "pyo3-build-config",
158
- "pyo3-ffi",
159
- "pyo3-macros",
160
- "unindent",
161
- ]
162
-
163
- [[package]]
164
- name = "pyo3-build-config"
165
- version = "0.18.1"
166
- source = "registry+https://github.com/rust-lang/crates.io-index"
167
- checksum = "75439f995d07ddfad42b192dfcf3bc66a7ecfd8b4a1f5f6f046aa5c2c5d7677d"
168
- dependencies = [
169
- "once_cell",
170
- "target-lexicon",
171
- ]
172
-
173
- [[package]]
174
- name = "pyo3-ffi"
175
- version = "0.18.1"
176
- source = "registry+https://github.com/rust-lang/crates.io-index"
177
- checksum = "839526a5c07a17ff44823679b68add4a58004de00512a95b6c1c98a6dcac0ee5"
178
- dependencies = [
179
- "libc",
180
- "pyo3-build-config",
181
- ]
182
-
183
- [[package]]
184
- name = "pyo3-macros"
185
- version = "0.18.1"
186
- source = "registry+https://github.com/rust-lang/crates.io-index"
187
- checksum = "bd44cf207476c6a9760c4653559be4f206efafb924d3e4cbf2721475fc0d6cc5"
188
- dependencies = [
189
- "proc-macro2",
190
- "pyo3-macros-backend",
191
- "quote",
192
- "syn",
193
- ]
194
-
195
- [[package]]
196
- name = "pyo3-macros-backend"
197
- version = "0.18.1"
198
- source = "registry+https://github.com/rust-lang/crates.io-index"
199
- checksum = "dc1f43d8e30460f36350d18631ccf85ded64c059829208fe680904c65bcd0a4c"
200
- dependencies = [
201
- "proc-macro2",
202
- "quote",
203
- "syn",
204
- ]
205
-
206
- [[package]]
207
- name = "quote"
208
- version = "1.0.23"
209
- source = "registry+https://github.com/rust-lang/crates.io-index"
210
- checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b"
211
- dependencies = [
212
- "proc-macro2",
213
- ]
214
-
215
- [[package]]
216
- name = "redox_syscall"
217
- version = "0.2.16"
218
- source = "registry+https://github.com/rust-lang/crates.io-index"
219
- checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a"
220
- dependencies = [
221
- "bitflags",
222
- ]
223
-
224
- [[package]]
225
- name = "scopeguard"
226
- version = "1.1.0"
227
- source = "registry+https://github.com/rust-lang/crates.io-index"
228
- checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
229
-
230
- [[package]]
231
- name = "smallvec"
232
- version = "1.10.0"
233
- source = "registry+https://github.com/rust-lang/crates.io-index"
234
- checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0"
235
-
236
- [[package]]
237
- name = "syn"
238
- version = "1.0.107"
239
- source = "registry+https://github.com/rust-lang/crates.io-index"
240
- checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5"
241
- dependencies = [
242
- "proc-macro2",
243
- "quote",
244
- "unicode-ident",
245
- ]
246
-
247
- [[package]]
248
- name = "target-lexicon"
249
- version = "0.12.6"
250
- source = "registry+https://github.com/rust-lang/crates.io-index"
251
- checksum = "8ae9980cab1db3fceee2f6c6f643d5d8de2997c58ee8d25fb0cc8a9e9e7348e5"
252
-
253
- [[package]]
254
- name = "thiserror"
255
- version = "1.0.38"
256
- source = "registry+https://github.com/rust-lang/crates.io-index"
257
- checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0"
258
- dependencies = [
259
- "thiserror-impl",
260
- ]
261
-
262
- [[package]]
263
- name = "thiserror-impl"
264
- version = "1.0.38"
265
- source = "registry+https://github.com/rust-lang/crates.io-index"
266
- checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f"
267
- dependencies = [
268
- "proc-macro2",
269
- "quote",
270
- "syn",
271
- ]
272
-
273
- [[package]]
274
- name = "unicode-ident"
275
- version = "1.0.6"
276
- source = "registry+https://github.com/rust-lang/crates.io-index"
277
- checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc"
278
-
279
- [[package]]
280
- name = "unindent"
281
- version = "0.1.11"
282
- source = "registry+https://github.com/rust-lang/crates.io-index"
283
- checksum = "e1766d682d402817b5ac4490b3c3002d91dfa0d22812f341609f97b08757359c"
284
-
285
- [[package]]
286
- name = "windows-sys"
287
- version = "0.45.0"
288
- source = "registry+https://github.com/rust-lang/crates.io-index"
289
- checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0"
290
- dependencies = [
291
- "windows-targets",
292
- ]
293
-
294
- [[package]]
295
- name = "windows-targets"
296
- version = "0.42.1"
297
- source = "registry+https://github.com/rust-lang/crates.io-index"
298
- checksum = "8e2522491fbfcd58cc84d47aeb2958948c4b8982e9a2d8a2a35bbaed431390e7"
299
- dependencies = [
300
- "windows_aarch64_gnullvm",
301
- "windows_aarch64_msvc",
302
- "windows_i686_gnu",
303
- "windows_i686_msvc",
304
- "windows_x86_64_gnu",
305
- "windows_x86_64_gnullvm",
306
- "windows_x86_64_msvc",
307
- ]
308
-
309
- [[package]]
310
- name = "windows_aarch64_gnullvm"
311
- version = "0.42.1"
312
- source = "registry+https://github.com/rust-lang/crates.io-index"
313
- checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608"
314
-
315
- [[package]]
316
- name = "windows_aarch64_msvc"
317
- version = "0.42.1"
318
- source = "registry+https://github.com/rust-lang/crates.io-index"
319
- checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7"
320
-
321
- [[package]]
322
- name = "windows_i686_gnu"
323
- version = "0.42.1"
324
- source = "registry+https://github.com/rust-lang/crates.io-index"
325
- checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640"
326
-
327
- [[package]]
328
- name = "windows_i686_msvc"
329
- version = "0.42.1"
330
- source = "registry+https://github.com/rust-lang/crates.io-index"
331
- checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605"
332
-
333
- [[package]]
334
- name = "windows_x86_64_gnu"
335
- version = "0.42.1"
336
- source = "registry+https://github.com/rust-lang/crates.io-index"
337
- checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45"
338
-
339
- [[package]]
340
- name = "windows_x86_64_gnullvm"
341
- version = "0.42.1"
342
- source = "registry+https://github.com/rust-lang/crates.io-index"
343
- checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463"
344
-
345
- [[package]]
346
- name = "windows_x86_64_msvc"
347
- version = "0.42.1"
348
- source = "registry+https://github.com/rust-lang/crates.io-index"
349
- checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd"
@@ -1,29 +0,0 @@
1
- [package]
2
- name = "gef-file-to-map"
3
- version = "0.1.0"
4
- edition = "2021"
5
-
6
- [lib]
7
- # Name of the python module
8
- name = "gef_file_to_map"
9
- crate-type = ["cdylib"]
10
-
11
- [dependencies]
12
- itertools = "0.10.5"
13
- nom = "7.1.3"
14
- pyo3 = { version = "0.18.1", features = ["extension-module", "abi3-py37"] }
15
- thiserror = "1.0.38"
16
-
17
- # Automatically add git hooks for code conventions & tests
18
- [dev-dependencies.cargo-husky]
19
- version = "1.5.0"
20
- features = [
21
- "precommit-hook",
22
- "postmerge-hook",
23
- "run-cargo-check",
24
- "run-cargo-clippy",
25
- "run-cargo-fmt",
26
- ]
27
-
28
- [package.metadata.maturin]
29
- python-source = "python"
@@ -1,15 +0,0 @@
1
- #!/bin/bash
2
- set -e
3
- echo "::group::Install Rust"
4
- which rustup > /dev/null || curl --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain stable
5
- export PATH="$HOME/.cargo/bin:$PATH"
6
- rustup override set stable
7
- rustup component add llvm-tools-preview || true
8
- echo "::endgroup::"
9
- export PATH="$PATH:/opt/python/cp36-cp36m/bin:/opt/python/cp37-cp37m/bin:/opt/python/cp38-cp38/bin:/opt/python/cp39-cp39/bin"
10
- echo "::group::Install maturin"
11
- curl -L https://github.com/PyO3/maturin/releases/download/v0.14.13/maturin-x86_64-unknown-linux-musl.tar.gz | tar -xz -C /usr/local/bin
12
- maturin --version || true
13
- which patchelf > /dev/null || python3 -m pip install patchelf
14
- echo "::endgroup::"
15
- maturin build --release --sdist -o dist --find-interpreter
@@ -1,7 +0,0 @@
1
- //! Tools and utilities for the nom crate.
2
-
3
- use nom::error::VerboseError;
4
-
5
- /// Remove a lot of boilerplate for nom, use the verbose error type for span
6
- /// information.
7
- pub(crate) type IResult<'a, T> = nom::IResult<&'a str, T, VerboseError<&'a str>>;
File without changes