python类Model()的实例源码

appengine.py 文件源码 项目:oscars2016 作者: 0x0ece 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def _is_ndb(self):
        """Determine whether the model of the instance is an NDB model.

        Returns:
            Boolean indicating whether or not the model is an NDB or DB model.
        """
        # issubclass will fail if one of the arguments is not a class, only
        # need worry about new-style classes since ndb and db models are
        # new-style
        if isinstance(self._model, type):
            if ndb is not None and issubclass(self._model, ndb.Model):
                return True
            elif issubclass(self._model, db.Model):
                return False

        raise TypeError('Model class not an NDB or DB model: %s.' %
                        (self._model,))
_google_appengine_ext_db.py 文件源码 项目:Tinychat-Bot--Discontinued 作者: Tinychat 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def transform_xdb_stubs(payload, context):
    """
    Called when a successful decode has been performed. Transform the stubs
    within the payload to proper db.Model instances.
    """
    stubs = context.get(XDB_STUB_NAME, None)

    if not stubs:
        return payload

    stubs.transform()

    return payload


# initialise the module here: hook into pyamf
appengine.py 文件源码 项目:GAMADV-XTD 作者: taers232c 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def _is_ndb(self):
        """Determine whether the model of the instance is an NDB model.

        Returns:
            Boolean indicating whether or not the model is an NDB or DB model.
        """
        # issubclass will fail if one of the arguments is not a class, only
        # need worry about new-style classes since ndb and db models are
        # new-style
        if isinstance(self._model, type):
            if _NDB_MODEL is not None and issubclass(self._model, _NDB_MODEL):
                return True
            elif issubclass(self._model, db.Model):
                return False

        raise TypeError(
            'Model class not an NDB or DB model: {0}.'.format(self._model))
polymodel.py 文件源码 项目:Intranet-Penetration 作者: yuxiaokui 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def from_entity(cls, entity):
    """Load from entity to class based on discriminator.

    Rather than instantiating a new Model instance based on the kind
    mapping, this creates an instance of the correct model class based
    on the entities class-key.

    Args:
      entity: Entity loaded directly from datastore.

    Raises:
      KindError when there is no class mapping based on discriminator.
    """
    if (_CLASS_KEY_PROPERTY in entity and
        tuple(entity[_CLASS_KEY_PROPERTY]) != cls.class_key()):
      key = tuple(entity[_CLASS_KEY_PROPERTY])
      try:
        poly_class = _class_map[key]
      except KeyError:
        raise db.KindError('No implementation for class \'%s\'' % (key,))
      return poly_class.from_entity(entity)
    return super(PolyModel, cls).from_entity(entity)
blobstore.py 文件源码 项目:Intranet-Penetration 作者: yuxiaokui 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __init__(self, query_string, model_class, *args, **kwds):
    """Constructor.

    Args:
      query_string: Properly formatted GQL query string.
      model_class: Model class from which entities are constructed.
      *args: Positional arguments used to bind numeric references in the query.
      **kwds: Dictionary-based arguments for named references.
    """


    from google.appengine.ext import gql
    app = kwds.pop('_app', None)
    self._proto_query = gql.GQL(query_string, _app=app, namespace='')

    super(db.GqlQuery, self).__init__(model_class)
    self.bind(*args, **kwds)
__init__.py 文件源码 项目:Intranet-Penetration 作者: yuxiaokui 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def make_directed_query(self, kind_class, keys_only=False):
    """Construct a query for this key range, including the scan direction.

    Args:
      kind_class: A kind implementation class (a subclass of either
        db.Model or ndb.Model).
      keys_only: bool, default False, use keys_only on Query?

    Returns:
      A db.Query or ndb.Query instance (corresponding to kind_class).

    Raises:
      KeyRangeError: if self.direction is not in (KeyRange.ASC, KeyRange.DESC).
    """
    if ndb is not None:
      if issubclass(kind_class, ndb.Model):
        return self.make_directed_ndb_query(kind_class, keys_only=keys_only)
    assert self._app is None, '_app is not supported for db.Query'
    direction = self.__get_direction("", "-")
    query = db.Query(kind_class, namespace=self.namespace, keys_only=keys_only)
    query.order("%s__key__" % direction)

    query = self.filter_query(query)
    return query
