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)"))
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)
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")
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 )
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()
class Place(typesystem.Schema): active = typesystem.Boolean() address = typesystem.String(allow_null=True) cuisine = typesystem.String(allow_null=True) cuisine_slugs = typesystem.Array(allow_null=True, items=typesystem.String(allow_null=True)) cuisines = typesystem.Array(allow_null=True, items=typesystem.String(allow_null=True)) curbside = typesystem.Boolean(default=False) curbside_instructions = typesystem.String(allow_null=True) delivery = typesystem.Boolean(default=False) delivery_service_websites = typesystem.String(allow_null=True) dinein = typesystem.Boolean(default=False) facebook_url = typesystem.String(allow_null=True) featured = typesystem.Boolean(default=False) food_urls = typesystem.Array(allow_null=True, items=typesystem.Reference(allow_null=True, to=Url)) giftcard = typesystem.Boolean(default=False) giftcard_notes = typesystem.String(allow_null=True) giftcard_url = typesystem.String(allow_null=True) hours = typesystem.String(allow_null=True) instagram_url = typesystem.String(allow_null=True) locality = typesystem.String( allow_null=True) # set default to a variable like "Lawrence" name = typesystem.String() neighborhood = typesystem.String(allow_null=True) neighborhood_slug = typesystem.String(allow_null=True) notes = typesystem.String(allow_blank=True) perma_closed = typesystem.Boolean(allow_null=True) place_type = typesystem.String(allow_null=True) region = typesystem.String(allow_null=True) restaurant_phone = typesystem.String(allow_null=True) sitemap = typesystem.Boolean() slug = typesystem.String() takeout = typesystem.Boolean(default=False) twitch_url = typesystem.String(allow_null=True) twitter_url = typesystem.String(allow_null=True) website = typesystem.String(allow_null=True)
async def upload(request): username = request.path_params["username"] table_id = request.path_params["table_id"] can_edit = check_can_edit(request, username) datasource = await load_datasource_or_404(username, table_id) form = await request.form() data = await form["upload-file"].read() encoding = chardet.detect(data)["encoding"] lines = data.decode(encoding).splitlines() rows = normalize_table([row for row in csv.reader(lines)]) column_identities = determine_column_identities(rows) column_types, schema = determine_column_types(rows) unvalidated_data = [dict(zip(column_identities, row)) for row in rows[1:]] validated_data = [ dict(instance) for instance in typesystem.Array(items=typesystem.Reference( to=schema)).validate(unvalidated_data, strict=False) ] column_insert_values = [{ "created_at": datetime.datetime.now(), "name": name, "identity": column_identities[idx], "datatype": column_types[idx], "table": datasource.table["pk"], "position": idx + 1, } for idx, name in enumerate(rows[0])] query = tables.column.insert() await database.execute_many(query, column_insert_values) row_insert_values = [{ "created_at": datetime.datetime.now(), "uuid": str(uuid.uuid4()), "table": datasource.table["pk"], "data": validated_data[idx], "search_text": " ".join(row), } for idx, row in enumerate(rows[1:])] query = tables.row.insert() await database.execute_many(query, row_insert_values) url = request.url_for("table", username=username, table_id=table_id) return RedirectResponse(url=url, status_code=303)
class BlogPost(typesystem.Schema): text = typesystem.String() modified = typesystem.Array(typesystem.Date())
class GroupSchema(typesystem.Schema): name = typesystem.String(title="Name") users = typesystem.Array(ObjectChoice(choices=_users), title="users")
class ExampleE(typesystem.Schema, definitions=definitions): field_on_e = typesystem.Integer() example_f = typesystem.Array(items=[typesystem.Reference("ExampleF")])
class Poll(typesystem.Schema): title = typesystem.String(max_length=100) options = typesystem.Array(items=typesystem.String(), unique_items=True) multi = typesystem.Boolean(default=False) suspended = typesystem.Boolean(default=False) creator = typesystem.String(allow_null=True)
class Album(typesystem.Schema): title = typesystem.String(max_length=100) release_year = typesystem.Integer() artists = typesystem.Array(items=typesystem.Reference(Artist), allow_null=True)
class NumberName(typesystem.Schema): pair = typesystem.Array([typesystem.Integer(), typesystem.String()])
class Product(typesystem.Schema): names = typesystem.Array(typesystem.String())
import typesystem definitions = typesystem.SchemaDefinitions() JSON_SCHEMA = ( typesystem.Object( properties={ "$ref": typesystem.String(), "type": typesystem.String() | typesystem.Array(items=typesystem.String()), "enum": typesystem.Array(unique_items=True, min_items=1), "definitions": typesystem.Object(additional_properties=typesystem.Reference( "JSONSchema", definitions=definitions)), # String "minLength": typesystem.Integer(minimum=0), "maxLength": typesystem.Integer(minimum=0), "pattern": typesystem.String(format="regex"), "format": typesystem.String(), # Numeric "minimum": typesystem.Number(), "maximum": typesystem.Number(), "exclusiveMinimum":
SWAGGER = typesystem.Object( title="Swagger", properties={ "swagger": typesystem.String(), "info": typesystem.Reference("Info", definitions=definitions), "paths": typesystem.Reference("Paths", definitions=definitions), "host": typesystem.String(), "basePath": typesystem.String(pattern="^/"), "schemes": typesystem.Array(items=typesystem.Choice( choices=["http", "https", "ws", "wss"])), "consumes": typesystem.Array(items=typesystem.String()), "produces": typesystem.Array(items=typesystem.String()), "definitions": typesystem.Object(additional_properties=typesystem.Any()), "parameters": typesystem.Object(additional_properties=typesystem.Reference( "Parameters", definitions=definitions)), "responses": typesystem.Object(additional_properties=typesystem.Reference( "Responses", definitions=definitions)), "securityDefinitions": typesystem.Object(additional_properties=typesystem.Reference( "SecurityScheme", definitions=definitions)),
class BarsSchema(typesystem.Schema): bars = typesystem.Array(typesystem.Reference(to=BarSchema))
REQUESTBODY_REF = typesystem.Object( properties={"$ref": typesystem.String(pattern="^#/components/requestBodies/")} ) RESPONSE_REF = typesystem.Object( properties={"$ref": typesystem.String(pattern="^#/components/responses/")} ) definitions = typesystem.SchemaDefinitions() OPEN_API = typesystem.Object( title="OpenAPI", properties={ "openapi": typesystem.String(), "info": typesystem.Reference("Info", definitions=definitions), "servers": typesystem.Array( items=typesystem.Reference("Server", definitions=definitions) ), "paths": typesystem.Reference("Paths", definitions=definitions), "components": typesystem.Reference("Components", definitions=definitions), "security": typesystem.Array( items=typesystem.Reference("SecurityRequirement", 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,
class ExampleC(typesystem.Schema, definitions=definitions): field_on_c = typesystem.Integer() example_d = typesystem.Array(items=typesystem.Reference("ExampleD"))