nebius/SWE-bench-extra huggingface dataset:
Repository: Azure/msrest-for-python

Issue:
Response content type json parser
Currently the deserializer only supports a list of content type values like "application/json" and "text/json".  Based on HTTP spec, "application/<randomtext>+json" is also json. So we should have a type parser to accept this syntax. 

Comments:

Patch:
diff --git a/msrest/pipeline/universal.py b/msrest/pipeline/universal.py
index f124ea7..b8dc40c 100644
--- a/msrest/pipeline/universal.py
+++ b/msrest/pipeline/universal.py
@@ -32,6 +32,7 @@ import os
 import xml.etree.ElementTree as ET
 import platform
 import codecs
+import re
 
 from typing import Mapping, Any, Optional, AnyStr, Union, IO, cast, TYPE_CHECKING  # pylint: disable=unused-import
 
@@ -129,10 +130,9 @@ class HTTPLogger(SansIOHTTPPolicy):
 
 class RawDeserializer(SansIOHTTPPolicy):
 
-    JSON_MIMETYPES = [
-        'application/json',
-        'text/json' # Because we're open minded people...
-    ]
+    # Accept "text" because we're open minded people...
+    JSON_REGEXP = re.compile(r'^(application|text)/([a-z+.]+\+)?json$')
+
     # Name used in context
     CONTEXT_NAME = "deserialized_data"
 
@@ -165,7 +165,7 @@ class RawDeserializer(SansIOHTTPPolicy):
         if content_type is None:
             return data
 
-        if content_type in cls.JSON_MIMETYPES:
+        if cls.JSON_REGEXP.match(content_type):
             try:
                 return json.loads(data_as_str)
             except ValueError as err:


Test patch:
diff --git a/tests/test_universal_pipeline.py b/tests/test_universal_pipeline.py
index 2568e34..cd92ca7 100644
--- a/tests/test_universal_pipeline.py
+++ b/tests/test_universal_pipeline.py
@@ -151,6 +151,12 @@ def test_raw_deserializer():
     result = response.context["deserialized_data"]
     assert result["success"] is True
 
+    # Simple JSON with complex content_type
+    response = build_response(b'{"success": true}', content_type="application/vnd.microsoft.appconfig.kv+json")
+    raw_deserializer.on_response(None, response, stream=False)
+    result = response.context["deserialized_data"]
+    assert result["success"] is True
+
     # JSON with UTF-8 BOM
     response = build_response(b'\xef\xbb\xbf{"success": true}', content_type="application/json; charset=utf-8")
     raw_deserializer.on_response(None, response, stream=False)
Repository: Azure/msrest-for-python

Issue:
Improve msrest exception message
msrest.exceptions : Parameter 'tags' must be of type '{str}'

Comments:

Patch:
diff --git a/msrest/exceptions.py b/msrest/exceptions.py
index 31bedf0..dcd14d2 100644
--- a/msrest/exceptions.py
+++ b/msrest/exceptions.py
@@ -107,6 +107,13 @@ class ValidationError(ClientException):
         "type": "must be of type {!r}"
     }
 
+    @staticmethod
+    def _format_message(rule, reason, value):
+        if rule == "type" and value.startswith(r"{"):
+            internal_type = value.strip(r"{}")
+            value = "dict[str, {}]".format(internal_type)
+        return reason.format(value)
+
     def __init__(self, rule, target, value, *args, **kwargs):
         # type: (str, str, str, str, str) -> None
         self.rule = rule
@@ -114,7 +121,7 @@ class ValidationError(ClientException):
         message = "Parameter {!r} ".format(target)
         reason = self._messages.get(
             rule, "failed to meet validation requirement.")
-        message += reason.format(value)
+        message += self._format_message(rule, reason, value)
         super(ValidationError, self).__init__(message, *args, **kwargs)
 
 


Test patch:
diff --git a/tests/test_serialization.py b/tests/test_serialization.py
index 399d963..00d253c 100644
--- a/tests/test_serialization.py
+++ b/tests/test_serialization.py
@@ -709,6 +709,10 @@ class TestRuntimeSerialized(unittest.TestCase):
         with self.assertRaises(SerializationError):
             self.s._serialize(test_obj)
 
