我们从Python开源项目中,提取了以下20个代码示例,用于说明如何使用google.appengine.ext.db.Text()。
def testTextSanitization(self): # Remove non-ascii from decimal import Decimal volley = [ ('‘Hello’', 'Hello'), (int(10), '10'), (False, 'False'), (long(20), '20'), (u'‘Hello’', 'Hello'), (u'‘Hello\nHi’', 'Hello\nHi'), (u'Kl\xfcft skr\xe4ms inf\xf6r p\xe5 f\xe9d\xe9ral \xe9lectoral gro\xdfe', 'Kluft skrams infor pa federal electoral groe'), (db.Text(u'‘Hello’'), 'Hello'), (db.Text(u'naïve café'), 'naive cafe') ] for v in volley: target = v[1] actual = tools.normalize_to_ascii(v[0]) self.assertEqual(actual, target)
def testTextSanitization(self): # Remove non-ascii from decimal import Decimal volley = [ ('‘Hello’', 'Hello'), (int(10), '10'), (False, 'False'), (None, None), (long(20), '20'), (u'‘Hello’', 'Hello'), (u'‘Hello\nHi’', 'Hello\nHi'), (u'Kl\xfcft skr\xe4ms inf\xf6r p\xe5 f\xe9d\xe9ral \xe9lectoral gro\xdfe', 'Kluft skrams infor pa federal electoral groe'), (db.Text(u'‘Hello’'), 'Hello'), (db.Text(u'naïve café'), 'naive cafe') ] for v in volley: target = v[1] actual = tools.normalize_to_ascii(v[0]) self.assertEqual(actual, target)
def _GetModelTypeForListPropertyType(property_type): """Converts (supported) db.ListProperty type to db.Model type.""" from google.appengine.ext import db _LISTPROPERTY_TYPE_TO_SCHEMA_ENTRY = { basestring: db.StringProperty, str: db.StringProperty, unicode: db.StringProperty, bool: db.BooleanProperty, int: db.IntegerProperty, float: db.FloatProperty, db.Text: db.TextProperty, } return _LISTPROPERTY_TYPE_TO_SCHEMA_ENTRY.get(property_type, None)
def _GetModelTypeForEntityType(python_type): """Converts python built in type to db.Model type.""" from google.appengine.ext import db _PYTHON_TYPE_TO_MODEL_TYPE = { basestring: db.StringProperty, str: db.StringProperty, unicode: db.StringProperty, int: db.IntegerProperty, bool: db.BooleanProperty, float: db.FloatProperty, db.Text: db.TextProperty, } return _PYTHON_TYPE_TO_MODEL_TYPE.get(python_type, None)
def __init__(self): bulkloader.Loader.__init__(self, 'Category', [('name', unicode), ('slug', unicode), ('description', db.Text), ('is_active', bool) ])
def get_value_for_datastore(self, model_instance): fake_model = getattr(model_instance, self.name) if not fake_model: return None if not self.indexed: return db.Text(fake_model.get_value_for_datastore()) return fake_model.get_value_for_datastore()
def __init__(self, model, *args, **kwargs): self.model = model if not kwargs.get('indexed', True): self.fake_item_type = db.Text super(FakeModelListProperty, self).__init__( self.__class__.fake_item_type, *args, **kwargs)
def get_value_for_datastore(self, model_instance): fake_models = getattr(model_instance, self.name) if not self.indexed: return [db.Text(fake_model.get_value_for_datastore()) for fake_model in fake_models] return [fake_model.get_value_for_datastore() for fake_model in fake_models]
def get_merkle_chains(self, root_key_name_yesterday): k=ndb.Key('DocRoot', root_key_name_yesterday) doc_root=k.get() if (doc_root.doc_root_hash!=''): raise Exception('ERROR! doc_root_hash already used!') my_list=DocLine.get_doclines_from_root(root_key_name_yesterday) if len(my_list)==0: raise Exception('WARNING. No documents to proof.') my_list2=map(lambda x:x.content_hash,my_list) tree = MerkleTree(my_list2, True) tree.build() doc_root_hash=binascii.hexlify(tree.root.val) for i in range(len(my_list2)): merkle_chain=tree.get_chain(i) merkle_chain2=map(lambda x: (binascii.hexlify(x[0]),x[1]), merkle_chain) my_list[i].merkle_chain=db.Text(str(merkle_chain2), encoding="latin-1") my_list[i].doc_root=doc_root_hash my_list[i].put() doc_root=k.get() doc_root.doc_root_hash=doc_root_hash doc_root.date_broadcast=test.utcnow() doc_root.nodes=db.Text(str(map(lambda x: binascii.hexlify(x.val), tree.leaves)), encoding='latin-1') doc_root.put() return doc_root_hash
def new(cls, parent, content_hash, date_received): d = cls(parent=parent, content_hash=content_hash, date_received=date_received, doc_root='', merkle_chain=db.Text('', encoding="utf-8")) d.put() return d
def new(cls, key_name): # http://stackoverflow.com/questions/24332648/google-app-engine-no-key-name-attribute d=cls(id=key_name, doc_root_hash='', date_broadcast=None, nodes=db.Text('', encoding='utf-8'), txid='') d.put() return d
def new(cls, message): d = cls(message=db.Text(message) if isinstance(message,unicode) else db.Text(message, encoding='utf-8'), date_received=test.utcnow()) d.put() return d