示例#1
0
文件: serial.py 项目: ff0000/bongo
	def dbinstance(self, dbrefserial):
		if isinstance(dbrefserial, mongor.DBRef):
			dbref = dbrefserial
			dbrefserial = mongor.serialize_dbref(dbrefserial)
		else:
			dbref = mongor.deserialize_dbref(dbrefserial)
		
		# look for instance - is this necessary or good?
		instance = mongor.Model.__instances__.get(dbrefserial)
		if instance: return instance
		
		# okay find the class
		cls = mongor.ModelMeta.__subclasses__.get(dbref.collection)
		if cls: return cls.get(dbref.id)
示例#2
0
文件: serial.py 项目: ff0000/bongo
	def _process_arg(self, kind, value):
		if kind == basestring: #TODO: does this still need to be here?
			return unicode(value)
		elif kind == bool:
			if isinstance(value, basestring) and value.isdigit():
				return bool(int(value))
			return bool(value)
		elif kind == datetime:
			try:
				return datetime.strptime(value, '%Y-%m-%d %H:%M:%S')
			except ValueError:
				return datetime.strptime(value, '%Y-%m-%d %H:%M:%S.%f')
		elif kind == date:
			return datetime.strptime(value, '%Y-%m-%d')
		elif kind == dict and isinstance(value, basestring):
			# You probably meant to input a dict
			return json.loads(value)
		elif kind == mongor.DBRef and not isinstance(value, mongor.DBRef):
			return mongor.deserialize_dbref(value)
		else:
			return kind(value)