Package pyamf :: Package adapters :: Module _google_appengine_ext_db
[hide private]
[frames] | no frames]

Source Code for Module pyamf.adapters._google_appengine_ext_db

 1  # Copyright (c) 2007-2008 The PyAMF Project. 
 2  # See LICENSE for details. 
 3   
 4  """ 
 5  Google App Engine adapter module. 
 6   
 7  Sets up basic type mapping and class mappings for using the Datastore API 
 8  in Google App Engine. 
 9   
10  @see: U{Datastore API on Google App Engine (external) 
11  <http://code.google.com/appengine/docs/datastore>} 
12   
13  @author: U{Nick Joyce<mailto:nick@boxdesign.co.uk>} 
14  @since: 0.3.1 
15  """ 
16   
17  from google.appengine.ext import db 
18   
19  import pyamf 
20  from pyamf import amf0, amf3 
21   
22 -def writeObjectAMF0(self, obj, *args, **kwargs):
23 alias = self.context.getClassAlias(obj.__class__) 24 remove = False 25 26 if alias is None: 27 remove = True 28 self.context.class_aliases[obj.__class__] = pyamf.ClassAlias(obj.__class__, None) 29 30 self.writeObject(obj, *args, **kwargs) 31 32 if remove: 33 self.context.class_aliases[obj.__class__] = None
34
35 -def writeObjectAMF3(self, obj, *args, **kwargs):
36 try: 37 self.context.getClassDefinitionReference(obj) 38 except pyamf.ReferenceError: 39 alias = self.context.getClassAlias(obj.__class__) 40 class_def = None 41 remove = False 42 43 if alias is None: 44 remove = True 45 alias = pyamf.ClassAlias(obj.__class__, None) 46 self.context.class_aliases[obj.__class__] = alias 47 48 self.writeObject(obj, *args, **kwargs) 49 50 if remove: 51 self.context.class_aliases[obj.__class__] = None
52
53 -def get_attrs_for_model(obj):
54 """ 55 Returns a list of properties on an C{db.Model} instance. 56 """ 57 return list(obj.__class__._properties)
58
59 -def get_attrs_for_expando(obj):
60 """ 61 Returns a list of dynamic properties on a C{db.Expando} instance. 62 """ 63 return obj.dynamic_properties()
64 65 pyamf.register_class(db.Model, attr_func=get_attrs_for_model, metadata=['dynamic']) 66 pyamf.register_class(db.Expando, attr_func=get_attrs_for_expando, metadata=['dynamic']) 67 68 amf0.Encoder.writeGoogleModel = writeObjectAMF0 69 amf0.Encoder.type_map.insert(len(amf0.Encoder.type_map) - 1, ((db.Model,db.Expando), "writeGoogleModel")) 70 71 amf3.Encoder.writeGoogleModel = writeObjectAMF3 72 amf3.Encoder.type_map.insert(len(amf3.Encoder.type_map) - 1, ((db.Model,db.Expando), "writeGoogleModel")) 73