예제 #1
0
class Comment(CSVColumn, typesystem.Schema):
    starts_with = "#/"
    description = typesystem.Text()

    def __hash__(self):
        return hash(self.description)

    def __eq__(self, other):
        if isinstance(other, Comment):
            return self.description == other.description

        return NotImplemented
예제 #2
0
class IssuePosition(CSVColumn, typesystem.Schema):
    """
    #M;Issue ID;position;meaning;
    """

    starts_with = "#M"
    issue = typesystem.String()
    position = typesystem.Number()
    description = typesystem.Text(allow_blank=True, allow_null=True)

    def __hash__(self):
        return hash(self.issue)

    def __eq__(self, other):
        if isinstance(other, PartialIssue):
            return self.issue == other.issue and self.position == other.position

        return NotImplemented
예제 #3
0
class PartialIssue(CSVColumn, typesystem.Schema):
    """
    An issue as referenced in the csv data file
    """
    starts_with = "#P"
    name = typesystem.String()
    description = typesystem.Text(allow_blank=True, allow_null=True)

    def __init__(self, *args, **kwargs):
        super(PartialIssue, self).__init__(*args, **kwargs)
        self.lower = None
        self.upper = None

    def __hash__(self):
        return hash(self.name)

    def __eq__(self, other):

        if isinstance(other, str):
            return self.name == other

        if isinstance(other, PartialIssue):
            return self.name == other.name

        return NotImplemented

    def __lt__(self, other):
        return self.name < other.name

    def validate_interval(self):

        if self.lower > self.upper:
            raise ValidationError(key='interval',
                                  text='lower needs to be less then upper')

    def as_model_object(self):

        issue = base.Issue(self.name, self.lower, self.upper)

        return issue
예제 #4
0
class ActorIssue(CSVColumn, typesystem.Schema):
    """
    #A;actor;issue;position;salience;power
    """

    starts_with = "#D"
    actor = typesystem.String()
    issue = typesystem.String()
    position = typesystem.Decimal()
    salience = typesystem.Decimal(minimum=0, maximum=100)
    power = typesystem.Decimal(minimum=0, maximum=100)
    comment = typesystem.Text(allow_blank=True, allow_null=True)

    def __str__(self):
        return str(self.actor) + "-" + str(self.issue)

    def __hash__(self):
        return hash(self.__str__())

    def __eq__(self, other):

        if isinstance(other, PartialIssue):
            return self.__str__() == other.__str__()

        return NotImplemented

    def __lt__(self, other):
        return self.issue.__lt__(other.issue)

    def validate_position(self, issue: PartialIssue):

        issue.validate_interval()

        if not issue.lower <= self.position <= issue.upper:
            raise ValidationError(
                key='position',
                text='exceeds the issue interval of {}-{}'.format(
                    issue.lower, issue.upper))
예제 #5
0
 class DetailedProduct(Product):
     info = typesystem.Text()
예제 #6
0
                                                    definitions=definitions)),
        "tags":
        typesystem.Array(
            items=typesystem.Reference("Tag", definitions=definitions)),
        "externalDocs":
        typesystem.Reference("ExternalDocumentation", definitions=definitions),
    },
    pattern_properties={"^x-": typesystem.Any()},
    additional_properties=False,
    required=["swagger", "info", "paths"],
)

definitions["Info"] = typesystem.Object(
    properties={
        "title": typesystem.String(allow_blank=True),
        "description": typesystem.Text(allow_blank=True),
        "termsOfService": typesystem.String(format="url"),
        "contact": typesystem.Reference("Contact", definitions=definitions),
        "license": typesystem.Reference("License", definitions=definitions),
        "version": typesystem.String(allow_blank=True),
    },
    pattern_properties={"^x-": typesystem.Any()},
    additional_properties=False,
    required=["title", "version"],
)

definitions["Contact"] = typesystem.Object(
    properties={
        "name": typesystem.String(allow_blank=True),
        "url": typesystem.String(format="url"),
        "email": typesystem.String(format="email"),
예제 #7
0
 def get_validator(self, **kwargs) -> typesystem.Field:
     return typesystem.Text(**kwargs)
예제 #8
0
class Contact(typesystem.Schema):
    a = typesystem.Boolean()
    b = typesystem.String(max_length=10)
    c = typesystem.Text()
    d = typesystem.Choice(choices=[("abc", "Abc"), ("def",
                                                    "Def"), ("ghi", "Ghi")])
예제 #9
0
class Contact(typesystem.Schema):
    a = typesystem.Boolean()
    b = typesystem.String(max_length=10)
    c = typesystem.Text()
    d = typesystem.Choice(choices=["abc", "def", "ghi"])
예제 #10
0
class SongSchema(typesystem.Schema):
    title = typesystem.String(max_length=255)
    content = typesystem.Text()

    def __str__(self) -> str:
        return self.title