<s> """<STR_LIT>""" <EOL> from django . core . serializers . json import DjangoJSONEncoder <EOL> from django . http import HttpRequest <EOL> import datetime <EOL> import json <EOL> import uuid <EOL> class MockRequest ( HttpRequest ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , user = None , ip_address = None ) : <EOL> from django . contrib . auth . models import AnonymousUser <EOL> self . user = user or AnonymousUser ( ) <EOL> self . GET = { } <EOL> self . POST = { } <EOL> self . COOKIES = { } <EOL> self . META = { <EOL> '<STR_LIT>' : ip_address , <EOL> } <EOL> class BetterJSONEncoder ( DjangoJSONEncoder ) : <EOL> def default ( self , obj ) : <EOL> if isinstance ( obj , uuid . UUID ) : <EOL> return obj . hex <EOL> elif isinstance ( obj , datetime . datetime ) : <EOL> return obj . strftime ( '<STR_LIT>' ) <EOL> elif isinstance ( obj , ( set , frozenset ) ) : <EOL> return list ( obj ) <EOL> return super ( BetterJSONEncoder , self ) . default ( obj ) <EOL> def dumps ( value , ** kwargs ) : <EOL> return json . dumps ( value , cls = BetterJSONEncoder , ** kwargs ) </s>
