コード例 #1
0
class PasswordFormSchema(typesystem.Schema):
    password = typesystem.String(title="Password",
                                 allow_null=False,
                                 format="password")
    password_confirm = typesystem.String(title="Password (confirm)",
                                         allow_null=False,
                                         format="password")
コード例 #2
0
class PartialActor(CSVColumn, typesystem.Schema):
    starts_with = "#A"
    id = typesystem.String()
    fullname = typesystem.String(allow_blank=True)
    comment = typesystem.String(allow_blank=True)

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

    def __eq__(self, other):

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

        if isinstance(other, PartialActor):
            return self.id == other.id

        return NotImplemented

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

    def as_model_object(self):

        actor = base.Actor(self.id, self.fullname)

        return actor
コード例 #3
0
class ItemSchema(typesystem.Schema):
    form_title = typesystem.String(title="title", max_length=40)
    form_descr = typesystem.String(
        title="description",
        max_length=120,
        default=str("Enter description of a weapon"))
    form_owner = typesystem.String(title="owner", max_length=40)
コード例 #4
0
class Issue(PartialIssue):
    """
    An issue from the InputWindow
    """
    name = typesystem.String()
    upper = typesystem.Float()
    lower = typesystem.Float()
    comment = typesystem.String(allow_blank=True)
コード例 #5
0
class AuthenticationResultType(typesystem.Schema):
    AccessToken = typesystem.String(pattern=r"[A-Za-z0-9_=.-]+")
    ExpiresIn = typesystem.Integer()
    TokenType = typesystem.String()
    RefreshToken = typesystem.String(pattern=r"[A-Za-z0-9_=.-]+")
    IdToken = typesystem.String(pattern=r"[A-Za-z0-9_=.-]+")
    NewDeviceMetadata = typesystem.Reference(NewDeviceMetadataType,
                                             allow_null=True)
コード例 #6
0
ファイル: schemas.py プロジェクト: mbeacom/starlette-jsonrpc
class JSONRPCResponse(typesystem.Schema):
    jsonrpc = typesystem.String(pattern="2.0", trim_whitespace=False)
    id = typesystem.Union(any_of=[
        typesystem.String(allow_null=True, min_length=1,
                          trim_whitespace=False),
        typesystem.Integer(allow_null=True),
    ])
    result = typesystem.Object()
コード例 #7
0
class RecaptchaResponse(typesystem.Schema):
    success = typesystem.Boolean(default=False)
    challenge_ts = typesystem.String(allow_null=True)
    hostname = typesystem.String(allow_null=True)
    score = typesystem.Float(allow_null=True)
    action = typesystem.String(allow_blank=True)
    error_codes = typesystem.Array(
        title="error-codes", items=typesystem.String(), allow_null=True
    )
コード例 #8
0
class GetIdRequest(typesystem.Schema):
    AccountId = typesystem.String(min_length=1,
                                  max_length=15,
                                  pattern=r"^\d+$",
                                  allow_null=True)
    IdentityPoolId = typesystem.String(min_length=1,
                                       max_length=55,
                                       pattern=r"^[\w-]+:[0-9a-f-]+$")
    Logins = typesystem.Object(allow_null=False)
コード例 #9
0
class UserRegistrationSchema(typesystem.Schema):
    email = typesystem.String(title="email",
                              max_length=50,
                              format="email",
                              description="*****@*****.**")
    password = typesystem.String(title="password",
                                 max_length=40,
                                 format="password")
    confirm_password = typesystem.String(title="confirm_password",
                                         max_length=40,
                                         format="password")
コード例 #10
0
ファイル: schemas.py プロジェクト: zer0n1/ceryx
class Settings(BaseSchema):
    enforce_https = typesystem.Boolean(default=False)
    mode = typesystem.Choice(
        choices=(
            ("proxy", "Proxy"),
            ("redirect", "Redirect"),
        ),
        default="proxy",
    )
    certificate_path = typesystem.String(allow_null=True)
    key_path = typesystem.String(allow_null=True)
コード例 #11
0
class JSONRPCRequest(typesystem.Schema):
    jsonrpc = typesystem.String(pattern="2.0", trim_whitespace=False)
    id = typesystem.Union(
        any_of=[
            typesystem.String(allow_null=True, min_length=1, trim_whitespace=False),
            typesystem.Integer(allow_null=True),
        ]
    )
    params = typesystem.Union(
        any_of=[typesystem.Object(additional_properties=True), typesystem.Array()]
    )
    method = typesystem.String()
コード例 #12
0
ファイル: schemas.py プロジェクト: w4tsn/ceryx
class Route(BaseSchema):
    DEFAULT_SETTINGS = dict(Settings.validate({}))

    source = typesystem.String()
    target = typesystem.String()
    settings = typesystem.Reference(Settings, default=DEFAULT_SETTINGS)

    @classmethod
    def validate(cls, data):
        if "target" in data.keys():
            data["target"] = ensure_protocol(data["target"])
        return super().validate(data)
コード例 #13
0
ファイル: forms.py プロジェクト: artisdom/yeoboseyo
class TriggerSchema(typesystem.Schema):
    """
       Schema to define the structure of a Trigger
    """
    description = typesystem.String(title="Description", max_length=200)
    rss_url = typesystem.String(title="RSS URL", max_length=255)
    joplin_folder = typesystem.String(title="Joplin Folder", max_length=80, allow_null=True)
    reddit = typesystem.String(title="Subreddit", max_length=80, allow_null=True)
    mail = typesystem.Boolean(title="Send a mail ?", default=False)
    mastodon = typesystem.Boolean(title="Publish on Mastodon ?", default=False)
    localstorage = typesystem.String(title="Markdown Folder")
    status = typesystem.Boolean(title="Status", default=False)
コード例 #14
0
ファイル: schemas.py プロジェクト: w4tsn/ceryx
class Settings(BaseSchema):
    enforce_https = typesystem.Boolean(default=False)
    mode = typesystem.Choice(
        choices=(
            ("proxy", "Proxy"),
            ("redirect", "Redirect"),
        ),
        default="proxy",
    )
    headers = typesystem.Object(default={}, properties=typesystem.String(max_length=100))
    ttl = typesystem.Integer(allow_null=True)
    certificate_path = typesystem.String(allow_null=True)
    key_path = typesystem.String(allow_null=True)
コード例 #15
0
ファイル: serializers.py プロジェクト: antwan/mobilewallet
class Transaction(typesystem.Schema):
    sender = typesystem.String(title='Sender account', format='uuid')
    recipient = typesystem.String(title='Recipient account', format='uuid')
    amount = typesystem.Integer(title='Transaction amount', exclusive_minimum=0)
    label = typesystem.String(title='Label', max_length=100, default='')
    created_at = typesystem.DateTime(title='Date created', default=datetime.utcnow())

    @classmethod
    def validate(cls, *args, **kwargs):
        ret = super().validate(*args, **kwargs)
        if ret['sender'] == ret['recipient']:
            raise typesystem.ValidationError(
                text='Sender and recipient account should be different',
                code='identical_accounts'
            )
        return ret
コード例 #16
0
ファイル: datasource.py プロジェクト: realsby/hostedapi
    def __init__(self, username, table, columns=None):
        self.name = table["name"]
        self.url = url_for("table",
                           username=username,
                           table_id=table["identity"])
        self.username = username
        self.table = table
        self.columns = columns
        self.query_limit = None
        self.query_offset = None
        self.uuid_filter = None
        self.search_term = None
        self.sort_func = None
        self.sort_reverse = False

        if columns is not None:
            fields = {}
            for column in columns:
                if column["datatype"] == "string":
                    fields[column["identity"]] = typesystem.String(
                        title=column["name"], max_length=100)
                elif column["datatype"] == "integer":
                    fields[column["identity"]] = typesystem.Integer(
                        title=column["name"])
            self.schema = type("Schema", (typesystem.Schema, ), fields)
コード例 #17
0
class Organization(typesystem.Schema):
    id = typesystem.Integer(allow_null=True)
    name = typesystem.String(max_length=50, allow_blank=True)
    user = typesystem.Reference(users_serializers.UserRef, allow_null=True)

    async def get_object(self) -> warehouse_models.Organization:
        return await warehouse_models.Organization.objects.get(id=self.id)
コード例 #18
0
class InitiateAuthResponse(typesystem.Schema):
    ChallengeName = typesystem.Choice(choices=list(ChallengeNameType),
                                      allow_null=True)
    Session = typesystem.String(max_length=2048, allow_null=True)
    ChallengeParameters = typesystem.Object(allow_null=True)
    AuthenticationResult = typesystem.Reference(AuthenticationResultType,
                                                allow_null=True)
コード例 #19
0
class UserPoolSchema(typesystem.Schema):
    name = typesystem.String(title="Name")
    alias_attributes = typesystem.Array(
        Choice(title="Alias attributes", choices=UserIdentityAttribute),
        unique_items=True,
        default=[],
    )
    auto_verified_attributes = typesystem.Array(
        Choice(title="Auto-verified attributes",
               choices=AuxiliaryIdentityAttribute),
        unique_items=True,
        default=[],
    )
    username_attributes = typesystem.Array(
        Choice(
            title=
            "Username attributes (if none selected, username will be used)",
            choices=AuxiliaryIdentityAttribute,
        ),
        unique_items=True,
        default=[],
    )
    username_case_sensitiveness = typesystem.Boolean(
        title=("User names are case sensitive"
               "(e-mail addresses are treated insensitively by default)"))
