code: def conbytes(
      *, regex: bytes = None, **kwargs
  ) -> Type[pydantic.BaseModel]:
      """
      Extend pydantic.conbytes() to support ``regex`` constraints (like pydantic.constr() does).
      """
  
      compiled_regex = re.compile(regex) if regex is not None else None
  
      class ConstrainedBytesWithRegex(pydantic.conbytes(**kwargs)):
          @classmethod
          def __get_validators__(cls):
              yield from super().__get_validators__()
              yield cls.match_regex
  
          @classmethod
          def match_regex(cls, value: bytes) -> bytes:
              if (
                  compiled_regex is not None
                  and compiled_regex.match(value) is None
              ):
                  raise ValueError(
                      f"Value `{value}` doesn't match regex `{regex}`"
                  )
              return value
  
      return ConstrainedBytesWithRegex
  
file_path: hivemind/hivemind/dht/schema.py
imports: import re
  from typing import Any, Dict, Optional, Type
  import pydantic
  from hivemind.dht.crypto import RSASignatureValidator
  from hivemind.dht.protocol import DHTProtocol
  from hivemind.dht.routing import DHTID
  from hivemind.dht.validation import DHTRecord, RecordValidatorBase
  from hivemind.utils import get_logger
label_desc: Use image node_id 1 for calling a global function with example usage: conbytes() and returns: ConstrainedBytesWithRegex, value