'Initialize a KeyRange object.
Args:
key_start: The starting key for this range (db.Key or ndb.Key).
key_end: The ending key for this range (db.Key or ndb.Key).
direction: The direction of the query for this range.
include_start: Whether the start key should be included in the range.
include_end: Whether the end key should be included in the range.
namespace: The namespace for this range. If None then the current
namespace is used.
NOTE: If NDB keys are passed in, they are converted to db.Key
instances before being stored.'

def __init__(self, key_start=None, key_end=None, direction=None, include_start=True, include_end=True, namespace=None, _app=None):

    if (direction is None):
        direction = KeyRange.ASC
    assert (direction in (KeyRange.ASC, KeyRange.DESC))
    self.direction = direction
    if (ndb is not None):
        if isinstance(key_start, ndb.Key):
            key_start = key_start.to_old_key()
        if isinstance(key_end, ndb.Key):
            key_end = key_end.to_old_key()
    self.key_start = key_start
    self.key_end = key_end
    self.include_start = include_start
    self.include_end = include_end
    if (namespace is not None):
        self.namespace = namespace
    else:
        self.namespace = namespace_manager.get_namespace()
    self._app = _app