__init__.py 文件源码 项目:Intranet-Penetration 作者: yuxiaokui 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def make_ascending_ndb_query(self, kind_class, keys_only=False, filters=None):
    """Construct an NDB query for this key range, without the scan direction.

    Args:
      kind_class: An ndb.Model subclass.
      keys_only: bool, default False, query only for keys.

    Returns:
      An ndb.Query instance.
    """
    assert issubclass(kind_class, ndb.Model)
    if keys_only:
      default_options = ndb.QueryOptions(keys_only=True)
    else:
      default_options = None
    query = kind_class.query(app=self._app,
                             namespace=self.namespace,
                             default_options=default_options)
    query = self.filter_ndb_query(query, filters=filters)
    query = query.order(kind_class._key)
    return query
bulkloader.py 文件源码 项目:Intranet-Penetration 作者: yuxiaokui 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def GetImplementationClass(kind_or_class_key):
  """Returns the implementation class for a given kind or class key.

  Args:
    kind_or_class_key: A kind string or a tuple of kind strings.

  Return:
    A db.Model subclass for the given kind or class key.
  """
  if isinstance(kind_or_class_key, tuple):
    try:
      implementation_class = polymodel._class_map[kind_or_class_key]
    except KeyError:
      raise db.KindError('No implementation for class \'%s\'' %
                         kind_or_class_key)
  else:
    implementation_class = db.class_for_kind(kind_or_class_key)
  return implementation_class
bulkloader.py 文件源码 项目:Intranet-Penetration 作者: yuxiaokui 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def handle_entity(self, entity):
    """Subclasses can override this to add custom entity conversion code.

    This is called for each entity, after its properties are populated
    from the input but before it is stored. Subclasses can override
    this to add custom entity handling code.

    The entity to be inserted should be returned. If multiple entities
    should be inserted, return a list of entities. If no entities
    should be inserted, return None or [].

    Args:
      entity: db.Model

    Returns:
      db.Model or list of db.Model
    """
    return entity
polymodel.py 文件源码 项目:MKFQ 作者: maojingios 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def from_entity(cls, entity):
    """Load from entity to class based on discriminator.

    Rather than instantiating a new Model instance based on the kind
    mapping, this creates an instance of the correct model class based
    on the entities class-key.

    Args:
      entity: Entity loaded directly from datastore.

    Raises:
      KindError when there is no class mapping based on discriminator.
    """
    if (_CLASS_KEY_PROPERTY in entity and
        tuple(entity[_CLASS_KEY_PROPERTY]) != cls.class_key()):
      key = tuple(entity[_CLASS_KEY_PROPERTY])
      try:
        poly_class = _class_map[key]
      except KeyError:
        raise db.KindError('No implementation for class \'%s\'' % (key,))
      return poly_class.from_entity(entity)
    return super(PolyModel, cls).from_entity(entity)
blobstore.py 文件源码 项目:MKFQ 作者: maojingios 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def __init__(self, query_string, model_class, *args, **kwds):
    """Constructor.

    Args:
      query_string: Properly formatted GQL query string.
      model_class: Model class from which entities are constructed.
      *args: Positional arguments used to bind numeric references in the query.
      **kwds: Dictionary-based arguments for named references.
    """


    from google.appengine.ext import gql
    app = kwds.pop('_app', None)
    self._proto_query = gql.GQL(query_string, _app=app, namespace='')

    super(db.GqlQuery, self).__init__(model_class)
    self.bind(*args, **kwds)
__init__.py 文件源码 项目:MKFQ 作者: maojingios 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def make_directed_query(self, kind_class, keys_only=False):
    """Construct a query for this key range, including the scan direction.

    Args:
      kind_class: A kind implementation class (a subclass of either
        db.Model or ndb.Model).
      keys_only: bool, default False, use keys_only on Query?

    Returns:
      A db.Query or ndb.Query instance (corresponding to kind_class).

    Raises:
      KeyRangeError: if self.direction is not in (KeyRange.ASC, KeyRange.DESC).
    """
    if ndb is not None:
      if issubclass(kind_class, ndb.Model):
        return self.make_directed_ndb_query(kind_class, keys_only=keys_only)
    assert self._app is None, '_app is not supported for db.Query'
    direction = self.__get_direction("", "-")
    query = db.Query(kind_class, namespace=self.namespace, keys_only=keys_only)
    query.order("%s__key__" % direction)

    query = self.filter_query(query)
    return query