+        with pytest.raises(ValidationError) as err:
+            test_obj.validate()
+        assert "Parameter 'attr_e' must be of type 'dict[str, float]'" in str(err.value)
+
         test_obj.attr_e = {"value": "NotAFloat"}
 
         with self.assertRaises(SerializationError):
@@ -1290,7 +1294,7 @@ class TestRuntimeSerialized(unittest.TestCase):
             long_type = long
         except NameError:
             long_type = int
- 
+
 
         class TestModel(Model):
             _attribute_map = {'data': {'key': 'data', 'type': 'object'}}
Repository: Azure/msrest-for-python

Issue:
Unable to serialize unicode string as type object on Python 2.7
```
from msrest.serialization import Serializer
s=Serializer()
s._serialize(u"\ua015", 'object')
```

Comments:

Patch:
diff --git a/README.rst b/README.rst
index 94950c2..ebce1fb 100644
--- a/README.rst
+++ b/README.rst
@@ -26,6 +26,7 @@ Release History
 **Bugfixes**
 
 - Fix serialization of random Model object  #220
+- Fix serialization of unicode string in Py2 and object mode #221
 
 
 2020-07-27 Version 0.6.18
diff --git a/msrest/serialization.py b/msrest/serialization.py
index ab7a28f..f9037b9 100644
--- a/msrest/serialization.py
+++ b/msrest/serialization.py
@@ -951,6 +951,8 @@ class Serializer(object):
             return self.serialize_basic(attr, self.basic_types[obj_type], **kwargs)
         if obj_type is _long_type:
             return self.serialize_long(attr)
+        if obj_type is unicode_str:
+            return self.serialize_unicode(attr)
 
         # If it's a model or I know this dependency, serialize as a Model
         elif obj_type in self.dependencies.values() or isinstance(attr, Model):


Test patch:
diff --git a/tests/test_serialization.py b/tests/test_serialization.py
index 99d3980..ab04cfd 100644
--- a/tests/test_serialization.py
+++ b/tests/test_serialization.py
@@ -1366,6 +1366,8 @@ class TestRuntimeSerialized(unittest.TestCase):
         except NameError:
             long_type = int
 
+        s = Serializer()
+        assert s.serialize_data(long_type(1), 'object') == long_type(1)
 
         class TestModel(Model):
             _attribute_map = {'data': {'key': 'data', 'type': 'object'}}
@@ -1376,6 +1378,23 @@ class TestRuntimeSerialized(unittest.TestCase):
             'data': {'id': long_type(1)}
         }
 
+    def test_unicode_as_type_object(self):
+        """Test irrelevant on Python 3. But still doing it to test regresssion.
+            https://github.com/Azure/msrest-for-python/issue/221
+        """
+
+        s = Serializer()
+        assert s.serialize_data(u"\ua015", 'object') == u"\ua015"
+
+        class TestModel(Model):
+            _attribute_map = {'data': {'key': 'data', 'type': 'object'}}
+
+        m = TestModel(data = {'id': u"\ua015"})
+        serialized = m.serialize()
+        assert serialized == {
+            'data': {'id': u"\ua015"}
+        }
+
     def test_json_with_xml_map(self):
         basic_json = {'age': 37, 'country': 'france'}
Repository: Azure/msrest-for-python

Issue:
v0.4.12 breaks mixed dict with enum if model-as-string=true
This breaks:
``` python
        async_security_rule = self.network_client.security_rules.create_or_update(
            self.group_name,
            security_group_name,
            new_security_rule_name,
            {
                    'access':azure.mgmt.network.models.SecurityRuleAccess.allow,
                    'description':'New Test security rule',
                    'destination_address_prefix':'*',
                    'destination_port_range':'123-3500',
                    'direction':azure.mgmt.network.models.SecurityRuleDirection.outbound,
                    'priority':400,
                    'protocol':azure.mgmt.network.models.SecurityRuleProtocol.tcp,
                    'source_address_prefix':'*',
                    'source_port_range':'655',
            }
        )
``` 

Comments:

