<s> from __future__ import absolute_import , unicode_literals , division <EOL> import sys <EOL> import json <EOL> import armet <EOL> from armet import resources , attributes , exceptions <EOL> models = sys . modules [ '<STR_LIT>' ] <EOL> __all__ = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> class SimpleResource ( resources . Resource ) : <EOL> def get ( self , request , response ) : <EOL> pass <EOL> class SimpleTrailingResource ( resources . Resource ) : <EOL> class Meta : <EOL> trailing_slash = False <EOL> def get ( self , request , response ) : <EOL> pass <EOL> class StreamingResource ( resources . Resource ) : <EOL> def get ( self , request , response ) : <EOL> response . status = <NUM_LIT> <EOL> response [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> yield '<STR_LIT>' <EOL> response . write ( '<STR_LIT>' ) <EOL> response . flush ( ) <EOL> response . write ( '<STR_LIT>' ) <EOL> yield <EOL> yield '<STR_LIT>' <EOL> response . write ( '<STR_LIT>' ) <EOL> yield '<STR_LIT>' <EOL> def spawn ( connectors , function ) : <EOL> import gevent <EOL> gevent . spawn ( function ) <EOL> class AsyncResource ( resources . Resource ) : <EOL> class Meta : <EOL> asynchronous = True <EOL> def get ( self , request , response ) : <EOL> def writer ( ) : <EOL> response . status = <NUM_LIT> <EOL> response [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> response . write ( '<STR_LIT>' ) <EOL> response . close ( ) <EOL> spawn ( self . meta . connectors , writer ) <EOL> class AsyncStreamResource ( resources . Resource ) : <EOL> class Meta : <EOL> asynchronous = True <EOL> def get ( self , request , response ) : <EOL> def streamer ( ) : <EOL> response . status = <NUM_LIT> <EOL> response [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> response . write ( '<STR_LIT>' ) <EOL> response . flush ( ) <EOL> response . write ( '<STR_LIT>' ) <EOL> response . flush ( ) <EOL> response . write ( '<STR_LIT>' ) <EOL> response . write ( '<STR_LIT>' ) <EOL> response . flush ( ) <EOL> response . write ( '<STR_LIT>' ) <EOL> response . write ( '<STR_LIT>' ) <EOL> response . close ( ) <EOL> spawn ( self . meta . connectors , streamer ) <EOL> @ armet . resource ( methods = '<STR_LIT:GET>' ) <EOL> def lightweight ( request , response ) : <EOL> response . status = <NUM_LIT> <EOL> response [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> response . write ( '<STR_LIT>' ) <EOL> @ armet . resource ( methods = '<STR_LIT:POST>' ) <EOL> def lightweight ( request , response ) : <EOL> response . status = <NUM_LIT> <EOL> response [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> response . write ( '<STR_LIT>' ) <EOL> @ armet . resource ( methods = '<STR_LIT:GET>' ) <EOL> def lightweight_streaming ( request , response ) : <EOL> response . status = <NUM_LIT> <EOL> response [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> yield '<STR_LIT>' <EOL> response . write ( '<STR_LIT>' ) <EOL> response . flush ( ) <EOL> response . write ( '<STR_LIT>' ) <EOL> yield <EOL> yield '<STR_LIT>' <EOL> response . write ( '<STR_LIT>' ) <EOL> yield '<STR_LIT>' <EOL> @ armet . asynchronous <EOL> @ armet . resource ( methods = '<STR_LIT:GET>' ) <EOL> def lightweight_async ( request , response ) : <EOL> def writer ( ) : <EOL> response . status = <NUM_LIT> <EOL> response [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> response . write ( '<STR_LIT>' ) <EOL> response . close ( ) <EOL> spawn ( lightweight_async . meta . connectors , writer ) <EOL> class PollResource ( resources . ModelResource ) : <EOL> class Meta : <EOL> model = models . Poll <EOL> slug = '<STR_LIT:id>' <EOL> id = attributes . IntegerAttribute ( '<STR_LIT:id>' ) <EOL> question = attributes . TextAttribute ( '<STR_LIT>' ) <EOL> available = attributes . BooleanAttribute ( '<STR_LIT>' ) <EOL> class LeftResource ( resources . Resource ) : <EOL> class Meta : <EOL> http_allowed_methods = ( '<STR_LIT>' , '<STR_LIT:GET>' , '<STR_LIT>' , ) <EOL> http_allowed_origins = ( '<STR_LIT>' , ) <EOL> http_allowed_headers = ( '<STR_LIT:Content-Type>' , '<STR_LIT>' , '<STR_LIT>' , ) <EOL> def get ( self ) : <EOL> pass <EOL> class RightResource ( resources . Resource ) : <EOL> class Meta : <EOL> http_allowed_methods = ( '<STR_LIT>' , '<STR_LIT:GET>' , '<STR_LIT>' , '<STR_LIT>' , ) <EOL> http_allowed_origins = ( '<STR_LIT:*>' , ) <EOL> http_allowed_headers = ( '<STR_LIT:Content-Type>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> def get ( self ) : <EOL> pass <EOL> @ armet . resource ( methods = '<STR_LIT:POST>' ) <EOL> def echo ( request , response ) : <EOL> data = request . read ( deserialize = True ) <EOL> response . write ( data , serialize = True ) <EOL> @ armet . resource ( methods = '<STR_LIT:GET>' ) <EOL> def cookie ( request , response ) : <EOL> response [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> response . write ( request . cookies [ '<STR_LIT>' ] . value ) <EOL> class DirectResource ( resources . Resource ) : <EOL> def route ( self , request , response ) : <EOL> return super ( DirectResource , self ) . route ( request , response ) <EOL> def get ( self , request , response ) : <EOL> response . write ( b'<STR_LIT>' ) <EOL> class ModelDirectResource ( resources . ModelResource ) : <EOL> class Meta : <EOL> model = models . Poll <EOL> id = attributes . IntegerAttribute ( '<STR_LIT:id>' ) <EOL> question = attributes . TextAttribute ( '<STR_LIT>' ) <EOL> def route ( self , request , response ) : <EOL> return super ( ModelDirectResource , self ) . route ( request , response ) <EOL> class IndirectResource ( DirectResource ) : <EOL> def route ( self , request , response ) : <EOL> return super ( IndirectResource , self ) . route ( request , response ) <EOL> def get ( self , request , response ) : <EOL> response . write ( b'<STR_LIT>' ) <EOL> class ModelIndirectResource ( ModelDirectResource ) : <EOL> class Meta : <EOL> model = models . Poll <EOL> def read ( self ) : <EOL> return super ( ModelIndirectResource , self ) . read ( ) <EOL> class TwiceIndirectResource ( IndirectResource ) : <EOL> def route ( self , request , response ) : <EOL> return super ( TwiceIndirectResource , self ) . route ( request , response ) <EOL> def get ( self , request , response ) : <EOL> response . write ( b'<STR_LIT>' ) <EOL> class ModelTwiceIndirectResource ( ModelIndirectResource ) : <EOL> class Meta : <EOL> model = models . Poll <EOL> def read ( self ) : <EOL> return super ( ModelTwiceIndirectResource , self ) . read ( ) <EOL> class ThriceIndirectResource ( IndirectResource ) : <EOL> def route ( self , request , response ) : <EOL> return super ( ThriceIndirectResource , self ) . route ( request , response ) <EOL> def get ( self , request , response ) : <EOL> response . write ( b'<STR_LIT>' ) <EOL> class ModelThriceIndirectResource ( ModelIndirectResource ) : <EOL> class Meta : <EOL> model = models . Poll <EOL> def read ( self ) : <EOL> return super ( ModelThriceIndirectResource , self ) . read ( ) <EOL> class ExtraStuff ( object ) : <EOL> def dispatch ( self , * args ) : <EOL> self . content = b'<STR_LIT>' <EOL> return super ( ExtraStuff , self ) . dispatch ( * args ) <EOL> class MixinResource ( ExtraStuff , IndirectResource ) : <EOL> content = b'<STR_LIT>' <EOL> def route ( self , request , response ) : <EOL> return super ( MixinResource , self ) . route ( request , response ) <EOL> def get ( self , request , response ) : <EOL> response . write ( self . content ) <EOL> class PollExcludeResource ( PollResource ) : <EOL> question = attributes . TextAttribute ( '<STR_LIT>' , include = False ) <EOL> class PollUnreadResource ( PollResource ) : <EOL> question = attributes . TextAttribute ( '<STR_LIT>' , read = False ) <EOL> class PollUnwriteResource ( PollResource ) : <EOL> question = attributes . TextAttribute ( '<STR_LIT>' , write = False ) <EOL> class PollNoNullResource ( PollResource ) : <EOL> question = attributes . TextAttribute ( '<STR_LIT>' , null = False ) <EOL> class PollRequiredResource ( PollResource ) : <EOL> question = attributes . TextAttribute ( '<STR_LIT>' , required = True ) <EOL> class PollNamedResource ( PollResource ) : <EOL> question = attributes . TextAttribute ( '<STR_LIT>' , name = '<STR_LIT>' ) <EOL> class PollValidResource ( PollResource ) : <EOL> votes = attributes . IntegerAttribute ( '<STR_LIT>' ) <EOL> def clean_votes ( self , value ) : <EOL> assert value > <NUM_LIT:0> , '<STR_LIT>' <EOL> assert value < <NUM_LIT> , '<STR_LIT>' <EOL> return value <EOL> def clean_question ( self , value ) : <EOL> errors = [ ] <EOL> if len ( value ) <= <NUM_LIT:15> : <EOL> errors . append ( '<STR_LIT>' ) <EOL> if value . find ( '<STR_LIT:?>' ) == - <NUM_LIT:1> : <EOL> errors . append ( '<STR_LIT>' ) <EOL> if errors : <EOL> raise exceptions . ValidationError ( * errors ) <EOL> return value <EOL> class DirectConnectorResource ( resources . Resource ) : <EOL> @ classmethod <EOL> def view ( cls , * args , ** kwargs ) : <EOL> cls . status = <NUM_LIT> <EOL> return super ( DirectConnectorResource , cls ) . view ( * args , ** kwargs ) <EOL> def get ( self , request , response ) : <EOL> response . status = self . status <EOL> response . write ( b'<STR_LIT>' ) <EOL> class IndirectConnectorResource ( DirectConnectorResource ) : <EOL> pass <EOL> class TwiceIndirectConnectorResource ( IndirectConnectorResource ) : <EOL> pass <EOL> class ThriceIndirectConnectorResource ( TwiceIndirectConnectorResource ) : <EOL> pass <EOL> class DirectModelConnectorResource ( resources . ModelResource ) : <EOL> class Meta : <EOL> model = models . Poll <EOL> id = attributes . IntegerAttribute ( '<STR_LIT:id>' ) <EOL> def route ( self , request , response ) : <EOL> response . status = <NUM_LIT> <EOL> return super ( DirectModelConnectorResource , self ) . route ( <EOL> request , response ) <EOL> def get ( self , request , response ) : <EOL> response . write ( json . dumps ( self . read ( ) ) . encode ( '<STR_LIT:utf8>' ) ) <EOL> def read ( self ) : <EOL> return [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> class IndirectModelConnectorResource ( DirectModelConnectorResource ) : <EOL> pass <EOL> class TwiceIndirectModelConnectorResource ( IndirectModelConnectorResource ) : <EOL> pass <EOL> class ThriceIndirectModelConnectorResource ( <EOL> TwiceIndirectModelConnectorResource ) : <EOL> pass <EOL> class DirectModelConnectorMixin ( object ) : <EOL> def destroy ( self ) : <EOL> self . response . status = <NUM_LIT> <EOL> return None <EOL> class DirectModelConnectorMixinResource ( <EOL> DirectModelConnectorMixin , resources . ModelResource ) : <EOL> class Meta : <EOL> model = models . Poll <EOL> id = attributes . IntegerAttribute ( '<STR_LIT:id>' ) <EOL> def delete ( self , request , response ) : <EOL> self . response . status = <NUM_LIT> <EOL> self . destroy ( ) <EOL> class IndirectModelConnectorMixinResource ( DirectModelConnectorMixinResource ) : <EOL> pass <EOL> class TwiceIndirectModelConnectorMixinResource ( <EOL> IndirectModelConnectorMixinResource ) : <EOL> pass <EOL> class ThriceIndirectModelConnectorMixinResource ( <EOL> TwiceIndirectModelConnectorMixinResource ) : <EOL> pass </s>