__init__.py 文件源码 项目:MKFQ 作者: maojingios 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def make_ascending_ndb_query(self, kind_class, keys_only=False, filters=None):
    """Construct an NDB query for this key range, without the scan direction.

    Args:
      kind_class: An ndb.Model subclass.
      keys_only: bool, default False, query only for keys.

    Returns:
      An ndb.Query instance.
    """
    assert issubclass(kind_class, ndb.Model)
    if keys_only:
      default_options = ndb.QueryOptions(keys_only=True)
    else:
      default_options = None
    query = kind_class.query(app=self._app,
                             namespace=self.namespace,
                             default_options=default_options)
    query = self.filter_ndb_query(query, filters=filters)
    query = query.order(kind_class._key)
    return query
bulkloader.py 文件源码 项目:MKFQ 作者: maojingios 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def GetImplementationClass(kind_or_class_key):
  """Returns the implementation class for a given kind or class key.

  Args:
    kind_or_class_key: A kind string or a tuple of kind strings.

  Return:
    A db.Model subclass for the given kind or class key.
  """
  if isinstance(kind_or_class_key, tuple):
    try:
      implementation_class = polymodel._class_map[kind_or_class_key]
    except KeyError:
      raise db.KindError('No implementation for class \'%s\'' %
                         kind_or_class_key)
  else:
    implementation_class = db.class_for_kind(kind_or_class_key)
  return implementation_class
bulkloader.py 文件源码 项目:MKFQ 作者: maojingios 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def handle_entity(self, entity):
    """Subclasses can override this to add custom entity conversion code.

    This is called for each entity, after its properties are populated
    from the input but before it is stored. Subclasses can override
    this to add custom entity handling code.

    The entity to be inserted should be returned. If multiple entities
    should be inserted, return a list of entities. If no entities
    should be inserted, return None or [].

    Args:
      entity: db.Model

    Returns:
      db.Model or list of db.Model
    """
    return entity
appengine.py 文件源码 项目:deb-python-oauth2client 作者: openstack 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def _is_ndb(self):
        """Determine whether the model of the instance is an NDB model.

        Returns:
            Boolean indicating whether or not the model is an NDB or DB model.
        """
        # issubclass will fail if one of the arguments is not a class, only
        # need worry about new-style classes since ndb and db models are
        # new-style
        if isinstance(self._model, type):
            if _NDB_MODEL is not None and issubclass(self._model, _NDB_MODEL):
                return True
            elif issubclass(self._model, db.Model):
                return False

        raise TypeError(
            'Model class not an NDB or DB model: {0}.'.format(self._model))
appengine.py 文件源码 项目:REMAP 作者: REMAPApp 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def _is_ndb(self):
        """Determine whether the model of the instance is an NDB model.

        Returns:
            Boolean indicating whether or not the model is an NDB or DB model.
        """
        # issubclass will fail if one of the arguments is not a class, only
        # need worry about new-style classes since ndb and db models are
        # new-style
        if isinstance(self._model, type):
            if _NDB_MODEL is not None and issubclass(self._model, _NDB_MODEL):
                return True
            elif issubclass(self._model, db.Model):
                return False

        raise TypeError(
            'Model class not an NDB or DB model: {0}.'.format(self._model))
appengine.py 文件源码 项目:REMAP 作者: REMAPApp 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def __init__(self, model, key_name, property_name, cache=None, user=None):
    """Constructor for Storage.

    Args:
      model: db.Model or ndb.Model, model class
      key_name: string, key name for the entity that has the credentials
      property_name: string, name of the property that is a CredentialsProperty
        or CredentialsNDBProperty.
      cache: memcache, a write-through cache to put in front of the datastore.
        If the model you are using is an NDB model, using a cache will be
        redundant since the model uses an instance cache and memcache for you.
      user: users.User object, optional. Can be used to grab user ID as a
        key_name if no key name is specified.
    """
    if key_name is None:
      if user is None:
        raise ValueError('StorageByKeyName called with no key name or user.')
      key_name = user.user_id()

    self._model = model
    self._key_name = key_name
    self._property_name = property_name
    self._cache = cache
