def data_must_be_url_or_base64(cls, v, values): if values['type'] == 'url': return AnyUrl.validate(v) elif values['type'] == 'b64': match = re.match( "^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$", v) if match is not None: return match.group(0) else: raise ValueError()
def validate( # type: ignore cls, value: str, field: "ModelField", config: "BaseConfig" ) -> Union["AnyUrl", str]: """ """ if value.startswith("mailto:"): schema = value[0:7] email = value[7:] realname = parseaddr(email)[0] name, email = validate_email(email) if realname: email = formataddr((name, email)) return schema + email elif value.startswith("mllp:") or value.startswith("llp:"): # xxx: find validation return value elif value in FHIR_PRIMITIVES: # Extensions may contain a valueUrl for a primitive FHIR type return value return AnyUrl.validate(value, field, config)