Changeset 3868:c3e7ae860b4a in livinglogic.python.xist

Show
Ignore:
Timestamp:
10/09/09 16:49:04 (10 years ago)
Author:
Walter Doerwald <walter@…>
Branch:
default
Message:

Make Pipeline a subclass of tuple.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/ll/xist/parsers.py

    r3867 r3868  
    148148### 
    149149 
    150 class Pipeline(object): 
     150class Pipeline(tuple): 
    151151    """ 
    152152    A :class:`Pipeline` object is a sequence of :class:`PipelineObject` instances. 
     
    155155    pipeline. 
    156156    """ 
    157     def __init__(self, *objects): 
    158         self.objects = objects 
     157    def __new__(cls, *objects): 
     158        return tuple.__new__(cls, objects) 
    159159 
    160160    def __or__(self, other): 
    161         return Pipeline(*(self.objects + (other,))) 
     161        return Pipeline(*(self + (other,))) 
    162162 
    163163    def __iter__(self): 
    164         url = self.objects[0].url 
     164        url = self[0].url 
    165165        pipe = None 
    166         for obj in self.objects: 
     166        for obj in tuple.__iter__(self): 
    167167            pipe = obj.transform(pipe, url) 
    168168        return pipe 
    169169 
    170170    def __repr__(self): 
    171         return "(%s)" % " | ".join(repr(obj) for obj in self.objects) 
     171        return "(%s)" % " | ".join(repr(obj) for obj in self) 
    172172 
    173173