<s> from flask import request <EOL> import re <EOL> __mime_types__ = [ '<STR_LIT:application/json>' , '<STR_LIT>' ] <EOL> __default_names__ = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> class Fixture ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , data , name , app_name , request_path , <EOL> request_method , is_response = True ) : <EOL> self . data = data <EOL> self . name = name <EOL> self . app_name = app_name <EOL> self . request_path = request_path <EOL> self . request_method = request_method <EOL> self . is_response = is_response <EOL> @ property <EOL> def payload ( self ) : <EOL> return self . data . decode ( '<STR_LIT:utf-8>' ) <EOL> @ property <EOL> def type ( self ) : <EOL> return '<STR_LIT>' <EOL> @ classmethod <EOL> def from_request ( cls , request , app , name ) : <EOL> if not Fixture . is_supported ( request . mimetype ) : <EOL> raise TypeError <EOL> fixture = cls ( request . data , name , app . name , request . path , <EOL> request . method , is_response = False ) <EOL> return fixture <EOL> @ classmethod <EOL> def from_response ( cls , response , app , name ) : <EOL> if not Fixture . is_supported ( response . mimetype ) : <EOL> raise TypeError <EOL> fixture = cls ( response . get_data ( ) , name , app . name , request . path , <EOL> request . method ) <EOL> return fixture <EOL> @ staticmethod <EOL> def is_supported ( mime_type ) : <EOL> for supported_mime_type in __mime_types__ : <EOL> if re . match ( supported_mime_type , mime_type ) : <EOL> return True <EOL> return False </s>
