nebius/SWE-bench-extra huggingface dataset:
Repository: mozman/steputils

Issue:
.step file parsing error
I am unable to read a step file.
These .step file are coming from Rhino & Creo professional tools
I keep getting the following error.

```
File "D:\Progam Files\Python\python v3.7.0\lib\site-packages\steputils\p21.py", line 1025, in readfile
    return load(fp)
  File "D:\Progam Files\Python\python v3.7.0\lib\site-packages\steputils\p21.py", line 1019, in load
    return loads(content)
  File "D:\Progam Files\Python\python v3.7.0\lib\site-packages\steputils\p21.py", line 1003, in loads
    return Parser(lexer).parse()
  File "D:\Progam Files\Python\python v3.7.0\lib\site-packages\steputils\p21.py", line 633, in __init__
    self.tokens = list(lexer.parse())
  File "D:\Progam Files\Python\python v3.7.0\lib\site-packages\steputils\p21.py", line 505, in parse
    yield step_decoder(self.string())  # str
  File "D:\Progam Files\Python\python v3.7.0\lib\site-packages\steputils\p21.py", line 557, in string
    raise ParseError(f'Found invalid character in string "{current}".')
steputils.exceptions.ParseError: Found invalid character in string "
".
```

When I open the .stp files in notepad++ text editor, the encoding is UTF-8. 
I tried changing the file encoding to ISO 8859-1 without any success. 


Comments:

Patch:
diff --git a/src/steputils/p21.py b/src/steputils/p21.py
index c8dd28b..a7f3de1 100644
--- a/src/steputils/p21.py
+++ b/src/steputils/p21.py
@@ -33,6 +33,7 @@ FIRST_KEYWORD_CHAR = ascii_uppercase + '_'
 KEYWORD_CHARS = ascii_letters + digits + '_-'  # should accept ISO-10303-21 and lower case letters
 
 STRING_CHARS = ascii_letters + digits + ' _' + SPECIAL + BACKSLASH
+IGNORE_DELIMETERS = "\n\r\f\t"
 FIRST_NUMBER_CHARS = '-+01234567890'
 NUMBER_CHARS = FIRST_NUMBER_CHARS + '.eE'
 FIRST_ENUM_CHARS = ascii_uppercase + '_.'
@@ -553,6 +554,8 @@ class Lexer:
                     return ''.join(s)
             elif current in STRING_CHARS:
                 s.append(b.get())
+            elif current in IGNORE_DELIMETERS:
+                b.skip()
             else:
                 raise ParseError(f'Found invalid character in string "{current}".')
 


Test patch:
diff --git a/tests/p21/test_p21_lexer.py b/tests/p21/test_p21_lexer.py
index 53cda6c..787b453 100644
--- a/tests/p21/test_p21_lexer.py
+++ b/tests/p21/test_p21_lexer.py
@@ -63,9 +63,7 @@ def test_lexer_string_with_enclosed_comments():
 
 
 def test_lexer_string_across_lines():
-    # strings across lines are not allowed
-    with pytest.raises(p21.ParseError):
-        list(p21.Lexer("'\n',"))
+    assert list(p21.Lexer("'multi\nline',")) == ['multiline', ',']
 
 
 def test_lexer_empty_string():
Repository: mpdavis/python-jose

Issue:
Use OrderedDict for headers in jwt.decode and jws._encode_header
Hello,

I would implement the "headless JWT" idea I rode in this article https://dev.to/neilmadden/7-best-practices-for-json-web-tokens the section 4 "Consider using "headless" JWTs" .

But the fact python-jose build the headers from dict make this impossible. Indeed, keys don't have an order in a classic dict. Could you consider to use OrderedDict instead, in jws.py l.131 and jwt.py l.114 ?

If this idea interests you, I could make a pull request.

Best,



Comments:

Patch:
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index 4d7654d..c9df8d2 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -17,6 +17,8 @@ Major
   `#121 <https://github.com/mpdavis/python-jose/pull/121>`_
 * Make pyca/cryptography backend the preferred backend if multiple backends are present.
   `#122 <https://github.com/mpdavis/python-jose/pull/122>`_
+* Allow for headless JWT by sorting headers when serializing.
+  `#136 <https://github.com/mpdavis/python-jose/pull/136>`_
 
 Bugfixes
 """"""""
diff --git a/jose/jws.py b/jose/jws.py
index b2a75fd..9d2fc0d 100644
--- a/jose/jws.py
+++ b/jose/jws.py
@@ -144,6 +144,7 @@ def _encode_header(algorithm, additional_headers=None):
     json_header = json.dumps(
         header,
         separators=(',', ':'),
+        sort_keys=True,
     ).encode('utf-8')
 
     return base64url_encode(json_header)


Test patch:
diff --git a/tests/test_jwt.py b/tests/test_jwt.py
index 0140954..9ceb239 100644
--- a/tests/test_jwt.py
+++ b/tests/test_jwt.py
@@ -107,6 +107,33 @@ class TestJWT:
         for k, v in headers.items():
             assert all_headers[k] == v
 
+    def test_deterministic_headers(self):
+        from collections import OrderedDict
+        from jose.utils import base64url_decode
+
+        claims = {"a": "b"}
+        key = "secret"
+
+        headers1 = OrderedDict((
+            ('kid', 'my-key-id'),
+            ('another_key', 'another_value'),
+        ))
+        encoded1 = jwt.encode(claims, key, algorithm='HS256', headers=headers1)
+        encoded_headers1 = encoded1.split('.', 1)[0]
+
+        headers2 = OrderedDict((
+            ('another_key', 'another_value'),
+            ('kid', 'my-key-id'),
+        ))
+        encoded2 = jwt.encode(claims, key, algorithm='HS256', headers=headers2)
+        encoded_headers2 = encoded2.split('.', 1)[0]
+
+        assert encoded_headers1 == encoded_headers2
+
+        # manually decode header to compare it to known good
+        decoded_headers1 = base64url_decode(encoded_headers1.encode('utf-8'))
+        assert decoded_headers1 == b"""{"alg":"HS256","another_key":"another_value","kid":"my-key-id","typ":"JWT"}"""
+
     def test_encode(self, claims, key):
 
         expected = (