我们从Python开源项目中,提取了以下1个代码示例,用于说明如何使用google.appengine.ext.db.NotSavedError()。
def encodeKey(self, key, encoding): """ Returns an AMF encoded representation of a L{db.Key} instance. @param key: The L{db.Key} to be encoded. @type key: L{db.Key} @param encoding: The AMF version. """ if hasattr(key, 'key'): # we have a db.Model instance try: key = key.key() except db.NotSavedError: key = None if not key: # the AMF representation of None if encoding == pyamf.AMF3: return '\x01' return '\x05' k = str(key) if encoding == pyamf.AMF3: return '\x06%s%s' % ( amf3.encode_int(len(k) << 1 | amf3.REFERENCE_BIT), k) return '\x02%s%s' % (struct.pack('>H', len(k)), k)