Skip to content

Commit

Permalink
removed unused map resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
joamag committed Mar 28, 2016
1 parent c67d117 commit 70d6a42
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
20 changes: 13 additions & 7 deletions src/quorum/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
from . import common
from . import legacy
from . import typesf
from . import mongodb
from . import observer
from . import validation
from . import exceptions
Expand Down Expand Up @@ -1283,12 +1282,12 @@ def _name(cls):
return name

@classmethod
def _eager(cls, model, names, map = False):
def _eager(cls, model, names):
# verifies if the provided model instance is a sequence and if
# that's the case runs the recursive eager loading of names and
# returns the resulting sequence to the caller method
is_list = isinstance(model, (list, tuple))
if is_list: return [cls._eager(_model, names, map = map) for _model in model]
if is_list: return [cls._eager(_model, names) for _model in model]

# iterates over the complete set of names that are meant to be
# eager loaded from the model and runs the "resolution" process
Expand All @@ -1297,20 +1296,20 @@ def _eager(cls, model, names, map = False):
_model = model
for part in name.split("."):
is_sequence = type(_model) in (list, tuple)
if is_sequence: _model = [cls._res(value, part, map = map) for value in _model]
else: _model = cls._res(_model, part, map = map)
if is_sequence: _model = [cls._res(value, part) for value in _model]
else: _model = cls._res(_model, part)
if not _model: break

# returns the resulting model to the caller method, most of the
# times this model should have not been touched
return model

@classmethod
def _res(cls, model, part, map = False):
def _res(cls, model, part):
value = model[part]
is_reference = isinstance(value, TYPE_REFERENCES)
if not value and not is_reference: return value
if is_reference: model[part] = value.resolve(map = map)
if is_reference: model[part] = value.resolve()
model = model[part]
return model

Expand Down Expand Up @@ -1598,6 +1597,13 @@ def logger(self):
def val(self, name, default = None):
return self.model.get(name, default)

def json_v(self, *args, **kwargs):
return self.model

def map_v(self, *args, **kwargs):
resolve = kwargs.get("resolve", True)
return self._resolve_all(self.model, resolve = resolve)

def build_m(self, model = None, rules = True):
"""
Builds the currently defined model, this should run
Expand Down
20 changes: 8 additions & 12 deletions src/quorum/typesf.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,21 +459,23 @@ def json_v(self, *args, **kwargs):
else: return self.value()

def map_v(self, *args, **kwargs):
value = self.resolve()
if not value: return value
resolve = kwargs.get("resolve", True)
value = self.resolve() if resolve else self._object
if resolve and not value: return value
if not value: return self.id
return value.map(*args, **kwargs)

def value(self):
is_empty = self.id in ("", b"", None)
if is_empty: return None
return self._type(self.id)

def resolve(self, map = False, strict = False):
def resolve(self, strict = False):
# verifies if the underlying object reference exists
# in the current names dictionary and if it exists
# verifies if it's valid (value is valid) if that's
# the case returns the current value immediately
exists = "_object" in self.__dict__ and not map
exists = "_object" in self.__dict__
if exists and self._object: return self._object

# verifies if there's an id value currently set in
Expand All @@ -492,14 +494,8 @@ def resolve(self, map = False, strict = False):
kwargs = {
name : self._target.cast(name, self.id)
}
if map: kwargs["map"] = map
_object = self._target.get(raise_e = strict, **kwargs)

# in case the map flag is active the retrieved value is returned
# immediately, not valid to store a map base retrieval as the
# resolved object as the serialization process is not compatible
if map: return _object

# sets the resolved object (using the current id attribute)
# in the current instance's dictionary and then returns this
# value to the caller method as the resolved value
Expand Down Expand Up @@ -592,8 +588,8 @@ def map_v(self, *args, **kwargs):
def list(self):
return [object.value() for object in self.objects]

def resolve(self, map = False):
return [object.resolve(map = map) for object in self.objects]
def resolve(self):
return [object.resolve() for object in self.objects]

def is_empty(self):
ids_l = len(self.ids)
Expand Down

0 comments on commit 70d6a42

Please sign in to comment.