Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 1415

Show
Ignore:
Timestamp:
10/27/06 13:14:09
Author:
fumanchu
Message:

Moved _cprequest.flattener to cherrypy.tools.flatten.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cherrypy/_cprequest.py

    r1406 r1415  
    540540        elif isinstance(value, types.FileType): 
    541541            value = file_generator(value) 
    542         elif isinstance(value, types.GeneratorType): 
    543             value = flattener(value) 
    544542        elif value is None: 
    545543            value = [] 
    546544        obj._body = value 
    547  
    548  
    549 def flattener(input): 
    550     """Yield the given input, recursively iterating over each result (if needed).""" 
    551     for x in input: 
    552         if not isinstance(x, types.GeneratorType): 
    553             yield x 
    554         else: 
    555             for y in flattener(x): 
    556                 yield y  
    557545 
    558546 
  • trunk/cherrypy/_cptools.py

    r1375 r1415  
    322322_d.digest_auth = Tool('on_start_resource', auth.digest_auth) 
    323323_d.trailing_slash = Tool('before_handler', cptools.trailing_slash) 
     324_d.flatten = Tool('before_finalize', cptools.flatten) 
    324325 
    325326del _d, cptools, encoding, auth, static, tidy 
  • trunk/cherrypy/lib/cptools.py

    r1412 r1415  
    332332                raise cherrypy.HTTPRedirect(new_url) 
    333333 
     334def flatten(): 
     335    """Wrap response.body in a generator that recursively iterates over body. 
     336     
     337    This allows cherrypy.response.body to consist of 'nested generators'; 
     338    that is, a set of generators that yield generators. 
     339    """ 
     340    import types 
     341    def flattener(input): 
     342        for x in input: 
     343            if not isinstance(x, types.GeneratorType): 
     344                yield x 
     345            else: 
     346                for y in flattener(x): 
     347                    yield y  
     348    response = cherrypy.response 
     349    response.body = flattener(response.body) 
     350 
  • trunk/cherrypy/test/test_core.py

    r1400 r1415  
    215215        def as_dblyield(self): 
    216216            yield self.as_yield() 
     217        as_dblyield._cp_config = {'tools.flatten.on': True} 
    217218         
    218219        def as_refyield(self): 

Hosted by WebFaction

Log in as guest/cpguest to create tickets