Untitled

From Gray Bushbaby, 2 Years ago, written in Plain Text, viewed 179 times. This paste will die in 1 Second.
URL https://paste.gajim.org/view/c17be988 Embed
Download Paste or View Raw
  1. from typing import Union
  2.  
  3.  
  4. def from_xs_boolean(value: Union[str, bool]) -> bool:
  5.     # Convert a xs:boolean ('true', 'false', '1', '0', '')
  6.     # to a python boolean (True, False)
  7.     if value in (True, False):
  8.         return value
  9.  
  10.     if value in ('1', 'true'):
  11.         return True
  12.  
  13.     # '0', 'false' or empty
  14.     if value in ('0', 'false', ''):
  15.         return False
  16.  
  17.     raise ValueError(
  18.         'Cant convert %s to python boolean' % value)
  19.  

Reply to "Untitled"

Here you can reply to the paste above