#NEWLINE# def _cast( self , v ) : #NEWLINE# #INDENT# ' Returns the given value as a string (used to cast handler functions).\n            If the value is a dictionary, returns a JSON-string.\n            If the value is a generator, starts a stream.\n            If the value is an iterable, joins the values with a space.\n        ' #NEWLINE# if isinstance ( v , basestring ) : #NEWLINE# #INDENT# return v #NEWLINE# #UNINDENT# if isinstance ( v , cp . lib . file_generator ) : #NEWLINE# #INDENT# return v #NEWLINE# #UNINDENT# if isinstance ( v , dict ) : #NEWLINE# #INDENT# cp . response . headers [ 'Content-Type' ] = 'application/json; charset=utf-8' #NEWLINE# cp . response . headers [ 'Access-Control-Allow-Origin' ] = '*' #NEWLINE# return json . dumps ( v ) #NEWLINE# #UNINDENT# if isinstance ( v , types . GeneratorType ) : #NEWLINE# #INDENT# cp . response . stream = True #NEWLINE# return iter ( ( self . _cast ( v ) for v in v ) ) #NEWLINE# #UNINDENT# if isinstance ( v , ( list , tuple , set ) ) : #NEWLINE# #INDENT# return ' ' . join ( ( self . _cast ( v ) for v in v ) ) #NEWLINE# #UNINDENT# if isinstance ( v , HTTPError ) : #NEWLINE# #INDENT# raise cp . HTTPError ( v . status , message = v . message ) #NEWLINE# #UNINDENT# if ( v is None ) : #NEWLINE# #INDENT# return '' #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# return unicode ( v ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# return encode_entities ( repr ( v ) )