<s> """<STR_LIT>""" <EOL> import os <EOL> import sys <EOL> import werkzeug <EOL> from textwrap import wrap <EOL> from werkzeug . wrappers import BaseRequest as Request , BaseResponse as Response <EOL> from werkzeug . utils import escape <EOL> logo = Response ( '''<STR_LIT>''' . decode ( '<STR_LIT>' ) , mimetype = '<STR_LIT>' ) <EOL> TEMPLATE = u'''<STR_LIT>''' <EOL> def iter_sys_path ( ) : <EOL> if os . name == '<STR_LIT>' : <EOL> def strip ( x ) : <EOL> prefix = os . path . expanduser ( '<STR_LIT>' ) <EOL> if x . startswith ( prefix ) : <EOL> x = '<STR_LIT>' + x [ len ( prefix ) : ] <EOL> return x <EOL> else : <EOL> strip = lambda x : x <EOL> cwd = os . path . abspath ( os . getcwd ( ) ) <EOL> for item in sys . path : <EOL> path = os . path . join ( cwd , item or os . path . curdir ) <EOL> yield strip ( os . path . normpath ( path ) ) , not os . path . isdir ( path ) , path != item <EOL> def render_testapp ( req ) : <EOL> try : <EOL> import pkg_resources <EOL> except ImportError : <EOL> eggs = ( ) <EOL> else : <EOL> eggs = list ( pkg_resources . working_set ) <EOL> eggs . sort ( lambda a , b : cmp ( a . project_name . lower ( ) , <EOL> b . project_name . lower ( ) ) ) <EOL> python_eggs = [ ] <EOL> for egg in eggs : <EOL> try : <EOL> version = egg . version <EOL> except ( ValueError , AttributeError ) : <EOL> version = '<STR_LIT>' <EOL> python_eggs . append ( '<STR_LIT>' % ( <EOL> escape ( egg . project_name ) , <EOL> escape ( version ) <EOL> ) ) <EOL> wsgi_env = [ ] <EOL> sorted_environ = req . environ . items ( ) <EOL> sorted_environ . sort ( key = lambda x : repr ( x [ <NUM_LIT:0> ] ) . lower ( ) ) <EOL> for key , value in sorted_environ : <EOL> wsgi_env . append ( '<STR_LIT>' % ( <EOL> escape ( str ( key ) ) , <EOL> '<STR_LIT:U+0020>' . join ( wrap ( escape ( repr ( value ) ) ) ) <EOL> ) ) <EOL> sys_path = [ ] <EOL> for item , virtual , expanded in iter_sys_path ( ) : <EOL> class_ = [ ] <EOL> if virtual : <EOL> class_ . append ( '<STR_LIT>' ) <EOL> if expanded : <EOL> class_ . append ( '<STR_LIT>' ) <EOL> sys_path . append ( '<STR_LIT>' % ( <EOL> class_ and '<STR_LIT>' % '<STR_LIT:U+0020>' . join ( class_ ) or '<STR_LIT>' , <EOL> escape ( item ) <EOL> ) ) <EOL> return TEMPLATE % { <EOL> '<STR_LIT>' : '<STR_LIT>' . join ( escape ( sys . version ) . splitlines ( ) ) , <EOL> '<STR_LIT>' : escape ( sys . platform ) , <EOL> '<STR_LIT>' : escape ( os . name ) , <EOL> '<STR_LIT>' : sys . api_version , <EOL> '<STR_LIT>' : sys . byteorder , <EOL> '<STR_LIT>' : werkzeug . __version__ , <EOL> '<STR_LIT>' : '<STR_LIT:\n>' . join ( python_eggs ) , <EOL> '<STR_LIT>' : '<STR_LIT:\n>' . join ( wsgi_env ) , <EOL> '<STR_LIT>' : '<STR_LIT:\n>' . join ( sys_path ) <EOL> } <EOL> def test_app ( environ , start_response ) : <EOL> """<STR_LIT>""" <EOL> req = Request ( environ , populate_request = False ) <EOL> if req . args . get ( '<STR_LIT>' ) == '<STR_LIT>' : <EOL> response = logo <EOL> else : <EOL> response = Response ( render_testapp ( req ) , mimetype = '<STR_LIT>' ) <EOL> return response ( environ , start_response ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> from werkzeug . serving import run_simple <EOL> run_simple ( '<STR_LIT:localhost>' , <NUM_LIT> , test_app , use_reloader = True ) </s>
