Exemplo n.º 1
0
 def __contains__(self, item):
     self._id_name_list()
     if isinstance(item, str) or isinstance(item, unicode):
         if is_bson_id(item):
             return item in [item.id for item in self._list]
         else:
             return item in [item.name for item in self._list]
     return item.id in [item.id for item in self._list]
 def __contains__(self, item):
     self._id_name_list()
     if isinstance(item, str) or isinstance(item, unicode):
         if is_bson_id(item):
             return item in [item.id for item in self._list]
         else:
             return item in [item.name for item in self._list]
     return item.id in [item.id for item in self._list]
Exemplo n.º 3
0
    def __getitem__(self, item):
        self._id_name_list()
        if isinstance(item, int): return self._get_item(self._list[item])
        elif isinstance(item, slice): return [self._get_item(i) for i in self._list[item]]

        found = [x for x in self._list if (is_bson_id(item) and x.id == item) or x.name == item]
        if len(found) is 0:
            raise exceptions.NotFoundError("None of '{1}' in {0}".format(self.__class__.__name__, item))
        return self._get_item(found[-1])
    def __getitem__(self, item):
        self._id_name_list()
        if isinstance(item, int): return self._get_item(self._list[item])
        elif isinstance(item, slice):
            return [self._get_item(i) for i in self._list[item]]

        found = [
            x for x in self._list
            if (is_bson_id(item) and x.id == item) or x.name == item
        ]
        if len(found) is 0:
            raise exceptions.NotFoundError("None of '{1}' in {0}".format(
                self.__class__.__name__, item))
        return self._get_item(found[-1])