Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New custom type - Regex #7

Open
smailq opened this issue Mar 7, 2014 · 0 comments
Open

New custom type - Regex #7

smailq opened this issue Mar 7, 2014 · 0 comments

Comments

@smailq
Copy link
Member

smailq commented Mar 7, 2014

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants