# Path: smc/base/decorators.py
# class cached_property(object):
#     """
#     Use for caching a property value on the instance. If the
#     attribute is deleted, it will be recreated when called.
#     """
# 
#     def __init__(self, func):
#         self.func = func
#         #self.__doc__ = func.__doc__
# 
#     def __get__(self, obj, cls):
#         if obj is None:
#             return self
#         value = obj.__dict__[self.func.__name__] = self.func(obj)
#         return value
# 
# class classproperty(object):
#     """
#     Used for collection manager so objects can be accessed as a
#     class property and also from the instance
#     """
# 
#     def __init__(self, fget):
#         self.fget = fget
# 
#     def __get__(self, instance, owner_cls):
#         return self.fget(owner_cls)
# 
# Path: smc/api/exceptions.py
# class FetchElementFailed(SMCException):
#     """
#     Failure when fetching results
#     """
# 
# class InvalidSearchFilter(SMCException):
#     """
#     Thrown by collections when using invalid search sequences.
#     """
# 
# Path: smc/api/common.py
# def entry_point():
#     return _get_session().entry_points


import re
import copy
import smc.base.model
from itertools import islice
from smc.base.decorators import cached_property, classproperty
from smc.api.exceptions import FetchElementFailed, InvalidSearchFilter
from smc.api.common import entry_point
        3
        >>> query2 = query1.filter(address='10.10.10.1')  # change filter to kwarg
        >>> list(query2)
        [Router(name=Router-10.10.10.1)]

    .. note:: ``exists`` does not perform filtering when using ``filter_key``.
        Results on filter(kwargs) are only done by retrieving the list of
        results or iterating.
    """
    def __init__(self, **params):
        self._params = params
        self._iexact = params.pop('iexact', None)

    def __iter__(self):
        limit = self._params.pop('limit', None)
        count = 0
        
        for item in self._list:
            element = smc.base.model.Element.from_meta(**item)
            if self._iexact:
                if all(element.data.get(k) == v for k, v in self._iexact.items()):
                    yield element
                    count += 1
            else:
                yield element
                count += 1
                
            if limit and count >= limit:
                return
    

# Path: smc/base/decorators.py
# class cached_property(object):
#     """
#     Use for caching a property value on the instance. If the
#     attribute is deleted, it will be recreated when called.
#     """
# 
#     def __init__(self, func):
#         self.func = func
#         #self.__doc__ = func.__doc__
# 
#     def __get__(self, obj, cls):
#         if obj is None:
#             return self
#         value = obj.__dict__[self.func.__name__] = self.func(obj)
#         return value
# 
# class classproperty(object):
#     """
#     Used for collection manager so objects can be accessed as a
#     class property and also from the instance
#     """
# 
#     def __init__(self, fget):
#         self.fget = fget
# 
#     def __get__(self, instance, owner_cls):
#         return self.fget(owner_cls)
# 
# Path: smc/api/exceptions.py
# class FetchElementFailed(SMCException):
#     """
#     Failure when fetching results
#     """
# 
# class InvalidSearchFilter(SMCException):
#     """
#     Thrown by collections when using invalid search sequences.
#     """
# 
# Path: smc/api/common.py
# def entry_point():
#     return _get_session().entry_points


# Path: smc/base/collection.py
import re
import copy
import smc.base.model
from itertools import islice
from smc.base.decorators import cached_property, classproperty
from smc.api.exceptions import FetchElementFailed, InvalidSearchFilter
from smc.api.common import entry_point

        3
        >>> query2 = query1.filter(address='10.10.10.1')  # change filter to kwarg
        >>> list(query2)
        [Router(name=Router-10.10.10.1)]

    .. note:: ``exists`` does not perform filtering when using ``filter_key``.
        Results on filter(kwargs) are only done by retrieving the list of
        results or iterating.
    """
    def __init__(self, **params):
        self._params = params
        self._iexact = params.pop('iexact', None)

    def __iter__(self):
        limit = self._params.pop('limit', None)
        count = 0
        
        for item in self._list:
            element = smc.base.model.Element.from_meta(**item)
            if self._iexact:
                if all(element.data.get(k) == v for k, v in self._iexact.items()):
                    yield element
                    count += 1
            else:
                yield element
                count += 1
                
            if limit and count >= limit:
                return
    

    @cached_property