biothings.web.options

biothings.web.options.manager

Request Argument Standardization

class biothings.web.options.manager.Converter(**kwargs)[source]

Bases: object

A generic HTTP request argument processing unit. Only perform one level of validation at this moment. The strict switch controls the type conversion rules.

convert(value)[source]
convert_to(value, to_type)[source]
static str_to_bool(val)[source]

Interpret string representation of bool values.

str_to_int(val)[source]

Convert a numerical string to an integer.

static str_to_list(val)[source]

Cast Biothings-style str to list.

classmethod subclasses(kwargs)[source]
static to_type(val, type_)[source]

Native type casting in Python. Fallback approach for type casting.

translate(value)[source]
class biothings.web.options.manager.Existentialist(defdict)[source]

Bases: object

Describes the requirement of the existance of an argument. {

“default”: <object>, “required”: <bool>,

}

inquire(obj)[source]
class biothings.web.options.manager.FormArgCvter(**kwargs)[source]

Bases: biothings.web.options.manager.Converter

Dedicated argument converter for HTTP body arguments. Additionally support JSON seriealization format as values. Correspond to arguments received in tornado from

RequestHandler.get_body_argument

See https://www.tornadoweb.org/en/stable/web.html

convert_to(value, to_type)[source]
class biothings.web.options.manager.JsonArgCvter(**kwargs)[source]

Bases: biothings.web.options.manager.Converter

Dedicated argument converter for JSON HTTP bodys. Here it is used for dict JSON objects, with their first level keys considered as parameters and their values considered as arguments to process.

May correspond to this tornado implementation: https://www.tornadoweb.org/en/stable/web.html#input

convert_to(value, to_type)[source]
to_type(val, type_)[source]

Native type casting in Python. Fallback approach for type casting.

class biothings.web.options.manager.Locator(defdict)[source]

Bases: object

Describes the location of an argument in ReqArgs. {

“keyword”: <str>, “path”: <int or str>, “alias”: <str or [<str>, …]>

}

lookin(location)[source]

Find an argument in the specified location. Use directions indicated in this locator.

class biothings.web.options.manager.Option(*args, **kwargs)[source]

Bases: collections.UserDict

A parameter for end applications to consume. Find the value of it in the desired location.

For example: {

“keyword”: “q”, “location”: (“query”, “form”, “json”), “default”: “__all__”, “type”: “str”

}

parse(reqargs)[source]
exception biothings.web.options.manager.OptionError(reason=None, **kwargs)[source]

Bases: ValueError

simplify()[source]
class biothings.web.options.manager.OptionSet(*args, **kwargs)[source]

Bases: collections.UserDict

A collection of options that a specific endpoint consumes. Divided into groups and by the request methods.

For example: {

“*”:{“raw”:{…},”size”:{…},”dotfield”:{…}}, “GET”:{“q”:{…},”from”:{…},”sort”:{…}}, “POST”:{“q”:{…},”scopes”:{…}}

}

parse(method, reqargs)[source]

Parse a HTTP request, represented by its method and args, with this OptionSet and return an attribute dictionary.

setup()[source]

Apply the wildcard method configurations dict. Must call this method after changes to this object.

class biothings.web.options.manager.OptionsManager(**kwargs)[source]

Bases: collections.UserDict

A collection of OptionSet(s) that makes up an application. Provide an interface to setup and serialize.

Example: {

“annotation”: {“*”: {…}, “GET”: {…}, “POST”: {… }}, “query”: {“*”: {…}, “GET”: {…}, “POST”: {… }}, “metadata”: {“GET”: {…}, “POST”: {… }}

}

add(name, optionset, groups=())[source]
log()[source]
class biothings.web.options.manager.PathArgCvter(**kwargs)[source]

Bases: biothings.web.options.manager.Converter

Dedicated argument converter for path arguments. Correspond to arguments received in tornado for

RequestHandler.path_args RequestHandler.path_kwargs

See https://www.tornadoweb.org/en/stable/web.html

class biothings.web.options.manager.QueryArgCvter(**kwargs)[source]

Bases: biothings.web.options.manager.Converter

Dedicated argument converter for url query arguments. Correspond to arguments received in tornado from

RequestHandler.get_query_argument

See https://www.tornadoweb.org/en/stable/web.html

classmethod str_to_bool(val)[source]

Biothings-style str to bool interpretation

class biothings.web.options.manager.ReqArgs(path=None, query=None, form=None, json_=None)[source]

Bases: object

class Path(args=(), kwargs={})[source]

Bases: object

lookup(locator, order=None, src=False)[source]
class biothings.web.options.manager.ReqResult[source]

Bases: biothings.utils.common.dotdict

class biothings.web.options.manager.Validator(defdict)[source]

Bases: object

Describes the requirement of the existance of an argument. {

“enum”: <container>, “max”: <int>

}

validate(obj)[source]

biothings.web.options.openapi

class biothings.web.options.openapi.OpenAPIContactContext(parent)[source]

Bases: biothings.web.options.openapi._ChildContext

ATTRIBUTE_FIELDS = {'email': 'email', 'name': 'name', 'url': 'url'}
EXTENSION = True
email(v)

Set email field

name(v)

Set name field

subclasses: MutableMapping[str, Type[biothings.web.options.openapi._ChildContext]] = {'OpenAPIContactContext': <class 'biothings.web.options.openapi.OpenAPIContactContext'>, 'OpenAPIContext': <class 'biothings.web.options.openapi.OpenAPIContext'>, 'OpenAPIExternalDocsContext': <class 'biothings.web.options.openapi.OpenAPIExternalDocsContext'>, 'OpenAPIInfoContext': <class 'biothings.web.options.openapi.OpenAPIInfoContext'>, 'OpenAPILicenseContext': <class 'biothings.web.options.openapi.OpenAPILicenseContext'>, 'OpenAPIOperation': <class 'biothings.web.options.openapi.OpenAPIOperation'>, 'OpenAPIParameterContext': <class 'biothings.web.options.openapi.OpenAPIParameterContext'>, 'OpenAPIPathItemContext': <class 'biothings.web.options.openapi.OpenAPIPathItemContext'>, '_BaseContext': <class 'biothings.web.options.openapi._BaseContext'>, '_ChildContext': <class 'biothings.web.options.openapi._ChildContext'>, '_HasDescription': <class 'biothings.web.options.openapi._HasDescription'>, '_HasExternalDocs': <class 'biothings.web.options.openapi._HasExternalDocs'>, '_HasParameters': <class 'biothings.web.options.openapi._HasParameters'>, '_HasSummary': <class 'biothings.web.options.openapi._HasSummary'>, '_HasTags': <class 'biothings.web.options.openapi._HasTags'>}
url(v)

Set url field

class biothings.web.options.openapi.OpenAPIContext[source]

Bases: biothings.web.options.openapi._HasExternalDocs

CHILD_CONTEXTS = {'info': ('OpenAPIInfoContext', 'info')}
EXTENSION = True
info(**kwargs)

Set info Create OpenAPIInfoContext and set info

path(path: str, summary: Optional[str] = None, description: Optional[str] = None)[source]
server(url: str, description: Optional[str] = None)[source]
subclasses: MutableMapping[str, Type[biothings.web.options.openapi._ChildContext]] = {'OpenAPIContactContext': <class 'biothings.web.options.openapi.OpenAPIContactContext'>, 'OpenAPIContext': <class 'biothings.web.options.openapi.OpenAPIContext'>, 'OpenAPIExternalDocsContext': <class 'biothings.web.options.openapi.OpenAPIExternalDocsContext'>, 'OpenAPIInfoContext': <class 'biothings.web.options.openapi.OpenAPIInfoContext'>, 'OpenAPILicenseContext': <class 'biothings.web.options.openapi.OpenAPILicenseContext'>, 'OpenAPIOperation': <class 'biothings.web.options.openapi.OpenAPIOperation'>, 'OpenAPIParameterContext': <class 'biothings.web.options.openapi.OpenAPIParameterContext'>, 'OpenAPIPathItemContext': <class 'biothings.web.options.openapi.OpenAPIPathItemContext'>, '_BaseContext': <class 'biothings.web.options.openapi._BaseContext'>, '_ChildContext': <class 'biothings.web.options.openapi._ChildContext'>, '_HasDescription': <class 'biothings.web.options.openapi._HasDescription'>, '_HasExternalDocs': <class 'biothings.web.options.openapi._HasExternalDocs'>, '_HasParameters': <class 'biothings.web.options.openapi._HasParameters'>, '_HasSummary': <class 'biothings.web.options.openapi._HasSummary'>, '_HasTags': <class 'biothings.web.options.openapi._HasTags'>}
biothings.web.options.openapi.OpenAPIDocumentBuilder

alias of biothings.web.options.openapi.OpenAPIContext

class biothings.web.options.openapi.OpenAPIExternalDocsContext(parent)[source]

Bases: biothings.web.options.openapi._ChildContext, biothings.web.options.openapi._HasDescription

ATTRIBUTE_FIELDS = {'url': 'url'}
EXTENSION = True
subclasses: MutableMapping[str, Type[biothings.web.options.openapi._ChildContext]] = {'OpenAPIContactContext': <class 'biothings.web.options.openapi.OpenAPIContactContext'>, 'OpenAPIContext': <class 'biothings.web.options.openapi.OpenAPIContext'>, 'OpenAPIExternalDocsContext': <class 'biothings.web.options.openapi.OpenAPIExternalDocsContext'>, 'OpenAPIInfoContext': <class 'biothings.web.options.openapi.OpenAPIInfoContext'>, 'OpenAPILicenseContext': <class 'biothings.web.options.openapi.OpenAPILicenseContext'>, 'OpenAPIOperation': <class 'biothings.web.options.openapi.OpenAPIOperation'>, 'OpenAPIParameterContext': <class 'biothings.web.options.openapi.OpenAPIParameterContext'>, 'OpenAPIPathItemContext': <class 'biothings.web.options.openapi.OpenAPIPathItemContext'>, '_BaseContext': <class 'biothings.web.options.openapi._BaseContext'>, '_ChildContext': <class 'biothings.web.options.openapi._ChildContext'>, '_HasDescription': <class 'biothings.web.options.openapi._HasDescription'>, '_HasExternalDocs': <class 'biothings.web.options.openapi._HasExternalDocs'>, '_HasParameters': <class 'biothings.web.options.openapi._HasParameters'>, '_HasSummary': <class 'biothings.web.options.openapi._HasSummary'>, '_HasTags': <class 'biothings.web.options.openapi._HasTags'>}
url(v)

Set url field

class biothings.web.options.openapi.OpenAPIInfoContext(parent)[source]

Bases: biothings.web.options.openapi._ChildContext, biothings.web.options.openapi._HasDescription

ATTRIBUTE_FIELDS = {'terms_of_service': 'termsOfService', 'title': 'title', 'version': 'version'}
CHILD_CONTEXTS = {'contact': ('OpenAPIContactContext', 'contact'), 'license': ('OpenAPILicenseContext', 'license')}
EXTENSION = True
contact(**kwargs)

Set contact Create OpenAPIContactContext and set contact

license(**kwargs)

Set license Create OpenAPILicenseContext and set license

subclasses: MutableMapping[str, Type[biothings.web.options.openapi._ChildContext]] = {'OpenAPIContactContext': <class 'biothings.web.options.openapi.OpenAPIContactContext'>, 'OpenAPIContext': <class 'biothings.web.options.openapi.OpenAPIContext'>, 'OpenAPIExternalDocsContext': <class 'biothings.web.options.openapi.OpenAPIExternalDocsContext'>, 'OpenAPIInfoContext': <class 'biothings.web.options.openapi.OpenAPIInfoContext'>, 'OpenAPILicenseContext': <class 'biothings.web.options.openapi.OpenAPILicenseContext'>, 'OpenAPIOperation': <class 'biothings.web.options.openapi.OpenAPIOperation'>, 'OpenAPIParameterContext': <class 'biothings.web.options.openapi.OpenAPIParameterContext'>, 'OpenAPIPathItemContext': <class 'biothings.web.options.openapi.OpenAPIPathItemContext'>, '_BaseContext': <class 'biothings.web.options.openapi._BaseContext'>, '_ChildContext': <class 'biothings.web.options.openapi._ChildContext'>, '_HasDescription': <class 'biothings.web.options.openapi._HasDescription'>, '_HasExternalDocs': <class 'biothings.web.options.openapi._HasExternalDocs'>, '_HasParameters': <class 'biothings.web.options.openapi._HasParameters'>, '_HasSummary': <class 'biothings.web.options.openapi._HasSummary'>, '_HasTags': <class 'biothings.web.options.openapi._HasTags'>}
terms_of_service(v)

Set termsOfService field

title(v)

Set title field

version(v)

Set version field

class biothings.web.options.openapi.OpenAPILicenseContext(parent)[source]

Bases: biothings.web.options.openapi._ChildContext

ATTRIBUTE_FIELDS = {'name': 'name', 'url': 'url'}
EXTENSION = True
name(v)

Set name field

subclasses: MutableMapping[str, Type[biothings.web.options.openapi._ChildContext]] = {'OpenAPIContactContext': <class 'biothings.web.options.openapi.OpenAPIContactContext'>, 'OpenAPIContext': <class 'biothings.web.options.openapi.OpenAPIContext'>, 'OpenAPIExternalDocsContext': <class 'biothings.web.options.openapi.OpenAPIExternalDocsContext'>, 'OpenAPIInfoContext': <class 'biothings.web.options.openapi.OpenAPIInfoContext'>, 'OpenAPILicenseContext': <class 'biothings.web.options.openapi.OpenAPILicenseContext'>, 'OpenAPIOperation': <class 'biothings.web.options.openapi.OpenAPIOperation'>, 'OpenAPIParameterContext': <class 'biothings.web.options.openapi.OpenAPIParameterContext'>, 'OpenAPIPathItemContext': <class 'biothings.web.options.openapi.OpenAPIPathItemContext'>, '_BaseContext': <class 'biothings.web.options.openapi._BaseContext'>, '_ChildContext': <class 'biothings.web.options.openapi._ChildContext'>, '_HasDescription': <class 'biothings.web.options.openapi._HasDescription'>, '_HasExternalDocs': <class 'biothings.web.options.openapi._HasExternalDocs'>, '_HasParameters': <class 'biothings.web.options.openapi._HasParameters'>, '_HasSummary': <class 'biothings.web.options.openapi._HasSummary'>, '_HasTags': <class 'biothings.web.options.openapi._HasTags'>}
url(v)

Set url field

class biothings.web.options.openapi.OpenAPIOperation(parent)[source]

Bases: biothings.web.options.openapi._ChildContext, biothings.web.options.openapi._HasSummary, biothings.web.options.openapi._HasExternalDocs, biothings.web.options.openapi._HasTags, biothings.web.options.openapi._HasDescription, biothings.web.options.openapi._HasParameters

ATTRIBUTE_FIELDS = {'operation_id': 'operationId'}
EXTENSION = True
operation_id(v)

Set operationId field

subclasses: MutableMapping[str, Type[biothings.web.options.openapi._ChildContext]] = {'OpenAPIContactContext': <class 'biothings.web.options.openapi.OpenAPIContactContext'>, 'OpenAPIContext': <class 'biothings.web.options.openapi.OpenAPIContext'>, 'OpenAPIExternalDocsContext': <class 'biothings.web.options.openapi.OpenAPIExternalDocsContext'>, 'OpenAPIInfoContext': <class 'biothings.web.options.openapi.OpenAPIInfoContext'>, 'OpenAPILicenseContext': <class 'biothings.web.options.openapi.OpenAPILicenseContext'>, 'OpenAPIOperation': <class 'biothings.web.options.openapi.OpenAPIOperation'>, 'OpenAPIParameterContext': <class 'biothings.web.options.openapi.OpenAPIParameterContext'>, 'OpenAPIPathItemContext': <class 'biothings.web.options.openapi.OpenAPIPathItemContext'>, '_BaseContext': <class 'biothings.web.options.openapi._BaseContext'>, '_ChildContext': <class 'biothings.web.options.openapi._ChildContext'>, '_HasDescription': <class 'biothings.web.options.openapi._HasDescription'>, '_HasExternalDocs': <class 'biothings.web.options.openapi._HasExternalDocs'>, '_HasParameters': <class 'biothings.web.options.openapi._HasParameters'>, '_HasSummary': <class 'biothings.web.options.openapi._HasSummary'>, '_HasTags': <class 'biothings.web.options.openapi._HasTags'>}
class biothings.web.options.openapi.OpenAPIParameterContext(parent, name: str, in_: str, required: bool)[source]

Bases: biothings.web.options.openapi._ChildContext, biothings.web.options.openapi._HasDescription

ATTRIBUTE_FIELDS = {'allow_empty': 'allowEmptyValue', 'allow_reserved': 'allowReserved', 'deprecated': 'deprecated', 'explode': 'explode', 'schema': 'schema', 'style': 'style'}
EXTENSION = True
allow_empty(v)

Set allowEmptyValue field

allow_reserved(v)

Set allowReserved field

deprecated(v)

Set deprecated field

explode(v)

Set explode field

schema(v)

Set schema field

style(v)

Set style field

subclasses: MutableMapping[str, Type[biothings.web.options.openapi._ChildContext]] = {'OpenAPIContactContext': <class 'biothings.web.options.openapi.OpenAPIContactContext'>, 'OpenAPIContext': <class 'biothings.web.options.openapi.OpenAPIContext'>, 'OpenAPIExternalDocsContext': <class 'biothings.web.options.openapi.OpenAPIExternalDocsContext'>, 'OpenAPIInfoContext': <class 'biothings.web.options.openapi.OpenAPIInfoContext'>, 'OpenAPILicenseContext': <class 'biothings.web.options.openapi.OpenAPILicenseContext'>, 'OpenAPIOperation': <class 'biothings.web.options.openapi.OpenAPIOperation'>, 'OpenAPIParameterContext': <class 'biothings.web.options.openapi.OpenAPIParameterContext'>, 'OpenAPIPathItemContext': <class 'biothings.web.options.openapi.OpenAPIPathItemContext'>, '_BaseContext': <class 'biothings.web.options.openapi._BaseContext'>, '_ChildContext': <class 'biothings.web.options.openapi._ChildContext'>, '_HasDescription': <class 'biothings.web.options.openapi._HasDescription'>, '_HasExternalDocs': <class 'biothings.web.options.openapi._HasExternalDocs'>, '_HasParameters': <class 'biothings.web.options.openapi._HasParameters'>, '_HasSummary': <class 'biothings.web.options.openapi._HasSummary'>, '_HasTags': <class 'biothings.web.options.openapi._HasTags'>}
type(typ: str, **kwargs)[source]
class biothings.web.options.openapi.OpenAPIPathItemContext(parent)[source]

Bases: biothings.web.options.openapi._ChildContext, biothings.web.options.openapi._HasSummary, biothings.web.options.openapi._HasDescription, biothings.web.options.openapi._HasParameters

CHILD_CONTEXTS = {'delete': ('OpenAPIOperation', 'delete'), 'get': ('OpenAPIOperation', 'get'), 'head': ('OpenAPIOperation', 'head'), 'options': ('OpenAPIOperation', 'options'), 'patch': ('OpenAPIOperation', 'patch'), 'post': ('OpenAPIOperation', 'post'), 'put': ('OpenAPIOperation', 'put'), 'trace': ('OpenAPIOperation', 'trace')}
EXTENSION = True
delete(**kwargs)

Set delete Create OpenAPIOperation and set delete

get(**kwargs)

Set get Create OpenAPIOperation and set get

head(**kwargs)

Set head Create OpenAPIOperation and set head

http_method = 'trace'
options(**kwargs)

Set options Create OpenAPIOperation and set options

patch(**kwargs)

Set patch Create OpenAPIOperation and set patch

post(**kwargs)

Set post Create OpenAPIOperation and set post

put(**kwargs)

Set put Create OpenAPIOperation and set put

subclasses: MutableMapping[str, Type[biothings.web.options.openapi._ChildContext]] = {'OpenAPIContactContext': <class 'biothings.web.options.openapi.OpenAPIContactContext'>, 'OpenAPIContext': <class 'biothings.web.options.openapi.OpenAPIContext'>, 'OpenAPIExternalDocsContext': <class 'biothings.web.options.openapi.OpenAPIExternalDocsContext'>, 'OpenAPIInfoContext': <class 'biothings.web.options.openapi.OpenAPIInfoContext'>, 'OpenAPILicenseContext': <class 'biothings.web.options.openapi.OpenAPILicenseContext'>, 'OpenAPIOperation': <class 'biothings.web.options.openapi.OpenAPIOperation'>, 'OpenAPIParameterContext': <class 'biothings.web.options.openapi.OpenAPIParameterContext'>, 'OpenAPIPathItemContext': <class 'biothings.web.options.openapi.OpenAPIPathItemContext'>, '_BaseContext': <class 'biothings.web.options.openapi._BaseContext'>, '_ChildContext': <class 'biothings.web.options.openapi._ChildContext'>, '_HasDescription': <class 'biothings.web.options.openapi._HasDescription'>, '_HasExternalDocs': <class 'biothings.web.options.openapi._HasExternalDocs'>, '_HasParameters': <class 'biothings.web.options.openapi._HasParameters'>, '_HasSummary': <class 'biothings.web.options.openapi._HasSummary'>, '_HasTags': <class 'biothings.web.options.openapi._HasTags'>}
trace(**kwargs)

Set trace Create OpenAPIOperation and set trace