Base handler¶
- class luna_faces.app.handlers.base_handler.AttributesBaseRequestHandler(request)[source]¶
Base handler for handlers which work with attributes.
- static convertInputDescriptors(inputDescriptors)[source]¶
Convert list of descriptors to Descriptor instances. Input descriptors have one of the following formats: 1. {“descriptor”: b”descr”, “version”: 51} - from msgpack 2. {“descriptor”: “base64 descr”, “version”: 51} - from json 3. b”SDK descr” - from msgpack 4. “base64 SDK descr” - from json
- Parameters:
inputDescriptors (
list
) – base64 descriptors from input json- Return type:
List
[Descriptor
]- Returns:
descriptors list
- static createTemporaryAttributes(inputAttribute, attributeId=None)[source]¶
Create temporary attribute :type inputAttribute:
dict
:param inputAttribute: input json with converted descriptors :type attributeId:Optional
[str
,None
] :param attributeId: attribute id- Return type:
TemporaryAttributes
- Returns:
new temporary attribute
- getEncodedDescriptor(descriptorVersion, descriptor)[source]¶
Encode given descriptor.
If requested format requires, encode bytes with base64. Otherwise, return bytes.
- Return type:
Union
[bytes
,str
]- Returns:
Encoded descriptor.
- async getInputAttribute(attributeId)[source]¶
Get input attributes from either json or Multipart.
- Return type:
TemporaryAttributes
- Returns:
temporary attribute
- async getInputAttributeFromJson()[source]¶
Get input attribute from request with json
- Return type:
dict
- Returns:
attribute as dict
- async getInputAttributeFromMultipart()[source]¶
Get input attribute from request with multipart
- Return type:
dict
- Returns:
attribute as dict
- makeOutputAttribute(attribute, targets, descriptorVersion=None)[source]¶
Make output attribute :type attribute:
TemporaryAttributes
:param attribute: temporary attribute :type targets:List
[str
] :param targets: list of targets :type descriptorVersion:Optional
[int
,None
] :param descriptorVersion: descriptor version- Return type:
dict
- Returns:
dict with all fields requested fields
- static validateAttribute(attribute)[source]¶
Validate compatibility attribute data :type attribute:
TemporaryAttributes
:param attribute: attribute- Raises:
VLException(Error.AttributeDoesNotContainAnyData) – if attribute does not contain basic attributes and descriptors
VLException(Error.AttributeContainsSamplesWithoutData) – if attribute contain samples without data
- static validateAttributeDescriptors(attribute)[source]¶
Validate length and version of input descriptors. Also function checks a duplication of descriptor versions.
- Parameters:
attribute (
TemporaryAttributes
) – input attribute- Raises:
VLException(Error.InvalidDescriptorLength) – if descriptor has incorrect length
VLException(Error.UnknownDescriptorVersion) – if descriptor has unknown version
VLException(Error.AttributeWithDescriptorsIdenticalVersion) – if there are two ore more descriptors with same versions
- class luna_faces.app.handlers.base_handler.BaseRequestHandler(request)[source]¶
Base handler for other handlers.
- property app: FacesApp¶
Get running app :rtype:
FacesApp
:returns: app
- checkLicense()[source]¶
Check that the license is available and the limit of face with attributes is not exceeded.
- Raises:
VLException(Error.LicenseProblem, 403) – if something went wrong with the license
- property config: SettingsFaces¶
Get app config :rtype:
SettingsFaces
:returns: app config
- success(statusCode=200, body=None, outputJson=None, contentType=None, extraHeaders=None)[source]¶
Finish success request. Generate correct reply with request id header, correct Content Type header Support “application/msgpack” “Accept” header.
- Parameters:
contentType (
Optional
[str
,None
]) – body content typestatusCode (
int
) – response status code, range(200, 300), default 200body (
Union
[bytes
,str
,None
]) – pure bodyoutputJson (
Union
[dict
,list
,None
]) – json as objectextraHeaders (
Optional
[dict
,None
]) – extra headers that will be added to the response (default headers in case of overlapping will be replaced);
- Return type:
HTTPResponse
- Returns:
aiohttp.web.Response object
- Raises:
ValueError – if response has body but its content-type was not determined in “Content-Type” header
- class luna_faces.app.handlers.base_handler.FaceBaseRequestHandler(request)[source]¶
Base handler for handlers which work with faces and face attributes.
- async checkListIds(listIds, accountId)[source]¶
Check list ids existence.
- Parameters:
listIds (
Set
[str
]) – list ids to checkaccountId (
str
) – account id
- Raises:
VLException(Error.ListsNotFound.format(nonExistListId), 400) if some list was not found –
- Return type:
None
- static getAttributeByData(attribute)[source]¶
Generate temporary attribute container by attribute data.
- Parameters:
attribute (
dict
) – attribute data- Return type:
TemporaryAttributes
- Returns:
temporary attribute container
- async getAttributeById(attributeId, accountId)[source]¶
Get temporary attribute container by attribute id.
- Parameters:
attributeId (
str
) – attribute idaccountId (
str
) – account id
- Return type:
TemporaryAttributes
- Returns:
temporary attribute container
- Raises:
VLException(Error.AttributesNotFound, 400) – if attribute was not found
- class luna_faces.app.handlers.base_handler.NewFace(data: dict, listIds: Optional[Set[str]] = None, attribute: Optional[TemporaryAttributes] = None)[source]¶
Data for new face
- attribute: Optional[TemporaryAttributes]¶
face attribute
- data: dict¶
dict with face data (user_data)
- listIds: Optional[Set[str]]¶
lists to link