本文整理匯總了Python中schematics.types.BooleanType方法的典型用法代碼示例。如果您正苦於以下問題:Python types.BooleanType方法的具體用法?Python types.BooleanType怎麽用?Python types.BooleanType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類schematics.types
的用法示例。
在下文中一共展示了types.BooleanType方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _value_to_dynamodb
# 需要導入模塊: from schematics import types [as 別名]
# 或者: from schematics.types import BooleanType [as 別名]
def _value_to_dynamodb(cls, key, value):
"""
Convert python/schematics values to DynamoDB values.
:param key: field name (string)
:param value: field value
:return: dynamodb-friendly value
"""
if isinstance(getattr(cls, key), (fields.DateTimeType,
fields.DateType)):
if not value:
return 0
value = getattr(cls, key).to_native(value)
return decimal.Decimal(int(calendar.timegm(value.timetuple())))
if isinstance(getattr(cls, key), fields.UUIDType) and value:
return getattr(cls, key).to_primitive(value)
if isinstance(getattr(cls, key), fields.BooleanType):
return decimal.Decimal('1') if value else decimal.Decimal('0')
if value == '': # Empty AttributeValue is an error in DynamoDB
return None
return value
示例2: _dynamodb_to_model
# 需要導入模塊: from schematics import types [as 別名]
# 或者: from schematics.types import BooleanType [as 別名]
def _dynamodb_to_model(self, row):
dict_row = dict(row)
for field_name, dynamodb_value in row.items():
if field_name in self._fields:
if isinstance(self._fields[field_name],
(fields.DateTimeType,
fields.DateType)):
if dynamodb_value:
dict_row[field_name] = datetime.datetime.utcfromtimestamp(
float(dynamodb_value)
) # TODO: test for this
else:
dict_row[field_name] = None
if isinstance(self._fields[field_name],
fields.BooleanType):
# tests/test_gis_report_provider.py covers this
dict_row[field_name] = bool(
dynamodb_value
) # DynamoDB loads boolean as e.g. Decimal('1')
return dict_row