#NEWLINE# @ gen . coroutine #NEWLINE# def check_image( self , kw ) : #NEWLINE# #INDENT# if ( self . context . config . MAX_ID_LENGTH > 0 ) : #NEWLINE# #INDENT# exists = ( yield gen . maybe_future ( self . context . modules . storage . exists ( kw [ 'image' ] [ : self . context . config . MAX_ID_LENGTH ] ) ) ) #NEWLINE# if exists : #NEWLINE# #INDENT# kw [ 'image' ] = kw [ 'image' ] [ : self . context . config . MAX_ID_LENGTH ] #NEWLINE# #UNINDENT# #UNINDENT# url = self . request . path #NEWLINE# kw [ 'image' ] = quote ( kw [ 'image' ] . encode ( 'utf-8' ) ) #NEWLINE# if ( not self . validate ( kw [ 'image' ] ) ) : #NEWLINE# #INDENT# self . _error ( 400 , 'No original image was specified in the given URL' ) #NEWLINE# return #NEWLINE# #UNINDENT# kw [ 'request' ] = self . request #NEWLINE# self . context . request = RequestParameters ( ** kw ) #NEWLINE# has_none = ( ( not self . context . request . unsafe ) and ( not self . context . request . hash ) ) #NEWLINE# has_both = ( self . context . request . unsafe and self . context . request . hash ) #NEWLINE# if ( has_none or has_both ) : #NEWLINE# #INDENT# self . _error ( 400 , ( 'URL does not have hash or unsafe, or has both: %s' % url ) ) #NEWLINE# return #NEWLINE# #UNINDENT# if ( self . context . request . unsafe and ( not self . context . config . ALLOW_UNSAFE_URL ) ) : #NEWLINE# #INDENT# self . _error ( 400 , ( 'URL has unsafe but unsafe is not allowed by the config: %s' % url ) ) #NEWLINE# return #NEWLINE# #UNINDENT# if self . context . config . USE_BLACKLIST : #NEWLINE# #INDENT# blacklist = ( yield self . get_blacklist_contents ( ) ) #NEWLINE# if ( self . context . request . image_url in blacklist ) : #NEWLINE# #INDENT# self . _error ( 400 , ( 'Source image url has been blacklisted: %s' % self . context . request . image_url ) ) #NEWLINE# return #NEWLINE# #UNINDENT# #UNINDENT# url_signature = self . context . request . hash #NEWLINE# if url_signature : #NEWLINE# #INDENT# signer = self . context . modules . url_signer ( self . context . server . security_key ) #NEWLINE# url_to_validate = url . replace ( ( '/%s/' % self . context . request . hash ) , '' ) . replace ( ( '/%s/' % quote ( self . context . request . hash ) ) , '' ) #NEWLINE# valid = signer . validate ( unquote ( url_signature ) , url_to_validate ) #NEWLINE# if ( ( not valid ) and self . context . config . STORES_CRYPTO_KEY_FOR_EACH_IMAGE ) : #NEWLINE# #INDENT# security_key = ( yield gen . maybe_future ( self . context . modules . storage . get_crypto ( self . context . request . image_url ) ) ) #NEWLINE# if ( security_key is not None ) : #NEWLINE# #INDENT# signer = self . context . modules . url_signer ( security_key ) #NEWLINE# valid = signer . validate ( url_signature , url_to_validate ) #NEWLINE# #UNINDENT# #UNINDENT# if ( not valid ) : #NEWLINE# #INDENT# self . _error ( 400 , ( 'Malformed URL: %s' % url ) ) #NEWLINE# return #NEWLINE# #UNINDENT# #UNINDENT# self . execute_image_operations ( )