MCPcopy
hub / github.com/pydantic/pydantic / resolve_conbytes

Function resolve_conbytes

pydantic/v1/_hypothesis_plugin.py:243–260  ·  view source on GitHub ↗
(cls)

Source from the content-addressed store, hash-verified

241
242@resolves(pydantic.ConstrainedBytes)
243def resolve_conbytes(cls): # type: ignore[no-untyped-def] # pragma: no cover
244 min_size = cls.min_length or 0
245 max_size = cls.max_length
246 if not cls.strip_whitespace:
247 return st.binary(min_size=min_size, max_size=max_size)
248 # Fun with regex to ensure we neither start nor end with whitespace
249 repeats = '{{{},{}}}'.format(
250 min_size - 2 if min_size > 2 else 0,
251 max_size - 2 if (max_size or 0) > 2 else '',
252 )
253 if min_size >= 2:
254 pattern = rf'\W.{repeats}\W'
255 elif min_size == 1:
256 pattern = rf'\W(.{repeats}\W)?'
257 else:
258 assert min_size == 0
259 pattern = rf'(\W(.{repeats}\W)?)?'
260 return st.from_regex(pattern.encode(), fullmatch=True)
261
262
263@resolves(pydantic.ConstrainedDecimal)

Callers

nothing calls this directly

Calls 1

encodeMethod · 0.45

Tested by

no test coverage detected