<s> """<STR_LIT>""" <EOL> from urllib import unquote <EOL> from urlparse import urlparse <EOL> from django . core . urlresolvers import resolve , Resolver404 <EOL> from django . http import HttpResponseNotFound <EOL> from unfriendly import settings <EOL> from unfriendly . utils import CheckSumError , decrypt , InvalidKeyError <EOL> def deobfuscate ( request , key , juice = None ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> url = decrypt ( str ( key ) , <EOL> settings . UNFRIENDLY_SECRET , <EOL> settings . UNFRIENDLY_IV , <EOL> checksum = settings . UNFRIENDLY_ENFORCE_CHECKSUM ) <EOL> except ( CheckSumError , InvalidKeyError ) : <EOL> return HttpResponseNotFound ( ) <EOL> url_parts = urlparse ( unquote ( url ) ) <EOL> path = url_parts . path <EOL> query = url_parts . query <EOL> try : <EOL> view , args , kwargs = resolve ( path ) <EOL> except Resolver404 : <EOL> return HttpResponseNotFound ( ) <EOL> environ = request . environ . copy ( ) <EOL> environ [ '<STR_LIT>' ] = path [ len ( environ [ '<STR_LIT>' ] ) : ] <EOL> environ [ '<STR_LIT>' ] = query <EOL> patched_request = request . __class__ ( environ ) <EOL> missing_items = set ( dir ( request ) ) - set ( dir ( patched_request ) ) <EOL> while missing_items : <EOL> missing_item = missing_items . pop ( ) <EOL> patched_request . __setattr__ ( missing_item , <EOL> request . __getattribute__ ( missing_item ) ) <EOL> patched_request . META [ '<STR_LIT>' ] = True <EOL> response = view ( patched_request , * args , ** kwargs ) <EOL> if juice and not response . has_header ( '<STR_LIT>' ) : <EOL> response [ '<STR_LIT>' ] = '<STR_LIT>' % juice <EOL> return response </s>
