当前位置: 首页>>代码示例>>Python>>正文


Python Model.from_version方法代码示例

本文整理汇总了Python中model.Model.from_version方法的典型用法代码示例。如果您正苦于以下问题:Python Model.from_version方法的具体用法?Python Model.from_version怎么用?Python Model.from_version使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在model.Model的用法示例。


在下文中一共展示了Model.from_version方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get

# 需要导入模块: from model import Model [as 别名]
# 或者: from model.Model import from_version [as 别名]
  def get(self, key):
    '''Retrieves the current entity addressed by `key`'''
    if not isinstance(key, Key):
      raise ValueError('key must be of type %s' % Key)

    # lookup the key in the datastore
    data = self._store.get(key)
    if data is None:
      return data

    # handle the data. if any conversion fails, propagate the exception up.
    serialRep = SerialRepresentation(data)
    version = Version(serialRep)
    return Model.from_version(version)
开发者ID:jbenet,项目名称:py-dronestore,代码行数:16,代码来源:repo.py

示例2: merge

# 需要导入模块: from model import Model [as 别名]
# 或者: from model.Model import from_version [as 别名]
  def merge(self, newVersionOrEntity):
    '''Merges a new version of an instance with the current one in the store.'''

    # get the new version
    new_version = self._cleanVersion(newVersionOrEntity)

    # get the instance
    key = new_version.key
    curr_instance = self.get(key) #THINKME(jbenet): try contains first?

    # brand new version. just store it.
    if curr_instance is None:
      self.put(new_version)
      return Model.from_version(new_version)

    # NOTE: semantically, we must merge into the current instance in the repo
    # so that merge strategies favor the incumbent version.
    curr_instance.merge(new_version)

    # store it back
    self.put(curr_instance)
    return curr_instance
开发者ID:jbenet,项目名称:py-dronestore,代码行数:24,代码来源:repo.py

示例3: next

# 需要导入模块: from model import Model [as 别名]
# 或者: from model.Model import from_version [as 别名]
  def next(self):
    '''Returns an instance of the version represented by the next object.'''
    if self.iter is None:
      raise StopIteration

    # if it returns none, return None as well. None is not necessarily the end.
    next = self.iter.next()
    if next is None:
      return None

    # if it is a dictionary, assume raw serial representation
    if isinstance(next, dict):
      next = serial.SerialRepresentation(next)

    # if it is a serialRepresentation, turn it into a Version
    if isinstance(next, serial.SerialRepresentation):
      next = Version(next)

    # if it is a Version, turn it into a Model
    if isinstance(next, Version):
      next = Model.from_version(next)

    # return whatever it is we have!
    return next
开发者ID:jbenet,项目名称:py-dronestore,代码行数:26,代码来源:query.py


注:本文中的model.Model.from_version方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。