#NEWLINE# def create_app( ) : #NEWLINE# #INDENT# app = Flask ( 'easymode' ) #NEWLINE# app . config [ 'TESTING' ] = True #NEWLINE# app . config [ 'SECRET_KEY' ] = '123454fdsafdsfdsfdsfds' #NEWLINE# @ app . route ( '/' ) #NEWLINE# def index( ) : #NEWLINE# #INDENT# return 'I am the index page.' #NEWLINE# #UNINDENT# @ app . route ( '/xhr' ) #NEWLINE# @ xhr_api ( ) #NEWLINE# def xhr_endpoint( ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# g . xhr . data [ 'test' ] = 'monkey' #NEWLINE# g . xhr . data [ 'walrus' ] = 'punch' #NEWLINE# #UNINDENT# except AttributeError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# flash ( 'This is a test message.' ) #NEWLINE# flash ( 'This is a warning.' , 'warning' ) #NEWLINE# flash ( 'This is an error' , 'error' ) #NEWLINE# flash ( 'This is just some info' , 'info' ) #NEWLINE# flash ( 'This is another warning' , 'warning' ) #NEWLINE# #UNINDENT# @ app . route ( '/xhr-failure' ) #NEWLINE# @ xhr_api ( ) #NEWLINE# def xhr_failure( ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# g . xhr . data [ 'test' ] = 'monkey' #NEWLINE# #UNINDENT# except AttributeError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# raise XHRError ( 'Disaster everywhere.' ) #NEWLINE# #UNINDENT# @ app . route ( '/xhr-failure-with-code' ) #NEWLINE# @ xhr_api ( ) #NEWLINE# def xhr_failure_with_code( ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# g . xhr . data [ 'test' ] = 'monkey' #NEWLINE# #UNINDENT# except AttributeError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# raise XHRError ( 'Disaster befalls the city' , status_code = 500 ) #NEWLINE# #UNINDENT# @ app . route ( '/xhr-that-returns-something' ) #NEWLINE# @ xhr_api ( ) #NEWLINE# def xhr_that_returns_something( ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# g . xhr . data [ 'test' ] = 'monkey' #NEWLINE# #UNINDENT# except AttributeError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# return 'Here is some string that would never be returned if the XHR API were active.' #NEWLINE# #UNINDENT# @ app . route ( '/xhr-that-allows-regular-http' ) #NEWLINE# @ xhr_api ( allow_http = True ) #NEWLINE# def xhr_that_allows_regular_http( ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# g . xhr . data [ 'test' ] = 'monkey' #NEWLINE# #UNINDENT# except AttributeError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# flash ( 'A message in a bottle.' ) #NEWLINE# return 'Here is some regular return stuff' #NEWLINE# #UNINDENT# @ app . route ( '/inject/<injectable_class_slug_name>' ) #NEWLINE# @ inject ( 'injectable_class' ) #NEWLINE# def inject_test_class_slug_name( ) : #NEWLINE# #INDENT# return ( 'I have been injected with %s' % g . injectable_class . slug_name ) #NEWLINE# #UNINDENT# @ app . route ( '/inject-as-arg/<injectable_class_slug_name>' ) #NEWLINE# @ inject ( 'injectable_class' , as_args = True ) #NEWLINE# def inject_test_class_args( injectable_class ) : #NEWLINE# #INDENT# return ( 'I have been injected with %s' % injectable_class . slug_name ) #NEWLINE# #UNINDENT# @ app . route ( '/inject-non-injectable/<non_injectable_class_slug_name>' ) #NEWLINE# @ inject ( 'non_injectable_class' ) #NEWLINE# def inject_the_noninjectable( ) : #NEWLINE# #INDENT# return 'This will never happen because there will be an exception :(' #NEWLINE# #UNINDENT# @ app . route ( '/inject-skip-by-default' , defaults = { #NEWLINE# #INDENT# 'injectable_class_slug_name' : None , #NEWLINE# #UNINDENT# } ) #NEWLINE# @ app . route ( '/inject-skip-by-default/<injectable_class_slug_name>' ) #NEWLINE# @ inject ( 'injectable_class' , as_args = True ) #NEWLINE# def inject_skip_by_default( injectable_class ) : #NEWLINE# #INDENT# return injectable_class . slug_name #NEWLINE# #UNINDENT# @ app . route ( '/inject-list-denoting/<injectable_class_category_name>' ) #NEWLINE# @ inject ( 'injectable_class' , default = 'skip' , lists = 'denote' , as_args = True ) #NEWLINE# def inject_list_denoting( injectable_class_list ) : #NEWLINE# #INDENT# return str ( injectable_class_list ) #NEWLINE# #UNINDENT# return app