コード例 #20
0
class ClientSchema(typesystem.Schema):
    name = typesystem.String(title="Name")
    oauth2_client_id = typesystem.String(title="Client ID", allow_null=True)
    oauth2_client_secret = typesystem.String(title="Client secret",
                                             allow_null=True)
    ttl_for_authorization_code = typesystem.String(
        title="Authorization code TTL", allow_null=True)
    ttl_for_implicit = typesystem.String(title="Implicit token TTL",
                                         allow_null=True)
    ttl_for_refresh_token = typesystem.String(title="Refresh token TTL",
                                              allow_null=True)
    authn_max_age = typesystem.String(title="OpenID Connect ID token max age",
                                      allow_null=True)
    redirect_uris = typesystem.Array(typesystem.String(),
                                     title="Redirect URIs")
    logout_uris = typesystem.Array(typesystem.String(), title="Logout URIs")
    scopes = typesystem.Array(typesystem.String(), title="Scopes")
コード例 #21
0
def test_to_json_schema_complex_regular_expression():
    field = typesystem.String(pattern=re.compile("foo", re.IGNORECASE
                                                 | re.VERBOSE))
    with pytest.raises(ValueError) as exc_info:
        to_json_schema(field)

    expected = ("Cannot convert regular expression with non-standard flags "
                "to JSON schema: RegexFlag.")
    assert str(exc_info.value).startswith(expected)
コード例 #22
0
class InitiateAuthRequest(typesystem.Schema):
    AuthFlow = typesystem.Choice(choices=list(AuthFlowType))
    AuthParameters = typesystem.Object()
    ClientMetadata = typesystem.Object(allow_null=True)
    ClientId = typesystem.String()
    AnalyticsMetadata = typesystem.Reference(AnalyticsMetadataType,
                                             allow_null=True)
    UserContextData = typesystem.Reference(UserContextDataType,
                                           allow_null=True)
コード例 #23
0
def test_validation_error_repr():
    result = Example.validate_or_error({"a": "a"})
    assert (
        repr(result.error) ==
        "ValidationError([Message(text='This field is required.', code='required', index=['b'])])"
    )

    result = typesystem.String(max_length=10).validate_or_error("a" * 100)
    assert (
        repr(result.error) ==
        "ValidationError(text='Must have no more than 10 characters.', code='max_length')"
    )
コード例 #24
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))
コード例 #25
0
ファイル: numpyschema.py プロジェクト: alexpearce/scikit-hep
 def isinstance(self, datum):
     if not isinstance(datum, numpy.generic):
         # if not Numpy, check as pure Python
         return typesystem.String(self.charset,
                                  self.maxlength).isinstance(datum)
     ok = False
     if self.charset == "bytes":
         ok = isinstance(datum, numpy.string_)
     if self.charset == "utf-32le":
         # Numpy uses utf-32le to encode Unicode (on a little-endian machine, at least)
         ok = isinstance(datum, numpy.unicode_)
     if ok and self.maxlength is not None:
         ok = ok and datum.dtype.itemsize <= self.maxlength
     return ok
コード例 #26
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
コード例 #27
0
ファイル: sync.py プロジェクト: tiepdotme/lfk.im
class Cuisine(typesystem.Schema):
    active = typesystem.Boolean(default=True)
    aliases = typesystem.Array(allow_null=True,
                               default=list,
                               items=typesystem.String(allow_blank=True))
    description = typesystem.String(allow_blank=True)
    name = typesystem.String()
    redirect_from = typesystem.Array(allow_null=True,
                                     default=list,
                                     items=typesystem.String(allow_blank=True))
    sitemap = typesystem.Boolean(default=True)
    slug = typesystem.String()
    title = typesystem.String(allow_blank=True)
コード例 #28
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
コード例 #29
0
def app():
    users = dashboard.MockDataSource(
        schema=typesystem.Schema(
            fields={
                "pk":
                typesystem.Integer(title="Identity",
                                   read_only=True,
                                   default=dashboard.autoincrement()),
                "username":
                typesystem.String(title="Username", max_length=100),
                "is_admin":
                typesystem.Boolean(title="Is Admin", default=False),
                "joined":
                typesystem.DateTime(title="Joined",
                                    read_only=True,
                                    default=datetime.datetime.now),
            }),
        initial=[{
            "username": f"user{i}@example.org",
            "is_admin": False,
        } for i in range(123)],
    )

    user_table = dashboard.DashboardTable(ident="users",
                                          title="Users",
                                          datasource=users)
    admin = dashboard.Dashboard(tables=[user_table])

    return Starlette(routes=[
        Mount(
            "/admin",
            admin,
            name="dashboard",
        ),
        Mount("/statics", ..., name="static"),
    ])
コード例 #30
0
 class GroupSchema(typesystem.Schema):
     name = typesystem.String(title="Name")
     users = typesystem.Array(ObjectChoice(choices=_users),
                              title="users")