#NEWLINE# def from_body( self , body ) : #NEWLINE# #INDENT# "Try to guess the appropriate response based on the body content.\n        This method is a bit magic and could be improved in the future, but\n        it's not meant to be used except for special cases where response types\n        cannot be guess using more straightforward methods." #NEWLINE# chunk = self [ : 5000 ] #NEWLINE# chunk = to_bytes ( chunk ) #NEWLINE# if ( not binary_is_text ( chunk ) ) : #NEWLINE# #INDENT# return self . from_mimetype ( 'application/octet-stream' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( b'<html>' in chunk . lower ( ) ) : #NEWLINE# #INDENT# return self . from_mimetype ( 'text/html' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( b'<?xml' in chunk . lower ( ) ) : #NEWLINE# #INDENT# return self . from_mimetype ( 'text/xml' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return self . from_mimetype ( 'text' )