appengine.py 文件源码 项目:ecodash 作者: Servir-Mekong 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def _is_ndb(self):
        """Determine whether the model of the instance is an NDB model.

        Returns:
            Boolean indicating whether or not the model is an NDB or DB model.
        """
        # issubclass will fail if one of the arguments is not a class, only
        # need worry about new-style classes since ndb and db models are
        # new-style
        if isinstance(self._model, type):
            if _NDB_MODEL is not None and issubclass(self._model, _NDB_MODEL):
                return True
            elif issubclass(self._model, db.Model):
                return False

        raise TypeError(
            'Model class not an NDB or DB model: {0}.'.format(self._model))
appengine.py 文件源码 项目:ecodash 作者: Servir-Mekong 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def __init__(self, model, key_name, property_name, cache=None, user=None):
    """Constructor for Storage.

    Args:
      model: db.Model or ndb.Model, model class
      key_name: string, key name for the entity that has the credentials
      property_name: string, name of the property that is a CredentialsProperty
        or CredentialsNDBProperty.
      cache: memcache, a write-through cache to put in front of the datastore.
        If the model you are using is an NDB model, using a cache will be
        redundant since the model uses an instance cache and memcache for you.
      user: users.User object, optional. Can be used to grab user ID as a
        key_name if no key name is specified.
    """
    if key_name is None:
      if user is None:
        raise ValueError('StorageByKeyName called with no key name or user.')
      key_name = user.user_id()

    self._model = model
    self._key_name = key_name
    self._property_name = property_name
    self._cache = cache
appengine.py 文件源码 项目:OneClickDTU 作者: satwikkansal 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def __init__(self, model, key_name, property_name, cache=None, user=None):
        """Constructor for Storage.

        Args:
            model: db.Model or ndb.Model, model class
            key_name: string, key name for the entity that has the credentials
            property_name: string, name of the property that is a
                           CredentialsProperty or CredentialsNDBProperty.
            cache: memcache, a write-through cache to put in front of the
                   datastore. If the model you are using is an NDB model, using
                   a cache will be redundant since the model uses an instance
                   cache and memcache for you.
            user: users.User object, optional. Can be used to grab user ID as a
                  key_name if no key name is specified.
        """
        if key_name is None:
            if user is None:
                raise ValueError('StorageByKeyName called with no '
                                 'key name or user.')
            key_name = user.user_id()

        self._model = model
        self._key_name = key_name
        self._property_name = property_name
        self._cache = cache
appengine.py 文件源码 项目:OneClickDTU 作者: satwikkansal 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def _is_ndb(self):
        """Determine whether the model of the instance is an NDB model.

        Returns:
            Boolean indicating whether or not the model is an NDB or DB model.
        """
        # issubclass will fail if one of the arguments is not a class, only
        # need worry about new-style classes since ndb and db models are
        # new-style
        if isinstance(self._model, type):
            if ndb is not None and issubclass(self._model, ndb.Model):
                return True
            elif issubclass(self._model, db.Model):
                return False

        raise TypeError('Model class not an NDB or DB model: %s.' %
                        (self._model,))
polymodel.py 文件源码 项目:xxNet 作者: drzorm 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def from_entity(cls, entity):
    """Load from entity to class based on discriminator.

    Rather than instantiating a new Model instance based on the kind
    mapping, this creates an instance of the correct model class based
    on the entities class-key.

    Args:
      entity: Entity loaded directly from datastore.

    Raises:
      KindError when there is no class mapping based on discriminator.
    """
    if (_CLASS_KEY_PROPERTY in entity and
        tuple(entity[_CLASS_KEY_PROPERTY]) != cls.class_key()):
      key = tuple(entity[_CLASS_KEY_PROPERTY])
      try:
        poly_class = _class_map[key]
      except KeyError:
        raise db.KindError('No implementation for class \'%s\'' % (key,))
      return poly_class.from_entity(entity)
    return super(PolyModel, cls).from_entity(entity)
blobstore.py 文件源码 项目:xxNet 作者: drzorm 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def __init__(self, query_string, model_class, *args, **kwds):
    """Constructor.

    Args:
      query_string: Properly formatted GQL query string.
      model_class: Model class from which entities are constructed.
      *args: Positional arguments used to bind numeric references in the query.
      **kwds: Dictionary-based arguments for named references.
    """


    from google.appengine.ext import gql
    app = kwds.pop('_app', None)
    self._proto_query = gql.GQL(query_string, _app=app, namespace='')

    super(db.GqlQuery, self).__init__(model_class)
    self.bind(*args, **kwds)