Patch:
diff --git a/msrest/serialization.py b/msrest/serialization.py
index 063f2e6..a3d50cd 100644
--- a/msrest/serialization.py
+++ b/msrest/serialization.py
@@ -1200,6 +1200,12 @@ class Deserializer(object):
         :param str data: response string to be deserialized.
         :rtype: str or unicode
         """
+        # We might be here because we have an enum modeled as string,
+        # and we try to deserialize a partial dict with enum inside
+        if isinstance(data, Enum):
+            return data
+
+        # Consider this is real string
         try:
             if isinstance(data, unicode):
                 return data


Test patch:
diff --git a/tests/test_serialization.py b/tests/test_serialization.py
index 787a086..10fb82f 100644
--- a/tests/test_serialization.py
+++ b/tests/test_serialization.py
@@ -353,10 +353,10 @@ class TestRuntimeSerialized(unittest.TestCase):
         class TestEnum(Enum):
             val = "Value"
 
-        t = test_obj
+        t = test_obj()
         t.abc = TestEnum.val
 
-        serialized = self.s._serialize(test_obj)
+        serialized = self.s._serialize(t)
         expected = {
             "ABC": "Value"
         }
@@ -374,6 +374,31 @@ class TestRuntimeSerialized(unittest.TestCase):
         with self.assertRaises(SerializationError):
             serializer._serialize(t)
 
+        serializer = Serializer({
+            'TestEnumObj': test_obj,
+            'TestEnum': TestEnum
+        })
+        serialized = serializer.body({
+            'abc': TestEnum.val
+        }, 'TestEnumObj')
+        expected = {
+            'ABC': 'Value'
+        }
+        self.assertEqual(expected, serialized)
+
+        # model-as-string=True
+        test_obj._attribute_map = {
+            "abc":{"key":"ABC", "type":"str"}
+        }
+        serialized = serializer.body({
+            'abc': TestEnum.val
+        }, 'TestEnumObj')
+        expected = {
+            'ABC': 'Value'
+        }
+        self.assertEqual(expected, serialized)
+
+
     def test_attr_none(self):
         """
         Test serializing an object with None attributes.
Repository: Azure/msrest-for-python

Issue:
Should refuse a string as a valid list of string
Ends up in the portal as ['a','b','c'] if we use `Model('abc')` instead of `Model(['abc'])`. Should fail, accepting a string for a list of string is likely an error and not a feature.

See https://github.com/Azure/azure-sdk-for-python/issues/1376#issuecomment-323409463

Comments:

Patch:
diff --git a/msrest/serialization.py b/msrest/serialization.py
index cc03063..61e811f 100644
--- a/msrest/serialization.py
+++ b/msrest/serialization.py
@@ -623,6 +623,8 @@ class Serializer(object):
          in the iterable into a combined string. Default is 'None'.
         :rtype: list, str
         """
+        if isinstance(data, str):
+            raise SerializationError("Refuse str type as a valid iter type.")
         serialized = []
         for d in data:
             try:


Test patch:
diff --git a/tests/test_serialization.py b/tests/test_serialization.py
index 4d6a80a..39f2878 100644
--- a/tests/test_serialization.py
+++ b/tests/test_serialization.py
@@ -736,6 +736,10 @@ class TestRuntimeSerialized(unittest.TestCase):
         b = self.s.serialize_iter([], 'int')
         self.assertEqual(b, [])
 
+    def test_serialize_str_as_iter(self):
+        with self.assertRaises(SerializationError):
+            self.s.serialize_iter("I am a string", 'str')
+
     def test_serialize_json_obj(self):
 
         class ComplexId(Model):
Repository: Azure/msrest-for-python

Issue:
Make BasicTokenAuthentication the new base class of OAuthTokenAuthentication
To enable some KV scenarios releated to MSI

Comments:

Patch:
diff --git a/msrest/authentication.py b/msrest/authentication.py
index 48c90ae..8d21624 100644
--- a/msrest/authentication.py
+++ b/msrest/authentication.py
@@ -79,6 +79,14 @@ class BasicTokenAuthentication(Authentication):
         self.scheme = 'Bearer'
         self.token = token
 
+    def set_token(self):
+        """Should be used to define the self.token attribute.
+
+        In this implementation, does nothing since the token is statically provided
+        at creation.
+        """
+        pass
+
     def signed_session(self):
         """Create requests session with any required auth headers
         applied.
@@ -91,7 +99,7 @@ class BasicTokenAuthentication(Authentication):
         return session
 
 
