Skip to content

New custom type - Regex #7

@smailq

Description

@smailq

I've implemented a Regex - primitive parametrized type that matches regular expression on the string.

Should this be included as a basic type? or some sort of plugin/extension?

import re
from teleport import ValidationError, ParametrizedPrimitive, Schema

class Regex(ParametrizedPrimitive):
  param_schema = Schema

  def from_json(self, datum):
    if re.match(self.param, datum) is None:
      raise ValidationError("Regex '%s' does not match " % self.param, datum)
    return datum

  def to_json(self, datum):
    return datum

Also, should I validate if datum is indeed a String?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions