Handler events handler¶
Receive events on handler
-
class
luna_handlers.app.handlers.handler_events_handler.
HandlerEventsHandler
(request)[source]¶ Receiver of events.
Resource: “/{api_version}/handlers/{handlerId}/events”
-
getDataFromMultipart
(imageType=<ImageType.rawImage: 0>)[source]¶ Get data from multipart request :param imageType: image type
Returns: list of Images or list warps and optionally dict with policies (for multipart request with policies) Return type: Tuple
[Union
[List
[SDKDetectableImage
],List
[FaceWarp
]],Optional
[dict
]]
-
getEventTime
()[source]¶ Get event time.
If user specified header “Luna-Event-Time” in correct format - it will be used for event time. Otherwise - current time.
Returns: user defined time otherwise current server or utc time. Return type: str
-
getHandlerWrapper
(handlerId, accountId=None, noCache=False)[source]¶ Wrapper around DBContext.getHandler.
Returns data from cache if present. Data is copied to prevent modification of cached data. If the data is from cache returns data version as well.
Parameters: - handlerId – handler id
- accountId – handler account id
- noCache – A bool, whether to force database querying
Returns: deserialized dict with handler, version of cached handler or None
Return type: (handlerJson, version)
Raises: VLException(Error.HandlerNotFound.format(handlerId), 404, isCriticalError=False) – if handler not found
Return type: Tuple
[Dict
[~KT, ~VT],Optional
[datetime
]]
-
getInputEstimationData
(request, validationModel, imageType=<ImageType.rawImage: 0>, autoOrient=True, allowRawDescriptors=True)[source]¶ Get images from request body to detect faces and, optionally, policies for a dynamic handler. :param request: request :param imageType: imageType :param validationModel: validation model :param autoOrient: whether to use orientation from exif or not :param allowRawDescriptors: whether raw descriptor mimetypes allowed or not
Returns: list of Images or list warps and, optionally, policies for a dynamic handler. Return type: Tuple
[Union
[List
[SDKDetectableImage
],List
[FaceWarp
]],Optional
[dict
]]
-
loadHandlerAndInputImages
(handlerId)[source]¶ Prepare handler and input images for processing.
If handler is static, policies are loaded from the database. If handler is dynamic, policies are required to be in the input request (multipart).
Parameters: handlerId – handler id Returns: tuple with handler object, input images, version of cached handler or None Return type: Tuple
[Any
,Union
[List
[SDKDetectableImage
],List
[FaceWarp
]],datetime
]
-
loadLocation
()[source]¶ Load location data from the query parameters.
Returns: location Return type: Location
-
post
(handlerId)[source]¶ Receive events handler. See spec receive_events.
Parameters: handlerId – handler id Returns: Response with events and detections Raises: VLException(Error.BadMultipartInput, 400, isCriticalError=False) – if failed to read multipart Return type: HTTPResponse
-
-
luna_handlers.app.handlers.handler_events_handler.
externalIdValidator
(value: str, minLength: Optional[int] = None, *, maxLength: Optional[int] = 36) → str¶ Check that the values length is between minLength and maxLength.
Parameters: - value – String to validate
- minLength – An int, minimum length
- maxLength – An int, maximum length
Raises: ValueError if length is incorrect
Returns: Given string
-
luna_handlers.app.handlers.handler_events_handler.
locationGetter
(value: str, minLength: Optional[int] = None, *, maxLength: Optional[int] = 36) → str¶ Check that the values length is between minLength and maxLength.
Parameters: - value – String to validate
- minLength – An int, minimum length
- maxLength – An int, maximum length
Raises: ValueError if length is incorrect
Returns: Given string
-
luna_handlers.app.handlers.handler_events_handler.
sourceValidator
(value: str, minLength: Optional[int] = None, *, maxLength: Optional[int] = 128) → str¶ Check that the values length is between minLength and maxLength.
Parameters: - value – String to validate
- minLength – An int, minimum length
- maxLength – An int, maximum length
Raises: ValueError if length is incorrect
Returns: Given string
Gets list from comma-separated strings, ensures validity by using itemValidator func.
Parameters: - value – String to extract list from.
- minItemsCount – An int, minimum number of items
- itemValidator – A function that validates every item
Raises: - ValueError if length is incorrect
- ValueError if any of items lenghts is incorrect
Returns: List of strings
-
luna_handlers.app.handlers.handler_events_handler.
userDataValidator
(value: str, minLength: Optional[int] = None, *, maxLength: Optional[int] = 128) → str¶ Check that the values length is between minLength and maxLength.
Parameters: - value – String to validate
- minLength – An int, minimum length
- maxLength – An int, maximum length
Raises: ValueError if length is incorrect
Returns: Given string