<s> from twisted . web import server <EOL> from . base import BaseResource <EOL> class DataResource ( BaseResource ) : <EOL> def __init__ ( self , dataserver ) : <EOL> self . dataserver = dataserver <EOL> BaseResource . __init__ ( self ) <EOL> def render ( self , request ) : <EOL> request . setHeader ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if "<STR_LIT>" in request . args : <EOL> get_deferreds = [ ] <EOL> for uuid in request . args [ "<STR_LIT>" ] : <EOL> get_deferreds . append ( self . dataserver . getData ( uuid ) ) <EOL> d = DeferredList ( get_deferreds , consumeErrors = True ) <EOL> d . addCallback ( self . _getCallback , request . args [ "<STR_LIT>" ] ) <EOL> d . addCallback ( self . _successResponse ) <EOL> d . addErrback ( self . _errorResponse ) <EOL> d . addCallback ( self . _immediateResponse , request ) <EOL> return server . NOT_DONE_YET <EOL> return self . _errorResponse ( Failure ( exc_value = Exception ( "<STR_LIT>" ) ) ) <EOL> def _getCallback ( self , data , uuids ) : <EOL> response = { } <EOL> for i in range ( <NUM_LIT:0> , len ( uuids ) ) : <EOL> if data [ i ] [ <NUM_LIT:0> ] == True : <EOL> response [ uuids [ i ] ] = data [ i ] [ <NUM_LIT:1> ] <EOL> else : <EOL> response [ uuids [ i ] ] = { "<STR_LIT:error>" : str ( data [ i ] [ <NUM_LIT:1> ] . value ) } <EOL> return response </s>
