1
0
Fork 0
mirror of https://github.com/morpheus65535/bazarr synced 2024-12-23 16:23:41 +00:00
bazarr/libs/knowit/properties/yesno.py

26 lines
686 B
Python
Raw Normal View History

2020-03-18 19:33:54 +00:00
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from six import text_type
from ..property import Property
class YesNo(Property):
"""Yes or No handler."""
mapping = ('yes', 'true', '1')
def __init__(self, name, yes=True, no=False, hide_value=None, **kwargs):
"""Init method."""
super(YesNo, self).__init__(name, **kwargs)
self.yes = yes
self.no = no
self.hide_value = hide_value
def handle(self, value, context):
"""Handle boolean values."""
v = text_type(value).lower()
result = self.yes if v in self.mapping else self.no
return result if result != self.hide_value else None