-class OAuthTokenAuthentication(Authentication):
+class OAuthTokenAuthentication(BasicTokenAuthentication):
     """OAuth Token Authentication.
     Requires that supplied token contains an expires_in field.
 


Test patch:
diff --git a/tests/test_auth.py b/tests/test_auth.py
index e573a02..32f67f5 100644
--- a/tests/test_auth.py
+++ b/tests/test_auth.py
@@ -39,6 +39,7 @@ except ImportError:
 
 from msrest.authentication import (
     BasicAuthentication,
+    BasicTokenAuthentication,
     OAuthTokenAuthentication)
 
 from requests import Request
@@ -71,6 +72,19 @@ class TestAuthentication(unittest.TestCase):
         self.assertTrue('Authorization' in req.headers)
         self.assertTrue(req.headers['Authorization'].startswith('Basic '))
 
+    def test_basic_token_auth(self):
+
+        token = {
+            'access_token': '123456789'
+        }
+        basic = BasicTokenAuthentication(token)
+        basic.set_token() # Just check that this does not raise
+        session = basic.signed_session()
+
+        req = session.prepare_request(self.request)
+        self.assertTrue('Authorization' in req.headers)
+        self.assertEquals(req.headers['Authorization'], 'Bearer 123456789')
+
     def test_token_auth(self):
 
         token =  {"my_token":123}
Repository: Azure/pykusto

Issue:
query.__add__ only handles short queries

Comments:

Patch:
diff --git a/pykusto/query.py b/pykusto/query.py
index 42caba4..272bbaf 100644
--- a/pykusto/query.py
+++ b/pykusto/query.py
@@ -53,7 +53,12 @@ class Query:
         self._table = head if isinstance(head, Table) else None
 
     def __add__(self, other: 'Query'):
-        other._head = self
+        other_base = other
+        while other_base._head is not None:
+            if other_base._head._head is None:
+                break
+            other_base = other_base._head
+        other_base._head = self
         return other
 
     def where(self, predicate: BooleanType) -> 'WhereQuery':


Test patch:
diff --git a/test/test_query.py b/test/test_query.py
index a228e03..034feec 100644
--- a/test/test_query.py
+++ b/test/test_query.py
@@ -15,9 +15,21 @@ class TestQuery(TestBase):
         )
 
     def test_add_queries(self):
-        query = Query().where(col.foo > 4) + Query().take(5) + Query().sort_by(col.bar, Order.ASC, Nulls.LAST)
+        query = (Query().where(col.foo > 4) +
+                 Query().take(5) +
+                 Query().where(col.foo > 1).sort_by(col.bar, Order.ASC, Nulls.LAST))
         self.assertEqual(
-            " | where foo > 4 | take 5 | sort by bar asc nulls last",
+            " | where foo > 4 | take 5 | where foo > 1 | sort by bar asc nulls last",
+            query.render(),
+        )
+
+    def test_add_queries_with_table(self):
+        mock_kusto_client = MockKustoClient()
+        table = PyKustoClient(mock_kusto_client)['test_db']['test_table']
+        b = Query().take(5).take(2).sort_by(col.bar, Order.ASC, Nulls.LAST)
+        query = Query(table).where(col.foo > 4) + b
+        self.assertEqual(
+            "test_table | where foo > 4 | take 5 | take 2 | sort by bar asc nulls last",
             query.render(),
         )
Repository: Backblaze/b2-sdk-python

Issue:
400 bad_request more than one upload using auth token
I have a loop uploading files locally to B2 cloud. After a few thousand uploads over a few hours, I get this error:
`b2sdk.exception.UnknownError: Unknown error: 400 bad_request more than one upload using auth token 4_0021a87abca5e6b0000000005_018fe4f8_97f3ec_uplg_wANv-9n9ent4nLDoDI0yMFmZqeQ=`

I feel like upload_local_file method should be able to handle renegotiating a new auth token on its own rather than failing as such.

Comments:

Patch:
diff --git a/b2sdk/v1/exception.py b/b2sdk/v1/exception.py
index cf149a68..7815a28f 100644
--- a/b2sdk/v1/exception.py
+++ b/b2sdk/v1/exception.py
@@ -18,6 +18,7 @@ from b2sdk.exception import B2HttpCallbackException
 from b2sdk.exception import B2HttpCallbackPostRequestException
 from b2sdk.exception import B2HttpCallbackPreRequestException
 from b2sdk.exception import B2RequestTimeout
+from b2sdk.exception import B2RequestTimeoutDuringUpload
 from b2sdk.exception import B2SimpleError
 from b2sdk.exception import BadDateFormat
 from b2sdk.exception import BadFileInfo
@@ -73,6 +74,7 @@ __all__ = (
     'B2HttpCallbackPostRequestException',
     'B2HttpCallbackPreRequestException',
     'B2RequestTimeout',
+    'B2RequestTimeoutDuringUpload',
     'B2SimpleError',
     'BadDateFormat',
     'BadFileInfo',


Test patch:
diff --git a/test/v1/test_bucket.py b/test/v1/test_bucket.py
index ec085c86..87c98d0f 100644
--- a/test/v1/test_bucket.py
+++ b/test/v1/test_bucket.py
@@ -21,6 +21,7 @@ from .test_base import TestBase
 from .deps_exception import (
     AlreadyFailed,
     B2Error,
+    B2RequestTimeoutDuringUpload,
     InvalidAuthToken,
     InvalidMetadataDirective,
     InvalidRange,
@@ -452,6 +453,11 @@ class TestUpload(TestCaseWithBucket):
         data = six.b('hello world')
         self.bucket.upload_bytes(data, 'file1')
 
+    def test_upload_timeout(self):
+        self.simulator.set_upload_errors([B2RequestTimeoutDuringUpload()])
+        data = six.b('hello world')
+        self.bucket.upload_bytes(data, 'file1')
+
     def test_upload_file_one_fatal_error(self):
         self.simulator.set_upload_errors([CanRetry(False)])
         data = six.b('hello world')
Repository: Backblaze/b2-sdk-python

Issue:
passing compiled regex results in AttributeError
I am using b2sdk-1.24.0.

`b2sdk.v2.ScalPoliciesManager` accepts `Iterable[str | re.Pattern]` for `exclude_dir_regexes`. However, if `exclude_dir_regexes` contains an `re.Pattern` instance, an Attribute error results at `b2sdk/scan/policies.py:70` because `re.Pattern has no attribute 'endswith'`. When regex is `re.Pattern`, `regex.pattern.endswith` must be used.

Comments:

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 03028df2..6b3a6531 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ## [Unreleased]
 
+### Fixed
+* Fix ScanPoliciesManager support for compiled regexes
+
 ### Infrastructure
 * Fix readthedocs build by updating to v2 configuration schema
 * Fix spellcheck erroring out on LICENSE file
diff --git a/b2sdk/scan/policies.py b/b2sdk/scan/policies.py
index e6a05396..349a76fd 100644
--- a/b2sdk/scan/policies.py
+++ b/b2sdk/scan/policies.py
@@ -43,7 +43,7 @@ class RegexSet:
         return any(c.match(s) is not None for c in self._compiled_list)
 
 
-def convert_dir_regex_to_dir_prefix_regex(dir_regex):
+def convert_dir_regex_to_dir_prefix_regex(dir_regex: str | re.Pattern) -> str:
     """
     The patterns used to match directory names (and file names) are allowed
     to match a prefix of the name.  This 'feature' was unintentional, but is