__init__.py 文件源码 项目:xxNet 作者: drzorm 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def make_directed_query(self, kind_class, keys_only=False):
    """Construct a query for this key range, including the scan direction.

    Args:
      kind_class: A kind implementation class (a subclass of either
        db.Model or ndb.Model).
      keys_only: bool, default False, use keys_only on Query?

    Returns:
      A db.Query or ndb.Query instance (corresponding to kind_class).

    Raises:
      KeyRangeError: if self.direction is not in (KeyRange.ASC, KeyRange.DESC).
    """
    if ndb is not None:
      if issubclass(kind_class, ndb.Model):
        return self.make_directed_ndb_query(kind_class, keys_only=keys_only)
    assert self._app is None, '_app is not supported for db.Query'
    direction = self.__get_direction("", "-")
    query = db.Query(kind_class, namespace=self.namespace, keys_only=keys_only)
    query.order("%s__key__" % direction)

    query = self.filter_query(query)
    return query
__init__.py 文件源码 项目:xxNet 作者: drzorm 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def make_ascending_ndb_query(self, kind_class, keys_only=False, filters=None):
    """Construct an NDB query for this key range, without the scan direction.

    Args:
      kind_class: An ndb.Model subclass.
      keys_only: bool, default False, query only for keys.

    Returns:
      An ndb.Query instance.
    """
    assert issubclass(kind_class, ndb.Model)
    if keys_only:
      default_options = ndb.QueryOptions(keys_only=True)
    else:
      default_options = None
    query = kind_class.query(app=self._app,
                             namespace=self.namespace,
                             default_options=default_options)
    query = self.filter_ndb_query(query, filters=filters)
    query = query.order(kind_class._key)
    return query
bulkloader.py 文件源码 项目:xxNet 作者: drzorm 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def GetImplementationClass(kind_or_class_key):
  """Returns the implementation class for a given kind or class key.

  Args:
    kind_or_class_key: A kind string or a tuple of kind strings.

  Return:
    A db.Model subclass for the given kind or class key.
  """
  if isinstance(kind_or_class_key, tuple):
    try:
      implementation_class = polymodel._class_map[kind_or_class_key]
    except KeyError:
      raise db.KindError('No implementation for class \'%s\'' %
                         kind_or_class_key)
  else:
    implementation_class = db.class_for_kind(kind_or_class_key)
  return implementation_class
bulkloader.py 文件源码 项目:xxNet 作者: drzorm 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def handle_entity(self, entity):
    """Subclasses can override this to add custom entity conversion code.

    This is called for each entity, after its properties are populated
    from the input but before it is stored. Subclasses can override
    this to add custom entity handling code.

    The entity to be inserted should be returned. If multiple entities
    should be inserted, return a list of entities. If no entities
    should be inserted, return None or [].

    Args:
      entity: db.Model

    Returns:
      db.Model or list of db.Model
    """
    return entity
appengine.py 文件源码 项目:aqua-monitor 作者: Deltares 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def __init__(self, model, key_name, property_name, cache=None, user=None):
        """Constructor for Storage.

        Args:
            model: db.Model or ndb.Model, model class
            key_name: string, key name for the entity that has the credentials
            property_name: string, name of the property that is a
                           CredentialsProperty or CredentialsNDBProperty.
            cache: memcache, a write-through cache to put in front of the
                   datastore. If the model you are using is an NDB model, using
                   a cache will be redundant since the model uses an instance
                   cache and memcache for you.
            user: users.User object, optional. Can be used to grab user ID as a
                  key_name if no key name is specified.
        """
        if key_name is None:
            if user is None:
                raise ValueError('StorageByKeyName called with no '
                                 'key name or user.')
            key_name = user.user_id()

        self._model = model
        self._key_name = key_name
        self._property_name = property_name
        self._cache = cache
appengine.py 文件源码 项目:aqua-monitor 作者: Deltares 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def _is_ndb(self):
        """Determine whether the model of the instance is an NDB model.

        Returns:
            Boolean indicating whether or not the model is an NDB or DB model.
        """
        # issubclass will fail if one of the arguments is not a class, only
        # need worry about new-style classes since ndb and db models are
        # new-style
        if isinstance(self._model, type):
            if ndb is not None and issubclass(self._model, ndb.Model):
                return True
            elif issubclass(self._model, db.Model):
                return False

        raise TypeError('Model class not an NDB or DB model: %s.' %
                        (self._model,))


问题


面经


文章

微信
公众号

扫码关注公众号