Contact: fumanchu@aminus.org

Log in as guest/dejavu to create tickets

Changeset 579

Show
Ignore:
Timestamp:
11/06/07 13:56:34
Author:
fumanchu
Message:

Some cleanup of storage init.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/dejavu/storage/__init__.py

    r555 r579  
    246246    def xrecall(self, classes, expr=None, order=None, limit=None, offset=None): 
    247247        """Return an iterable of Units.""" 
     248        if limit == 0: 
     249            return 
     250        if offset and not order: 
     251            raise TypeError("Order argument expected when offset is provided.") 
     252         
    248253        if isinstance(classes, dejavu.UnitJoin): 
    249254            for unitrow in self._xmultirecall(classes, expr, order=order, 
     
    456461    def xview(self, query, order=None, limit=None, offset=None, distinct=False): 
    457462        """Yield property tuples for the given query.""" 
     463        if limit == 0: 
     464            return 
     465        if offset and not order: 
     466            raise TypeError("Order argument expected when offset is provided.") 
     467         
    458468        if not isinstance(query, dejavu.Query): 
    459469            query = dejavu.Query(*query) 
     
    462472            self.log(logflags.VIEW.message(query, distinct)) 
    463473         
     474        if isinstance(query.attributes, logic.Expression): 
     475            attr_is_expr = True 
     476        elif query.attributes is None: 
     477            # Return all attributes (what sort order?) 
     478            raise NotImplementedError("Attribute order is undefined.") 
     479        else: 
     480            attr_is_expr = False 
     481         
    464482        expr = query.restriction 
    465483         
    466484        seen = {} 
    467485         
    468         # TODO: deconstruct expr into a set of subexpr's, one for 
    469         # each class in classes. 
    470486        if isinstance(query.relation, dejavu.UnitJoin): 
     487            # TODO: deconstruct expr into a set of subexpr's, one for 
     488            # each class in classes. 
    471489            filters = dict([(cls, None) for cls in query.relation]) 
    472490            data = self._combine(query.relation, filters) 
     
    476494                data = iter(data) 
    477495             
    478             if isinstance(query.attributes, logic.Expression): 
    479                 def puller()
    480                     for unitrow in data
    481                         if expr is None or expr(*unitrow)
     496            def puller(): 
     497                for unitrow in data
     498                    if expr is None or expr(*unitrow)
     499                        if attr_is_expr
    482500                            datarow = tuple(query.attributes(*unitrow)) 
    483                             if distinct: 
    484                                 if datarow not in seen: 
    485                                     yield datarow 
    486                                     seen[datarow] = None 
    487                             else: 
    488                                 yield datarow 
    489             elif query.attributes is None: 
    490                 # TODO: What sort order (within each Unit)? 
    491                 choke 
    492             else: 
    493                 def puller(): 
    494                     for unitrow in data: 
    495                         if expr is None or expr(*unitrow): 
     501                        else: 
    496502                            datarow = [] 
    497503                            for i, attrs in enumerate(query.attributes): 
    498504                                unit = unitrow[i] 
    499505                                if attrs is None: 
    500                                     # Return all attributes (what sort order?) 
    501                                     choke 
     506                                    # Return all attributes (TODO: what sort order?) 
     507                                    raise NotImplementedError("Attribute order is undefined.") 
    502508                                else: 
    503509                                    for attr in attrs: 
    504510                                        datarow.append(getattr(unit, attr)) 
    505511                            datarow = tuple(datarow) 
    506                             if distinct: 
    507                                 if datarow not in seen: 
    508                                     yield datarow 
    509                                     seen[datarow] = None 
    510                             else: 
     512                        if distinct: 
     513                            if datarow not in seen: 
    511514                                yield datarow 
     515                                seen[datarow] = None 
     516                        else: 
     517                            yield datarow 
    512518        else: 
    513519            data = self.recall(query.relation, expr) 
     
    516522                data = iter(data) 
    517523             
    518             if isinstance(query.attributes, logic.Expression): 
    519                 def puller(): 
    520                     for unit in data: 
    521                         if expr is None or expr(unit): 
     524            def puller(): 
     525                for unit in data: 
     526                    if expr is None or expr(unit): 
     527                        # Use tuples for hashability. 
     528                        if attr_is_expr: 
    522529                            datarow = tuple(query.attributes(unit)) 
    523                             if distinct: 
    524                                 if datarow not in seen: 
    525                                     yield datarow 
    526                                     seen[datarow] = None 
    527                             else: 
    528                                 yield datarow 
    529             elif query.attributes is None: 
    530                 # Return all attributes (what sort order?) 
    531                 choke 
    532             else: 
    533                 def puller(): 
    534                     for unit in data: 
    535                         if expr is None or expr(unit): 
    536                             # Use tuples for hashability. 
     530                        else: 
    537531                            datarow = tuple([getattr(unit, attr) 
    538532                                             for attr in query.attributes]) 
    539                             if distinct: 
    540                                 if datarow not in seen: 
    541                                     yield datarow 
    542                                     seen[datarow] = None 
    543                             else: 
     533                        if distinct: 
     534                            if datarow not in seen: 
    544535                                yield datarow 
     536                                seen[datarow] = None 
     537                        else: 
     538                            yield datarow 
    545539         
    546540        ordered_data = puller() 
     
    775769    def xrecall(self, classes, expr=None, order=None, limit=None, offset=None): 
    776770        """Return an iterable of Units.""" 
     771        if limit == 0: 
     772            return 
     773        if offset and not order: 
     774            raise TypeError("Order argument expected when offset is provided.") 
     775         
    777776        if isinstance(classes, dejavu.UnitJoin): 
    778777            for unitrow in self._xmultirecall(classes, expr, order=order, 
     
    811810    def xview(self, query, order=None, limit=None, offset=None, distinct=False): 
    812811        """Yield property tuples for the given query.""" 
     812        if limit == 0: 
     813            return 
     814        if offset and not order: 
     815            raise TypeError("Order argument expected when offset is provided.") 
     816         
    813817        if not isinstance(query, dejavu.Query): 
    814818            query = dejavu.Query(*query)