We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
MaxLen annotation validator for custom sequences is incorrect
### Initial Checks

- [X] I confirm that I'm using Pydantic V2

### Description

When using an `annotated_type.MaxLen` annotation with a custom sequence it rejects sequences that have precisely the maximum length when it should only reject if they are greater.

I'm pretty sure this is because [the validator function](https://github.com/pydantic/pydantic/blob/6ef959fa69d1ab1aedf2778b6c8f452e0fee37b6/pydantic/_internal/_validators.py#L266C27-L266C27) used for custom sequences currently checks for strict inequality rather than less or equal.

### Example Code

```Python
from typing import Annotated
from annotated_types import MaxLen

from pydantic import BaseModel

class MySequence(BaseModel):

    inner: list[int]

    def __len__(self):
        return len(self.inner)

    def __getitem__(self, __key: int) -> int:
        return self.inner[__key]


class MyModel(BaseModel):
    seq: Annotated[MySequence, MaxLen(3)]


MyModel.model_validate({"seq": {"inner": [1, 2, 3]}})
```


### Python, Pydantic & OS Version

```Text
pydantic version: 2.0.3
pydantic-core version: 2.3.0 release build profile
python version: 3.11.4 | packaged by Anaconda, Inc. | (main, Jul  5 2023, 13:47:18) [MSC v.1916 64 bit (AMD64)]
platform: Windows-10-10.0.19045-SP0
optional deps. installed: ['typing-extensions'];
```