@@ -65,8 +65,10 @@ def convert_dir_regex_to_dir_prefix_regex(dir_regex):
     either the regex ends in '$' or does not.
 
     :param dir_regex: a regular expression string or literal
-    :type dir_regex: str
+    :return: a regular expression string which matches the directory prefix
     """
+    if isinstance(dir_regex, re.Pattern):
+        dir_regex = dir_regex.pattern
     if dir_regex.endswith('$'):
         return dir_regex[:-1] + r'/'
     else:


Test patch:
diff --git a/test/unit/scan/test_scan_policies.py b/test/unit/scan/test_scan_policies.py
index fe79c9a4..2c6cd2fc 100644
--- a/test/unit/scan/test_scan_policies.py
+++ b/test/unit/scan/test_scan_policies.py
@@ -70,3 +70,15 @@ class TestScanPoliciesManager:
         }
         with pytest.raises(exception):
             ScanPoliciesManager(**kwargs)
+
+    @pytest.mark.apiver(from_ver=2)
+    def test_re_pattern_argument_support(self):
+        kwargs = {
+            param: (re.compile(r".*"),)
+            for param in (
+                "exclude_dir_regexes",
+                "exclude_file_regexes",
+                "include_file_regexes",
+            )
+        }
+        ScanPoliciesManager(**kwargs)