本文整理汇总了Python中pynamodb.attributes.UnicodeAttribute方法的典型用法代码示例。如果您正苦于以下问题:Python attributes.UnicodeAttribute方法的具体用法?Python attributes.UnicodeAttribute怎么用?Python attributes.UnicodeAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pynamodb.attributes
的用法示例。
在下文中一共展示了attributes.UnicodeAttribute方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_binary_attribute_update
# 需要导入模块: from pynamodb import attributes [as 别名]
# 或者: from pynamodb.attributes import UnicodeAttribute [as 别名]
def test_binary_attribute_update(ddb_url):
class DataModel(Model):
class Meta:
table_name = 'binary_attr_update'
host = ddb_url
pkey = UnicodeAttribute(hash_key=True)
data = BinaryAttribute()
DataModel.create_table(read_capacity_units=1, write_capacity_units=1, wait=True)
data = b'\x00hey\xfb'
pkey = 'pkey'
DataModel(pkey, data=data).save()
m = DataModel.get(pkey)
assert m.data == data
new_data = b'\xff'
m.update(actions=[DataModel.data.set(new_data)])
assert new_data == m.data
示例2: test_binary_set_attribute_update
# 需要导入模块: from pynamodb import attributes [as 别名]
# 或者: from pynamodb.attributes import UnicodeAttribute [as 别名]
def test_binary_set_attribute_update(ddb_url):
class DataModel(Model):
class Meta:
table_name = 'binary_set_attr_update'
host = ddb_url
pkey = UnicodeAttribute(hash_key=True)
data = BinarySetAttribute()
DataModel.create_table(read_capacity_units=1, write_capacity_units=1, wait=True)
data = {b'\x00hey\xfb', b'\x00beautiful\xfb'}
pkey = 'pkey'
DataModel(pkey, data=data).save()
m = DataModel.get(pkey)
assert m.data == data
new_data = {b'\xff'}
m.update(actions=[DataModel.data.set(new_data)])
assert new_data == m.data
示例3: test_list_attribute
# 需要导入模块: from pynamodb import attributes [as 别名]
# 或者: from pynamodb.attributes import UnicodeAttribute [as 别名]
def test_list_attribute(assert_mypy_output):
assert_mypy_output("""
from pynamodb.attributes import ListAttribute, MapAttribute, UnicodeAttribute
from pynamodb.models import Model
class MyMap(MapAttribute):
my_sub_attr = UnicodeAttribute()
class MyModel(Model):
my_list = ListAttribute(of=MyMap)
my_untyped_list = ListAttribute() # E: Need type annotation for 'my_untyped_list' [var-annotated]
reveal_type(MyModel.my_list) # N: Revealed type is 'pynamodb.attributes.ListAttribute[__main__.MyMap]'
reveal_type(MyModel().my_list) # N: Revealed type is 'builtins.list*[__main__.MyMap*]'
reveal_type(MyModel().my_list[0].my_sub_attr) # N: Revealed type is 'builtins.str*'
# Untyped lists are not well supported yet
reveal_type(MyModel().my_untyped_list[0].my_sub_attr) # N: Revealed type is 'Any'
""")
示例4: test_paths
# 需要导入模块: from pynamodb import attributes [as 别名]
# 或者: from pynamodb.attributes import UnicodeAttribute [as 别名]
def test_paths(assert_mypy_output):
assert_mypy_output("""
from pynamodb.attributes import ListAttribute, MapAttribute, UnicodeAttribute
from pynamodb.models import Model
class MyMap(MapAttribute):
my_sub_attr = UnicodeAttribute()
class MyModel(Model):
my_list = ListAttribute(of=MyMap)
my_map = MyMap()
reveal_type(MyModel.my_list[0]) # N: Revealed type is 'pynamodb.expressions.operand.Path'
reveal_type(MyModel.my_list[0] == MyModel()) # N: Revealed type is 'pynamodb.expressions.condition.Comparison'
# the following string indexing is not type checked - not by mypy nor in runtime
reveal_type(MyModel.my_list[0]['my_sub_attr'] == 'foobar') # N: Revealed type is 'pynamodb.expressions.condition.Comparison'
""")
示例5: test_exception
# 需要导入模块: from pynamodb import attributes [as 别名]
# 或者: from pynamodb.attributes import UnicodeAttribute [as 别名]
def test_exception():
class SampleModel(Model):
class Meta:
region = 'us-west-2'
table_name = 'mytable'
sample_attribute = UnicodeAttribute(hash_key=True)
try:
SampleModel.describe_table()
except Exception:
pass
subsegments = xray_recorder.current_segment().subsegments
assert len(subsegments) == 1
subsegment = subsegments[0]
assert subsegment.name == 'dynamodb'
assert len(subsegment.subsegments) == 0
assert subsegment.error
aws_meta = subsegment.aws
assert aws_meta['region'] == 'us-west-2'
assert aws_meta['operation'] == 'DescribeTable'
assert aws_meta['table_name'] == 'mytable'
示例6: test_create_projection_expression_with_attributes
# 需要导入模块: from pynamodb import attributes [as 别名]
# 或者: from pynamodb.attributes import UnicodeAttribute [as 别名]
def test_create_projection_expression_with_attributes(self):
attributes_to_get = [
UnicodeAttribute(attr_name='ProductReviews.FiveStar'),
UnicodeAttribute(attr_name='ProductReviews.ThreeStar'),
UnicodeAttribute(attr_name='ProductReviews.OneStar')
]
placeholders = {}
projection_expression = create_projection_expression(attributes_to_get, placeholders)
assert projection_expression == "#0, #1, #2"
assert placeholders == {
'ProductReviews.FiveStar': '#0',
'ProductReviews.ThreeStar': '#1',
'ProductReviews.OneStar': '#2',
}
示例7: setUp
# 需要导入模块: from pynamodb import attributes [as 别名]
# 或者: from pynamodb.attributes import UnicodeAttribute [as 别名]
def setUp(self):
self.attribute = UnicodeAttribute(attr_name='foo')
示例8: test_map_attribute
# 需要导入模块: from pynamodb import attributes [as 别名]
# 或者: from pynamodb.attributes import UnicodeAttribute [as 别名]
def test_map_attribute(assert_mypy_output):
assert_mypy_output("""
from pynamodb.attributes import MapAttribute, UnicodeAttribute
from pynamodb.models import Model
class MySubMap(MapAttribute):
s = UnicodeAttribute()
class MyMap(MapAttribute):
m2 = MySubMap()
class MyModel(Model):
m1 = MyMap()
reveal_type(MyModel.m1) # N: Revealed type is '__main__.MyMap'
reveal_type(MyModel().m1) # N: Revealed type is '__main__.MyMap'
reveal_type(MyModel.m1.m2) # N: Revealed type is '__main__.MySubMap'
reveal_type(MyModel().m1.m2) # N: Revealed type is '__main__.MySubMap'
reveal_type(MyModel.m1.m2.s) # N: Revealed type is 'builtins.str*'
reveal_type(MyModel().m1.m2.s) # N: Revealed type is 'builtins.str*'
reveal_type(MyMap.m2) # N: Revealed type is '__main__.MySubMap'
reveal_type(MyMap().m2) # N: Revealed type is '__main__.MySubMap'
reveal_type(MySubMap.s) # N: Revealed type is 'pynamodb.attributes.UnicodeAttribute'
reveal_type(MySubMap().s) # N: Revealed type is 'builtins.str*'
""")
示例9: test_getkeyname_should_workonstrings
# 需要导入模块: from pynamodb import attributes [as 别名]
# 或者: from pynamodb.attributes import UnicodeAttribute [as 别名]
def test_getkeyname_should_workonstrings():
class MyModel(Model):
class Meta:
table_name = 'some-table'
notmyid = UnicodeAttribute(null=True)
myid = UnicodeAttribute(hash_key=True)
assert get_key_name(MyModel) == 'myid'
示例10: test_getkeyname_should_workonnumbers
# 需要导入模块: from pynamodb import attributes [as 别名]
# 或者: from pynamodb.attributes import UnicodeAttribute [as 别名]
def test_getkeyname_should_workonnumbers():
class MyModel(Model):
class Meta:
table_name = 'some-table'
notmyid = UnicodeAttribute(null=True)
myid = NumberAttribute(hash_key=True)
assert get_key_name(MyModel) == 'myid'
示例11: ifind_first_object
# 需要导入模块: from pynamodb import attributes [as 别名]
# 或者: from pynamodb.attributes import UnicodeAttribute [as 别名]
def ifind_first_object(self, ObjectClass, **kwargs):
""" Retrieve the first object of type ``ObjectClass``,
matching the specified filters in ``**kwargs`` -- case insensitive.
| If USER_IFIND_MODE is 'nocase_collation' this method maps to find_first_object().
| If USER_IFIND_MODE is 'ifind' this method performs a case insensitive find.
"""
from pynamodb.attributes import UnicodeAttribute
if self.user_manager.USER_IFIND_MODE == 'nocase_collation':
return self.find_first_object(ObjectClass, **kwargs)
# The below is horrendously slow on a large user database, but DynamoDB
# has no support for case insensitive search, so we have to scan.
# We try and be a little smart and use any non-unicode filters in the scan, thought.
tfilters = {k: v.lower() for k, v in kwargs.items() if type(getattr(ObjectClass, k)) == UnicodeAttribute}
ntfilter = None
for k in [k for k in kwargs if k not in tfilters]:
cond = getattr(ObjectClass, k) == kwargs[k]
ntfilter = cond if ntfilter is None else ntfilter & cond
for o in ObjectClass.scan(ntfilter):
for k in tfilters:
if getattr(o, k, None).lower() != kwargs[k]:
break
else:
# all match
return o
return None