本文整理汇总了Python中memobject.MemObject类的典型用法代码示例。如果您正苦于以下问题:Python MemObject类的具体用法?Python MemObject怎么用?Python MemObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MemObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: syncDB
def syncDB(self):
"""同步到数据库
"""
state = self.get('_state')
tablename = self._name.split(':')[0]
if state == MMODE_STATE_ORI:
return
elif state == MMODE_STATE_NEW:
props = self.get('data')
props = self.dumps(props)
pk = self.get('_pk')
result = util.InsertIntoDB(tablename, props)
elif state == MMODE_STATE_UPDATE:
props = self.get('data')
pk = self.get('_pk')
props = self.dumps(props)
prere = {pk: props.get(pk)}
del(props[pk])
util.UpdateWithDict(tablename, props, prere)
result = True
else:
pk = self.get('_pk')
props = self.get('data')
props = self.dumps(props)
prere = {pk: props.get(pk)}
result = util.DeleteFromDB(tablename, prere)
if result:
MemObject.update(self, '_state', MMODE_STATE_ORI)
示例2: __init__
def __init__(self, name,pk,data={},fk=None,**kw):
"""
"""
MemObject.__init__(self, name,**kw)
self._pk = pk
self._fk = fk
self.data = data
示例3: __init__
def __init__(self, name,pk,timeout=TIMEOUT,**kw):
MemObject.__init__(self, name, mclient)
self._pk = pk
self._fk = kw.get('fk','')
self._incrkey = kw.get('incrkey','')
self._incrvalue = kw.get('incrvalue',0)
self._timeout = timeout
示例4: __init__
def __init__(self, name,pk,data={}):
"""
"""
MemObject.__init__(self, name, mclient)
self._state = MMODE_STATE_ORI#对象的状态 0未变更 1新建 2更新 3删除
self._pk = pk
self.data = data
self._time = time.time()
示例5: __init__
def __init__(self, pid, name, mc):
"""
"""
MemObject.__init__(self, name, mc)
self.id = pid
self.level = 0
self.profession = 0
self.nickname = u""
self.guanqia = 1000
示例6: __init__
def __init__(self,pid,name,mc):
"""初始化城镇要塞对象
@param territoryId: int 领地的ID
@param guard: int 殖民者的ID
@param guardname: str 殖民者的名称
@param updateTime: int 领地被更新的时间
"""
MemObject.__init__(self, name, mc)
self.id = pid
self.level = 0
self.profession = 0
self.nickname = u''
self.guanqia = 1000
示例7: checkSync
def checkSync(self,timeout=TIMEOUT):
"""检测同步
"""
ntime = time.time()
objtime = MemObject.get(self, '_time')
self.syncDB()
if ntime -objtime>=timeout and timeout:
self.mdelete()
示例8: update
def update(self, key, values):
data = self.get_multi(['data','_state'])
ntime = time.time()
data[key] = values
if data.get('_state')==1:
props = {'data':data.get('data'),'_time':ntime}
else:
props = {'_state':2,'data':data.get('data'),'_time':ntime}
return MemObject.update_multi(self,props)
示例9: checkSync
def checkSync(self, timeout=TIMEOUT):
"""检测同步
"""
ntime = time.time()
objtime = MemObject.get(self, '_time')
if ntime - objtime >= timeout and timeout:
self.mdelete()
else:
reactor.callLater(0, self.syncDB)
示例10: update
def update(self, key, values):
data = self.get_multi(['data','_state'])
ntime = time.time()
data['data'].update({key:values})
if data.get('_state')==MMODE_STATE_NEW:
props = {'data':data.get('data'),'_time':ntime}
else:
props = {'_state':MMODE_STATE_UPDATE,'data':data.get('data'),'_time':ntime}
return MemObject.update_multi(self, props)
示例11: update_multi
def update_multi(self, mapping):
ntime = time.time()
data = self.get_multi(['data','_state'])
data['data'].update(mapping)
if data.get('_state')==1:
props = {'data':data.get('data'),'_time':ntime}
else:
props = {'_state':2,'data':data.get('data'),'_time':ntime}
return MemObject.update_multi(self, props)
示例12: update_multi
def update_multi(self, mapping):
n_time = time.time()
data = self.get_multi(['data', '_state'])
data['data'].update(mapping)
if data.get('_state') == MMODE_STATE_NEW:
props = {'data': data.get('data'), '_time': n_time}
else:
props = {'_state': MMODE_STATE_UPDATE, 'data': data.get('data'), '_time': n_time}
return MemObject.update_multi(self, props)
示例13: update
def update(self, key, values):
data = self.getData()
if self._fk and self._fk==key:#判断外键是否更新
fk = data.get(self._fk,"")
pk = data.get(self._pk)
self._update_fk(pk, fk, values)#更新外键
data.update({key:values})
result = MemObject.update(self, 'data',data)
self.syncDB()
return result
示例14: update
def update(self, key, value):
data = self.getData()
fkName = self._mAdmin.getFk()
pkName = self._mAdmin.getPk()
if fkName and fkName == key:
fk = data.get(fkName, "")
pk = data.get(pkName)
self._updateFk(pk, fk, value)
data[key] = value
return MemObject.update(self, 'data', data) and self._updateDB(data[pkName], {key:value})
示例15: update_multi
def update_multi(self, mapping):
data = self.getData()
if self._fk and self._fk in mapping.keys():#查看外键是否在更新的map中
fk = data.get(self._fk,"")
new_fk = mapping.get(self._fk,fk)
if new_fk!=fk:#查看外键的值是否发生了变化
pk = data.get(self._pk)
self._update_fk(pk, fk, new_fk)#更新外键
data.update(mapping)
result = MemObject.update(self, 'data',data)
self.syncDB()
return result