#NEWLINE# def check_upload_permissions( request , bucket , key ) : #NEWLINE# #INDENT# '\n    Check permissions on the given upload policy. Raises\n    rest_framework.exceptions.PermissionDenied in case\n    of error.\n\n    ' #NEWLINE# from django.core.exceptions import ImproperlyConfigured #NEWLINE# from rest_framework.exceptions import PermissionDenied #NEWLINE# if ( bucket != upload_bucket ( ) ) : #NEWLINE# #INDENT# raise PermissionDenied ( _ ( ( "Bucket should be '%s'" % upload_bucket ( ) ) ) ) #NEWLINE# #UNINDENT# upload_prefix = upload_prefix_for_request ( request ) #NEWLINE# if ( ( upload_prefix is None ) or ( len ( upload_prefix ) == 0 ) ) : #NEWLINE# #INDENT# raise ImproperlyConfigured ( _ ( 'Upload prefix must be non-zero-length and should be unique for each user' ) ) #NEWLINE# #UNINDENT# if ( not key . startswith ( ( upload_prefix + '/' ) ) ) : #NEWLINE# #INDENT# raise PermissionDenied ( _ ( ( "Key should start with '%s/'" % upload_prefix ) ) )