<s> '''<STR_LIT>''' <EOL> from corepost . web import RESTResource , route <EOL> from corepost . enums import Http , MediaType , HttpHeader <EOL> from twisted . internet import defer <EOL> from xml . etree import ElementTree <EOL> import json , yaml <EOL> class HomeApp ( ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> self . issue1 = "<STR_LIT>" <EOL> @ route ( "<STR_LIT:/>" , Http . GET ) <EOL> @ defer . inlineCallbacks <EOL> def root ( self , request , ** kwargs ) : <EOL> yield <NUM_LIT:1> <EOL> request . write ( "<STR_LIT:%s>" % kwargs ) <EOL> request . finish ( ) <EOL> @ route ( "<STR_LIT>" , Http . GET ) <EOL> def test ( self , request , ** kwargs ) : <EOL> return "<STR_LIT:%s>" % kwargs <EOL> @ route ( "<STR_LIT>" , Http . GET ) <EOL> def test_get_resources ( self , request , numericid , stringid , ** kwargs ) : <EOL> return "<STR_LIT>" % ( numericid , stringid ) <EOL> @ route ( "<STR_LIT>" , ( Http . POST , Http . PUT ) ) <EOL> def test_post ( self , request , ** kwargs ) : <EOL> return "<STR_LIT:%s>" % kwargs <EOL> @ route ( "<STR_LIT>" , ( Http . POST , Http . PUT ) ) <EOL> def test_put ( self , request , ** kwargs ) : <EOL> return "<STR_LIT:%s>" % kwargs <EOL> @ route ( "<STR_LIT>" , ( Http . POST , Http . PUT ) ) <EOL> def test_postput ( self , request , ** kwargs ) : <EOL> return "<STR_LIT:%s>" % kwargs <EOL> @ route ( "<STR_LIT>" , Http . DELETE ) <EOL> def test_delete ( self , request , ** kwargs ) : <EOL> return "<STR_LIT:%s>" % kwargs <EOL> @ route ( "<STR_LIT>" , ( Http . POST , Http . PUT ) ) <EOL> def test_json ( self , request , ** kwargs ) : <EOL> return "<STR_LIT:%s>" % json . dumps ( request . json ) <EOL> @ route ( "<STR_LIT>" , ( Http . POST , Http . PUT ) ) <EOL> def test_xml ( self , request , ** kwargs ) : <EOL> return "<STR_LIT:%s>" % ElementTree . tostring ( request . xml ) <EOL> @ route ( "<STR_LIT>" , ( Http . POST , Http . PUT ) ) <EOL> def test_yaml ( self , request , ** kwargs ) : <EOL> return "<STR_LIT:%s>" % yaml . dump ( request . yaml , indent = <NUM_LIT:4> , width = <NUM_LIT> , default_flow_style = False ) <EOL> @ route ( "<STR_LIT>" , ( Http . POST , Http . PUT ) , MediaType . APPLICATION_JSON ) <EOL> def test_content_app_json ( self , request , ** kwargs ) : <EOL> return request . received_headers [ HttpHeader . CONTENT_TYPE ] <EOL> @ route ( "<STR_LIT>" , ( Http . POST , Http . PUT ) , ( MediaType . TEXT_XML , MediaType . APPLICATION_XML ) ) <EOL> def test_content_xml ( self , request , ** kwargs ) : <EOL> return request . received_headers [ HttpHeader . CONTENT_TYPE ] <EOL> @ route ( "<STR_LIT>" , ( Http . POST , Http . PUT ) , MediaType . TEXT_YAML ) <EOL> def test_content_yaml ( self , request , ** kwargs ) : <EOL> return request . received_headers [ HttpHeader . CONTENT_TYPE ] <EOL> @ route ( "<STR_LIT>" , ( Http . POST , Http . PUT ) ) <EOL> def test_content_catch_all ( self , request , ** kwargs ) : <EOL> return MediaType . WILDCARD <EOL> @ route ( "<STR_LIT>" ) <EOL> def test_return_content_by_accepts ( self , request , ** kwargs ) : <EOL> val = [ { "<STR_LIT>" : "<STR_LIT>" } , { "<STR_LIT>" : "<STR_LIT>" } ] <EOL> return val <EOL> @ route ( "<STR_LIT>" ) <EOL> @ defer . inlineCallbacks <EOL> def test_return_content_by_accept_deferred ( self , request , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> val = yield [ { "<STR_LIT>" : "<STR_LIT>" } , { "<STR_LIT>" : "<STR_LIT>" } ] <EOL> defer . returnValue ( val ) <EOL> @ route ( "<STR_LIT>" ) <EOL> def test_return_class_content_by_accepts ( self , request , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> class TestReturn : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . __t1 = '<STR_LIT>' <EOL> t1 = TestReturn ( ) <EOL> t1 . test1 = '<STR_LIT>' <EOL> t2 = TestReturn ( ) <EOL> t2 . test2 = "<STR_LIT>" <EOL> return ( t1 , t2 ) <EOL> @ route ( "<STR_LIT>" ) <EOL> def test_issue_1 ( self , request , ** kwargs ) : <EOL> return self . issue1 <EOL> @ route ( "<STR_LIT>" , Http . HEAD ) <EOL> def test_head_http ( self , request , ** kwargs ) : <EOL> return "<STR_LIT>" <EOL> @ route ( "<STR_LIT>" , Http . OPTIONS ) <EOL> def test_options_http ( self , request , ** kwargs ) : <EOL> return "<STR_LIT>" <EOL> @ route ( "<STR_LIT>" , Http . PATCH ) <EOL> def test_patch_http ( self , request , ** kwargs ) : <EOL> return "<STR_LIT>" % kwargs <EOL> def run_app_home ( ) : <EOL> app = RESTResource ( ( HomeApp ( ) , ) ) <EOL> app . run ( ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> run_app_home ( ) </s>