Selected Assignee: @davidhewitt

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pydantic/_internal/_validators.py`
Content:
```
1 """Validator functions for standard library types.
2 
3 Import of this module is deferred since it contains imports of many standard library modules.
4 """
5 
6 from __future__ import annotations as _annotations
7 
8 import re
9 import typing
10 from ipaddress import IPv4Address, IPv4Interface, IPv4Network, IPv6Address, IPv6Interface, IPv6Network
11 from typing import Any
12 
13 from pydantic_core import PydanticCustomError, core_schema
14 from pydantic_core._pydantic_core import PydanticKnownError
15 
16 
17 def sequence_validator(
18     __input_value: typing.Sequence[Any],
19     validator: core_schema.ValidatorFunctionWrapHandler,
20 ) -> typing.Sequence[Any]:
21     """Validator for `Sequence` types, isinstance(v, Sequence) has already been called."""
22     value_type = type(__input_value)
23 
24     # We don't accept any plain string as a sequence
25     # Relevant issue: https://github.com/pydantic/pydantic/issues/5595
26     if issubclass(value_type, (str, bytes)):
27         raise PydanticCustomError(
28             'sequence_str',
29             "'{type_name}' instances are not allowed as a Sequence value",
30             {'type_name': value_type.__name__},
31         )
32 
33     v_list = validator(__input_value)
34 
35     # the rest of the logic is just re-creating the original type from `v_list`
36     if value_type == list:
37         return v_list
38     elif issubclass(value_type, range):
39         # return the list as we probably can't re-create the range
40         return v_list
41     else:
42         # best guess at how to re-create the original type, more custom construction logic might be required
43         return value_type(v_list)  # type: ignore[call-arg]
44 
45 
46 def import_string(value: Any) -> Any:
47     if isinstance(value, str):
48         try:
49             return _import_string_logic(value)
50         except ImportError as e:
51             raise PydanticCustomError('import_error', 'Invalid python path: {error}', {'error': str(e)})
52     else:
53         # otherwise we just return the value and let the next validator do the rest of the work
54         return value
55 
56 
57 def _import_string_logic(dotted_path: str) -> Any:
58     """Inspired by uvicorn — dotted paths should include a colon before the final item if that item is not a module.
59     (This is necessary to distinguish between a submodule and an attribute when there is a conflict.).
60 
61     If the dotted path does not include a colon and the final item is not a valid module, importing as an attribute
62     rather than a submodule will be attempted automatically.
63 
64     So, for example, the following values of `dotted_path` result in the following returned values:
65     * 'collections': <module 'collections'>
66     * 'collections.abc': <module 'collections.abc'>
67     * 'collections.abc:Mapping': <class 'collections.abc.Mapping'>
68     * `collections.abc.Mapping`: <class 'collections.abc.Mapping'> (though this is a bit slower than the previous line)
69 
70     An error will be raised under any of the following scenarios:
71     * `dotted_path` contains more than one colon (e.g., 'collections:abc:Mapping')
72     * the substring of `dotted_path` before the colon is not a valid module in the environment (e.g., '123:Mapping')
73     * the substring of `dotted_path` after the colon is not an attribute of the module (e.g., 'collections:abc123')
74     """
75     from importlib import import_module
76 
77     components = dotted_path.strip().split(':')
78     if len(components) > 2:
79         raise ImportError(f"Import strings should have at most one ':'; received {dotted_path!r}")
80 
81     module_path = components[0]
82     if not module_path:
83         raise ImportError(f'Import strings should have a nonempty module name; received {dotted_path!r}')
84 
85     try:
86         module = import_module(module_path)
87     except ModuleNotFoundError as e:
88         if '.' in module_path:
89             # Check if it would be valid if the final item was separated from its module with a `:`
90             maybe_module_path, maybe_attribute = dotted_path.strip().rsplit('.', 1)
91             try:
92                 return _import_string_logic(f'{maybe_module_path}:{maybe_attribute}')
93             except ImportError:
94                 pass
95             raise ImportError(f'No module named {module_path!r}') from e
96         raise e
97 
98     if len(components) > 1:
99         attribute = components[1]
100         try:
101             return getattr(module, attribute)
102         except AttributeError as e:
103             raise ImportError(f'cannot import name {attribute!r} from {module_path!r}') from e
104     else:
105         return module
106 
107 
108 def pattern_either_validator(__input_value: Any) -> typing.Pattern[Any]:
109     if isinstance(__input_value, typing.Pattern):
110         return __input_value  # type: ignore
111     elif isinstance(__input_value, (str, bytes)):
112         # todo strict mode
113         return compile_pattern(__input_value)  # type: ignore
114     else:
115         raise PydanticCustomError('pattern_type', 'Input should be a valid pattern')
116 
117 
118 def pattern_str_validator(__input_value: Any) -> typing.Pattern[str]:
119     if isinstance(__input_value, typing.Pattern):
120         if isinstance(__input_value.pattern, str):
121             return __input_value
122         else:
123             raise PydanticCustomError('pattern_str_type', 'Input should be a string pattern')
124     elif isinstance(__input_value, str):
125         return compile_pattern(__input_value)
126     elif isinstance(__input_value, bytes):
127         raise PydanticCustomError('pattern_str_type', 'Input should be a string pattern')
128     else:
129         raise PydanticCustomError('pattern_type', 'Input should be a valid pattern')
130 
131 
132 def pattern_bytes_validator(__input_value: Any) -> typing.Pattern[bytes]:
133     if isinstance(__input_value, typing.Pattern):
134         if isinstance(__input_value.pattern, bytes):
135             return __input_value
136         else:
137             raise PydanticCustomError('pattern_bytes_type', 'Input should be a bytes pattern')
138     elif isinstance(__input_value, bytes):
139         return compile_pattern(__input_value)
140     elif isinstance(__input_value, str):
141         raise PydanticCustomError('pattern_bytes_type', 'Input should be a bytes pattern')
142     else:
143         raise PydanticCustomError('pattern_type', 'Input should be a valid pattern')
144 
145 
146 PatternType = typing.TypeVar('PatternType', str, bytes)
147 
148 
149 def compile_pattern(pattern: PatternType) -> typing.Pattern[PatternType]:
150     try:
151         return re.compile(pattern)
152     except re.error:
153         raise PydanticCustomError('pattern_regex', 'Input should be a valid regular expression')
154 
155 
156 def ip_v4_address_validator(__input_value: Any) -> IPv4Address:
157     if isinstance(__input_value, IPv4Address):
158         return __input_value
159 
160     try:
161         return IPv4Address(__input_value)
162     except ValueError:
163         raise PydanticCustomError('ip_v4_address', 'Input is not a valid IPv4 address')
164 
165 
166 def ip_v6_address_validator(__input_value: Any) -> IPv6Address:
167     if isinstance(__input_value, IPv6Address):
168         return __input_value
169 
170     try:
171         return IPv6Address(__input_value)
172     except ValueError:
173         raise PydanticCustomError('ip_v6_address', 'Input is not a valid IPv6 address')
174 
175 
176 def ip_v4_network_validator(__input_value: Any) -> IPv4Network:
177     """Assume IPv4Network initialised with a default `strict` argument.
178 
179     See more:
180     https://docs.python.org/library/ipaddress.html#ipaddress.IPv4Network
181     """
182     if isinstance(__input_value, IPv4Network):
183         return __input_value
184 
185     try:
186         return IPv4Network(__input_value)
187     except ValueError:
188         raise PydanticCustomError('ip_v4_network', 'Input is not a valid IPv4 network')
189 
190 
191 def ip_v6_network_validator(__input_value: Any) -> IPv6Network:
192     """Assume IPv6Network initialised with a default `strict` argument.
193 
194     See more:
195     https://docs.python.org/library/ipaddress.html#ipaddress.IPv6Network
196     """
197     if isinstance(__input_value, IPv6Network):
198         return __input_value
199 
200     try:
201         return IPv6Network(__input_value)
202     except ValueError:
203         raise PydanticCustomError('ip_v6_network', 'Input is not a valid IPv6 network')
204 
205 
206 def ip_v4_interface_validator(__input_value: Any) -> IPv4Interface:
207     if isinstance(__input_value, IPv4Interface):
208         return __input_value
209 
210     try:
211         return IPv4Interface(__input_value)
212     except ValueError:
213         raise PydanticCustomError('ip_v4_interface', 'Input is not a valid IPv4 interface')
214 
215 
216 def ip_v6_interface_validator(__input_value: Any) -> IPv6Interface:
217     if isinstance(__input_value, IPv6Interface):
218         return __input_value
219 
220     try:
221         return IPv6Interface(__input_value)
222     except ValueError:
223         raise PydanticCustomError('ip_v6_interface', 'Input is not a valid IPv6 interface')
224 
225 
226 def greater_than_validator(x: Any, gt: Any) -> Any:
227     if not (x > gt):
228         raise PydanticKnownError('greater_than', {'gt': str(gt)})
229     return x
230 
231 
232 def greater_than_or_equal_validator(x: Any, ge: Any) -> Any:
233     if not (x >= ge):
234         raise PydanticKnownError('greater_than_equal', {'ge': str(ge)})
235     return x
236 
237 
238 def less_than_validator(x: Any, lt: Any) -> Any:
239     if not (x < lt):
240         raise PydanticKnownError('less_than', {'lt': str(lt)})
241     return x
242 
243 
244 def less_than_or_equal_validator(x: Any, le: Any) -> Any:
245     if not (x <= le):
246         raise PydanticKnownError('less_than_equal', {'le': str(le)})
247     return x
248 
249 
250 def multiple_of_validator(x: Any, multiple_of: Any) -> Any:
251     if not (x % multiple_of == 0):
252         raise PydanticKnownError('multiple_of', {'multiple_of': multiple_of})
253     return x
254 
255 
256 def min_length_validator(x: Any, min_length: Any) -> Any:
257     if not (len(x) >= min_length):
258         raise PydanticKnownError(
259             'too_short',
260             {'field_type': 'Value', 'min_length': min_length, 'actual_length': len(x)},
261         )
262     return x
263 
264 
265 def max_length_validator(x: Any, max_length: Any) -> Any:
266     if not (len(x) < max_length):
267         raise PydanticKnownError(
268             'too_long',
269             {'field_type': 'Value', 'max_length': max_length, 'actual_length': len(x)},
270         )
271     return x
272
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/pydantic/_internal/_validators.py b/pydantic/_internal/_validators.py
--- a/pydantic/_internal/_validators.py
+++ b/pydantic/_internal/_validators.py
@@ -263,7 +263,7 @@
 
 
 def max_length_validator(x: Any, max_length: Any) -> Any:
