#NEWLINE# def setup_server( ) : #NEWLINE# #INDENT# class WSGIResponse ( object ) : #NEWLINE# #INDENT# def __init__( self , appresults ) : #NEWLINE# #INDENT# self . appresults = appresults #NEWLINE# self . iter = iter ( appresults ) #NEWLINE# #UNINDENT# def __iter__( self ) : #NEWLINE# #INDENT# return self #NEWLINE# #UNINDENT# def next( self ) : #NEWLINE# #INDENT# return self . iter . next ( ) #NEWLINE# #UNINDENT# def __next__( self ) : #NEWLINE# #INDENT# return next ( self . iter ) #NEWLINE# #UNINDENT# def close( self ) : #NEWLINE# #INDENT# if hasattr ( self . appresults , 'close' ) : #NEWLINE# #INDENT# self . appresults . close ( ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# class ChangeCase ( object ) : #NEWLINE# #INDENT# def __init__( self , app , to = None ) : #NEWLINE# #INDENT# self . app = app #NEWLINE# self . to = to #NEWLINE# #UNINDENT# def __call__( self , environ , start_response ) : #NEWLINE# #INDENT# res = self . app ( environ , start_response ) #NEWLINE# class CaseResults ( WSGIResponse ) : #NEWLINE# #INDENT# def next( this ) : #NEWLINE# #INDENT# return getattr ( this . iter . next ( ) , self . to ) ( ) #NEWLINE# #UNINDENT# def __next__( this ) : #NEWLINE# #INDENT# return getattr ( next ( this . iter ) , self . to ) ( ) #NEWLINE# #UNINDENT# #UNINDENT# return CaseResults ( res ) #NEWLINE# #UNINDENT# #UNINDENT# class Replacer ( object ) : #NEWLINE# #INDENT# def __init__( self , app , map = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# self . app = app #NEWLINE# self . map = map #NEWLINE# #UNINDENT# def __call__( self , environ , start_response ) : #NEWLINE# #INDENT# res = self . app ( environ , start_response ) #NEWLINE# class ReplaceResults ( WSGIResponse ) : #NEWLINE# #INDENT# def next( this ) : #NEWLINE# #INDENT# line = this . iter . next ( ) #NEWLINE# for ( k , v ) in self . map . iteritems ( ) : #NEWLINE# #INDENT# line = line . replace ( k , v ) #NEWLINE# #UNINDENT# return line #NEWLINE# #UNINDENT# def __next__( this ) : #NEWLINE# #INDENT# line = next ( this . iter ) #NEWLINE# for ( k , v ) in self . map . items ( ) : #NEWLINE# #INDENT# line = line . replace ( k , v ) #NEWLINE# #UNINDENT# return line #NEWLINE# #UNINDENT# #UNINDENT# return ReplaceResults ( res ) #NEWLINE# #UNINDENT# #UNINDENT# class Root ( object ) : #NEWLINE# #INDENT# def index( self ) : #NEWLINE# #INDENT# return 'HellO WoRlD!' #NEWLINE# #UNINDENT# index . exposed = True #NEWLINE# #UNINDENT# root_conf = { #NEWLINE# #INDENT# 'wsgi.pipeline' : [ ( 'replace' , Replacer ) ] , #NEWLINE# 'wsgi.replace.map' : { #NEWLINE# #INDENT# ntob ( 'L' ) : ntob ( 'X' ) , #NEWLINE# ntob ( 'l' ) : ntob ( 'r' ) , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } #NEWLINE# app = cherrypy . Application ( Root ( ) ) #NEWLINE# app . wsgiapp . pipeline . append ( ( 'changecase' , ChangeCase ) ) #NEWLINE# app . wsgiapp . config [ 'changecase' ] = { #NEWLINE# #INDENT# 'to' : 'upper' , #NEWLINE# #UNINDENT# } #NEWLINE# cherrypy . tree . mount ( app , config = { #NEWLINE# #INDENT# '/' : root_conf , #NEWLINE# #UNINDENT# } )