-    if not (len(x) < max_length):
+    if len(x) > max_length:
         raise PydanticKnownError(
             'too_long',
             {'field_type': 'Value', 'max_length': max_length, 'actual_length': len(x)},

{"golden_diff": "diff --git a/pydantic/_internal/_validators.py b/pydantic/_internal/_validators.py\n--- a/pydantic/_internal/_validators.py\n+++ b/pydantic/_internal/_validators.py\n@@ -263,7 +263,7 @@\n \n \n def max_length_validator(x: Any, max_length: Any) -> Any:\n-    if not (len(x) < max_length):\n+    if len(x) > max_length:\n         raise PydanticKnownError(\n             'too_long',\n             {'field_type': 'Value', 'max_length': max_length, 'actual_length': len(x)},\n", "issue": "MaxLen annotation validator for custom sequences is incorrect\n### Initial Checks\n\n- [X] I confirm that I'm using Pydantic V2\n\n### Description\n\nWhen using an `annotated_type.MaxLen` annotation with a custom sequence it rejects sequences that have precisely the maximum length when it should only reject if they are greater.\r\n\r\nI'm pretty sure this is because [the validator function](https://github.com/pydantic/pydantic/blob/6ef959fa69d1ab1aedf2778b6c8f452e0fee37b6/pydantic/_internal/_validators.py#L266C27-L266C27) used for custom sequences currently checks for strict inequality rather than less or equal.\n\n### Example Code\n\n```Python\nfrom typing import Annotated\r\nfrom annotated_types import MaxLen\r\n\r\nfrom pydantic import BaseModel\r\n\r\nclass MySequence(BaseModel):\r\n\r\n    inner: list[int]\r\n\r\n    def __len__(self):\r\n        return len(self.inner)\r\n\r\n    def __getitem__(self, __key: int) -> int:\r\n        return self.inner[__key]\r\n\r\n\r\nclass MyModel(BaseModel):\r\n    seq: Annotated[MySequence, MaxLen(3)]\r\n\r\n\r\nMyModel.model_validate({\"seq\": {\"inner\": [1, 2, 3]}})\n```\n\n\n### Python, Pydantic & OS Version\n\n```Text\npydantic version: 2.0.3\r\npydantic-core version: 2.3.0 release build profile\r\npython version: 3.11.4 | packaged by Anaconda, Inc. | (main, Jul  5 2023, 13:47:18) [MSC v.1916 64 bit (AMD64)]\r\nplatform: Windows-10-10.0.19045-SP0\r\noptional deps. installed: ['typing-extensions'];\n```\n\n\nSelected Assignee: @davidhewitt\n", "before_files": [{"content": "\"\"\"Validator functions for standard library types.\n\nImport of this module is deferred since it contains imports of many standard library modules.\n\"\"\"\n\nfrom __future__ import annotations as _annotations\n\nimport re\nimport typing\nfrom ipaddress import IPv4Address, IPv4Interface, IPv4Network, IPv6Address, IPv6Interface, IPv6Network\nfrom typing import Any\n\nfrom pydantic_core import PydanticCustomError, core_schema\nfrom pydantic_core._pydantic_core import PydanticKnownError\n\n\ndef sequence_validator(\n    __input_value: typing.Sequence[Any],\n    validator: core_schema.ValidatorFunctionWrapHandler,\n) -> typing.Sequence[Any]:\n    \"\"\"Validator for `Sequence` types, isinstance(v, Sequence) has already been called.\"\"\"\n    value_type = type(__input_value)\n\n    # We don't accept any plain string as a sequence\n    # Relevant issue: https://github.com/pydantic/pydantic/issues/5595\n    if issubclass(value_type, (str, bytes)):\n        raise PydanticCustomError(\n            'sequence_str',\n            \"'{type_name}' instances are not allowed as a Sequence value\",\n            {'type_name': value_type.__name__},\n        )\n\n    v_list = validator(__input_value)\n\n    # the rest of the logic is just re-creating the original type from `v_list`\n    if value_type == list:\n        return v_list\n    elif issubclass(value_type, range):\n        # return the list as we probably can't re-create the range\n        return v_list\n    else:\n        # best guess at how to re-create the original type, more custom construction logic might be required\n        return value_type(v_list)  # type: ignore[call-arg]\n\n\ndef import_string(value: Any) -> Any:\n    if isinstance(value, str):\n        try:\n            return _import_string_logic(value)\n        except ImportError as e:\n            raise PydanticCustomError('import_error', 'Invalid python path: {error}', {'error': str(e)})\n    else:\n        # otherwise we just return the value and let the next validator do the rest of the work\n        return value\n\n\ndef _import_string_logic(dotted_path: str) -> Any:\n    \"\"\"Inspired by uvicorn \u2014 dotted paths should include a colon before the final item if that item is not a module.\n    (This is necessary to distinguish between a submodule and an attribute when there is a conflict.).\n\n    If the dotted path does not include a colon and the final item is not a valid module, importing as an attribute\n    rather than a submodule will be attempted automatically.\n\n    So, for example, the following values of `dotted_path` result in the following returned values:\n    * 'collections': <module 'collections'>\n    * 'collections.abc': <module 'collections.abc'>\n    * 'collections.abc:Mapping': <class 'collections.abc.Mapping'>\n    * `collections.abc.Mapping`: <class 'collections.abc.Mapping'> (though this is a bit slower than the previous line)\n\n    An error will be raised under any of the following scenarios:\n    * `dotted_path` contains more than one colon (e.g., 'collections:abc:Mapping')\n    * the substring of `dotted_path` before the colon is not a valid module in the environment (e.g., '123:Mapping')\n    * the substring of `dotted_path` after the colon is not an attribute of the module (e.g., 'collections:abc123')\n    \"\"\"\n    from importlib import import_module\n\n    components = dotted_path.strip().split(':')\n    if len(components) > 2:\n        raise ImportError(f\"Import strings should have at most one ':'; received {dotted_path!r}\")\n\n    module_path = components[0]\n    if not module_path:\n        raise ImportError(f'Import strings should have a nonempty module name; received {dotted_path!r}')\n\n    try:\n        module = import_module(module_path)\n    except ModuleNotFoundError as e:\n        if '.' in module_path:\n            # Check if it would be valid if the final item was separated from its module with a `:`\n            maybe_module_path, maybe_attribute = dotted_path.strip().rsplit('.', 1)\n            try:\n                return _import_string_logic(f'{maybe_module_path}:{maybe_attribute}')\n            except ImportError:\n                pass\n            raise ImportError(f'No module named {module_path!r}') from e\n        raise e\n\n    if len(components) > 1:\n        attribute = components[1]\n        try:\n            return getattr(module, attribute)\n        except AttributeError as e:\n            raise ImportError(f'cannot import name {attribute!r} from {module_path!r}') from e\n    else:\n        return module\n\n\ndef pattern_either_validator(__input_value: Any) -> typing.Pattern[Any]:\n    if isinstance(__input_value, typing.Pattern):\n        return __input_value  # type: ignore\n    elif isinstance(__input_value, (str, bytes)):\n        # todo strict mode\n        return compile_pattern(__input_value)  # type: ignore\n    else:\n        raise PydanticCustomError('pattern_type', 'Input should be a valid pattern')\n\n\ndef pattern_str_validator(__input_value: Any) -> typing.Pattern[str]:\n    if isinstance(__input_value, typing.Pattern):\n        if isinstance(__input_value.pattern, str):\n            return __input_value\n        else:\n            raise PydanticCustomError('pattern_str_type', 'Input should be a string pattern')\n    elif isinstance(__input_value, str):\n        return compile_pattern(__input_value)\n    elif isinstance(__input_value, bytes):\n        raise PydanticCustomError('pattern_str_type', 'Input should be a string pattern')\n    else:\n        raise PydanticCustomError('pattern_type', 'Input should be a valid pattern')\n\n\ndef pattern_bytes_validator(__input_value: Any) -> typing.Pattern[bytes]:\n    if isinstance(__input_value, typing.Pattern):\n        if isinstance(__input_value.pattern, bytes):\n            return __input_value\n        else:\n            raise PydanticCustomError('pattern_bytes_type', 'Input should be a bytes pattern')\n    elif isinstance(__input_value, bytes):\n        return compile_pattern(__input_value)\n    elif isinstance(__input_value, str):\n        raise PydanticCustomError('pattern_bytes_type', 'Input should be a bytes pattern')\n    else:\n        raise PydanticCustomError('pattern_type', 'Input should be a valid pattern')\n\n\nPatternType = typing.TypeVar('PatternType', str, bytes)\n\n\ndef compile_pattern(pattern: PatternType) -> typing.Pattern[PatternType]:\n    try:\n        return re.compile(pattern)\n    except re.error:\n        raise PydanticCustomError('pattern_regex', 'Input should be a valid regular expression')\n\n\ndef ip_v4_address_validator(__input_value: Any) -> IPv4Address:\n    if isinstance(__input_value, IPv4Address):\n        return __input_value\n\n    try:\n        return IPv4Address(__input_value)\n    except ValueError:\n        raise PydanticCustomError('ip_v4_address', 'Input is not a valid IPv4 address')\n\n\ndef ip_v6_address_validator(__input_value: Any) -> IPv6Address:\n    if isinstance(__input_value, IPv6Address):\n        return __input_value\n\n    try:\n        return IPv6Address(__input_value)\n    except ValueError:\n        raise PydanticCustomError('ip_v6_address', 'Input is not a valid IPv6 address')\n\n\ndef ip_v4_network_validator(__input_value: Any) -> IPv4Network:\n    \"\"\"Assume IPv4Network initialised with a default `strict` argument.\n\n    See more:\n    https://docs.python.org/library/ipaddress.html#ipaddress.IPv4Network\n    \"\"\"\n    if isinstance(__input_value, IPv4Network):\n        return __input_value\n\n    try:\n        return IPv4Network(__input_value)\n    except ValueError:\n        raise PydanticCustomError('ip_v4_network', 'Input is not a valid IPv4 network')\n\n\ndef ip_v6_network_validator(__input_value: Any) -> IPv6Network:\n    \"\"\"Assume IPv6Network initialised with a default `strict` argument.\n\n    See more:\n    https://docs.python.org/library/ipaddress.html#ipaddress.IPv6Network\n    \"\"\"\n    if isinstance(__input_value, IPv6Network):\n        return __input_value\n\n    try:\n        return IPv6Network(__input_value)\n    except ValueError:\n        raise PydanticCustomError('ip_v6_network', 'Input is not a valid IPv6 network')\n\n\ndef ip_v4_interface_validator(__input_value: Any) -> IPv4Interface:\n    if isinstance(__input_value, IPv4Interface):\n        return __input_value\n\n    try:\n        return IPv4Interface(__input_value)\n    except ValueError:\n        raise PydanticCustomError('ip_v4_interface', 'Input is not a valid IPv4 interface')\n\n\ndef ip_v6_interface_validator(__input_value: Any) -> IPv6Interface:\n    if isinstance(__input_value, IPv6Interface):\n        return __input_value\n\n    try:\n        return IPv6Interface(__input_value)\n    except ValueError:\n        raise PydanticCustomError('ip_v6_interface', 'Input is not a valid IPv6 interface')\n\n\ndef greater_than_validator(x: Any, gt: Any) -> Any:\n    if not (x > gt):\n        raise PydanticKnownError('greater_than', {'gt': str(gt)})\n    return x\n\n\ndef greater_than_or_equal_validator(x: Any, ge: Any) -> Any:\n    if not (x >= ge):\n        raise PydanticKnownError('greater_than_equal', {'ge': str(ge)})\n    return x\n\n\ndef less_than_validator(x: Any, lt: Any) -> Any:\n    if not (x < lt):\n        raise PydanticKnownError('less_than', {'lt': str(lt)})\n    return x\n\n\ndef less_than_or_equal_validator(x: Any, le: Any) -> Any:\n    if not (x <= le):\n        raise PydanticKnownError('less_than_equal', {'le': str(le)})\n    return x\n\n\ndef multiple_of_validator(x: Any, multiple_of: Any) -> Any:\n    if not (x % multiple_of == 0):\n        raise PydanticKnownError('multiple_of', {'multiple_of': multiple_of})\n    return x\n\n\ndef min_length_validator(x: Any, min_length: Any) -> Any:\n    if not (len(x) >= min_length):\n        raise PydanticKnownError(\n            'too_short',\n            {'field_type': 'Value', 'min_length': min_length, 'actual_length': len(x)},\n        )\n    return x\n\n\ndef max_length_validator(x: Any, max_length: Any) -> Any:\n    if not (len(x) < max_length):\n        raise PydanticKnownError(\n            'too_long',\n            {'field_type': 'Value', 'max_length': max_length, 'actual_length': len(x)},\n        )\n    return x\n", "path": "pydantic/_internal/_validators.py"}], "after_files": [{"content": "\"\"\"Validator functions for standard library types.\n\nImport of this module is deferred since it contains imports of many standard library modules.\n\"\"\"\n\nfrom __future__ import annotations as _annotations\n\nimport re\nimport typing\nfrom ipaddress import IPv4Address, IPv4Interface, IPv4Network, IPv6Address, IPv6Interface, IPv6Network\nfrom typing import Any\n\nfrom pydantic_core import PydanticCustomError, core_schema\nfrom pydantic_core._pydantic_core import PydanticKnownError\n\n\ndef sequence_validator(\n    __input_value: typing.Sequence[Any],\n    validator: core_schema.ValidatorFunctionWrapHandler,\n) -> typing.Sequence[Any]:\n    \"\"\"Validator for `Sequence` types, isinstance(v, Sequence) has already been called.\"\"\"\n    value_type = type(__input_value)\n\n    # We don't accept any plain string as a sequence\n    # Relevant issue: https://github.com/pydantic/pydantic/issues/5595\n    if issubclass(value_type, (str, bytes)):\n        raise PydanticCustomError(\n            'sequence_str',\n            \"'{type_name}' instances are not allowed as a Sequence value\",\n            {'type_name': value_type.__name__},\n        )\n\n    v_list = validator(__input_value)\n\n    # the rest of the logic is just re-creating the original type from `v_list`\n    if value_type == list:\n        return v_list\n    elif issubclass(value_type, range):\n        # return the list as we probably can't re-create the range\n        return v_list\n    else:\n        # best guess at how to re-create the original type, more custom construction logic might be required\n        return value_type(v_list)  # type: ignore[call-arg]\n\n\ndef import_string(value: Any) -> Any:\n    if isinstance(value, str):\n        try:\n            return _import_string_logic(value)\n        except ImportError as e:\n            raise PydanticCustomError('import_error', 'Invalid python path: {error}', {'error': str(e)})\n    else:\n        # otherwise we just return the value and let the next validator do the rest of the work\n        return value\n\n\ndef _import_string_logic(dotted_path: str) -> Any:\n    \"\"\"Inspired by uvicorn \u2014 dotted paths should include a colon before the final item if that item is not a module.\n    (This is necessary to distinguish between a submodule and an attribute when there is a conflict.).\n\n    If the dotted path does not include a colon and the final item is not a valid module, importing as an attribute\n    rather than a submodule will be attempted automatically.\n\n    So, for example, the following values of `dotted_path` result in the following returned values:\n    * 'collections': <module 'collections'>\n    * 'collections.abc': <module 'collections.abc'>\n    * 'collections.abc:Mapping': <class 'collections.abc.Mapping'>\n    * `collections.abc.Mapping`: <class 'collections.abc.Mapping'> (though this is a bit slower than the previous line)\n\n    An error will be raised under any of the following scenarios:\n    * `dotted_path` contains more than one colon (e.g., 'collections:abc:Mapping')\n    * the substring of `dotted_path` before the colon is not a valid module in the environment (e.g., '123:Mapping')\n    * the substring of `dotted_path` after the colon is not an attribute of the module (e.g., 'collections:abc123')\n    \"\"\"\n    from importlib import import_module\n\n    components = dotted_path.strip().split(':')\n    if len(components) > 2:\n        raise ImportError(f\"Import strings should have at most one ':'; received {dotted_path!r}\")\n\n    module_path = components[0]\n    if not module_path:\n        raise ImportError(f'Import strings should have a nonempty module name; received {dotted_path!r}')\n\n    try:\n        module = import_module(module_path)\n    except ModuleNotFoundError as e:\n        if '.' in module_path:\n            # Check if it would be valid if the final item was separated from its module with a `:`\n            maybe_module_path, maybe_attribute = dotted_path.strip().rsplit('.', 1)\n            try:\n                return _import_string_logic(f'{maybe_module_path}:{maybe_attribute}')\n            except ImportError:\n                pass\n            raise ImportError(f'No module named {module_path!r}') from e\n        raise e\n\n    if len(components) > 1:\n        attribute = components[1]\n        try:\n            return getattr(module, attribute)\n        except AttributeError as e:\n            raise ImportError(f'cannot import name {attribute!r} from {module_path!r}') from e\n    else:\n        return module\n\n\ndef pattern_either_validator(__input_value: Any) -> typing.Pattern[Any]:\n    if isinstance(__input_value, typing.Pattern):\n        return __input_value  # type: ignore\n    elif isinstance(__input_value, (str, bytes)):\n        # todo strict mode\n        return compile_pattern(__input_value)  # type: ignore\n    else:\n        raise PydanticCustomError('pattern_type', 'Input should be a valid pattern')\n\n\ndef pattern_str_validator(__input_value: Any) -> typing.Pattern[str]:\n    if isinstance(__input_value, typing.Pattern):\n        if isinstance(__input_value.pattern, str):\n            return __input_value\n        else:\n            raise PydanticCustomError('pattern_str_type', 'Input should be a string pattern')\n    elif isinstance(__input_value, str):\n        return compile_pattern(__input_value)\n    elif isinstance(__input_value, bytes):\n        raise PydanticCustomError('pattern_str_type', 'Input should be a string pattern')\n    else:\n        raise PydanticCustomError('pattern_type', 'Input should be a valid pattern')\n\n\ndef pattern_bytes_validator(__input_value: Any) -> typing.Pattern[bytes]:\n    if isinstance(__input_value, typing.Pattern):\n        if isinstance(__input_value.pattern, bytes):\n            return __input_value\n        else:\n            raise PydanticCustomError('pattern_bytes_type', 'Input should be a bytes pattern')\n    elif isinstance(__input_value, bytes):\n        return compile_pattern(__input_value)\n    elif isinstance(__input_value, str):\n        raise PydanticCustomError('pattern_bytes_type', 'Input should be a bytes pattern')\n    else:\n        raise PydanticCustomError('pattern_type', 'Input should be a valid pattern')\n\n\nPatternType = typing.TypeVar('PatternType', str, bytes)\n\n\ndef compile_pattern(pattern: PatternType) -> typing.Pattern[PatternType]:\n    try:\n        return re.compile(pattern)\n    except re.error:\n        raise PydanticCustomError('pattern_regex', 'Input should be a valid regular expression')\n\n\ndef ip_v4_address_validator(__input_value: Any) -> IPv4Address:\n    if isinstance(__input_value, IPv4Address):\n        return __input_value\n\n    try:\n        return IPv4Address(__input_value)\n    except ValueError:\n        raise PydanticCustomError('ip_v4_address', 'Input is not a valid IPv4 address')\n\n\ndef ip_v6_address_validator(__input_value: Any) -> IPv6Address:\n    if isinstance(__input_value, IPv6Address):\n        return __input_value\n\n    try:\n        return IPv6Address(__input_value)\n    except ValueError:\n        raise PydanticCustomError('ip_v6_address', 'Input is not a valid IPv6 address')\n\n\ndef ip_v4_network_validator(__input_value: Any) -> IPv4Network:\n    \"\"\"Assume IPv4Network initialised with a default `strict` argument.\n\n    See more:\n    https://docs.python.org/library/ipaddress.html#ipaddress.IPv4Network\n    \"\"\"\n    if isinstance(__input_value, IPv4Network):\n        return __input_value\n\n    try:\n        return IPv4Network(__input_value)\n    except ValueError:\n        raise PydanticCustomError('ip_v4_network', 'Input is not a valid IPv4 network')\n\n\ndef ip_v6_network_validator(__input_value: Any) -> IPv6Network:\n    \"\"\"Assume IPv6Network initialised with a default `strict` argument.\n\n    See more:\n    https://docs.python.org/library/ipaddress.html#ipaddress.IPv6Network\n    \"\"\"\n    if isinstance(__input_value, IPv6Network):\n        return __input_value\n\n    try:\n        return IPv6Network(__input_value)\n    except ValueError:\n        raise PydanticCustomError('ip_v6_network', 'Input is not a valid IPv6 network')\n\n\ndef ip_v4_interface_validator(__input_value: Any) -> IPv4Interface:\n    if isinstance(__input_value, IPv4Interface):\n        return __input_value\n\n    try:\n        return IPv4Interface(__input_value)\n    except ValueError:\n        raise PydanticCustomError('ip_v4_interface', 'Input is not a valid IPv4 interface')\n\n\ndef ip_v6_interface_validator(__input_value: Any) -> IPv6Interface:\n    if isinstance(__input_value, IPv6Interface):\n        return __input_value\n\n    try:\n        return IPv6Interface(__input_value)\n    except ValueError:\n        raise PydanticCustomError('ip_v6_interface', 'Input is not a valid IPv6 interface')\n\n\ndef greater_than_validator(x: Any, gt: Any) -> Any:\n    if not (x > gt):\n        raise PydanticKnownError('greater_than', {'gt': str(gt)})\n    return x\n\n\ndef greater_than_or_equal_validator(x: Any, ge: Any) -> Any:\n    if not (x >= ge):\n        raise PydanticKnownError('greater_than_equal', {'ge': str(ge)})\n    return x\n\n\ndef less_than_validator(x: Any, lt: Any) -> Any:\n    if not (x < lt):\n        raise PydanticKnownError('less_than', {'lt': str(lt)})\n    return x\n\n\ndef less_than_or_equal_validator(x: Any, le: Any) -> Any:\n    if not (x <= le):\n        raise PydanticKnownError('less_than_equal', {'le': str(le)})\n    return x\n\n\ndef multiple_of_validator(x: Any, multiple_of: Any) -> Any:\n    if not (x % multiple_of == 0):\n        raise PydanticKnownError('multiple_of', {'multiple_of': multiple_of})\n    return x\n\n\ndef min_length_validator(x: Any, min_length: Any) -> Any:\n    if not (len(x) >= min_length):\n        raise PydanticKnownError(\n            'too_short',\n            {'field_type': 'Value', 'min_length': min_length, 'actual_length': len(x)},\n        )\n    return x\n\n\ndef max_length_validator(x: Any, max_length: Any) -> Any:\n    if len(x) > max_length:\n        raise PydanticKnownError(\n            'too_long',\n            {'field_type': 'Value', 'max_length': max_length, 'actual_length': len(x)},\n        )\n    return x\n", "path": "pydantic/_internal/_validators.py"}]}