# -*- coding: utf-8 -*-

# Copyright (c) 2015, thumbor-community, Wikimedia Foundation
# Use of this source code is governed by the MIT license that can be
# found in the LICENSE file.

import urllib

from tornado import gen

from thumbor.handlers.imaging import ImagingHandler


class UrlPurgerHandler(ImagingHandler):
    @classmethod
    def regex(cls):
        '''
        :return: The regex used for routing.
        :rtype: string
        '''
        return r'/purge/?(?P<image>.+)?'

    @gen.coroutine
    def get(self, **kw):
        imageurl = urllib.quote(kw['image'].encode('utf8'))

        exists = yield gen.maybe_future(
            self.context.modules.storage.exists(imageurl)
        )

        if exists:
            self.context.modules.storage.remove(imageurl)
            self.context.modules.result_storage.remove(imageurl)
            self.set_status(204)
        else:
            self._error(404, 'Image not found at the given URL')

    @gen.coroutine
    def execute_image_operations(self):
        pass

@@ -593,141 +593,8 @@
 ))%0A%0A
-        exists = yield gen.maybe_future(%0A            self.context.modules.storage.exists(imageurl)%0A        )%0A%0A        if exists:%0A    
     
@@ -635,36 +635,32 @@
 emove(imageurl)%0A
-    
         self.con
@@ -708,28 +708,24 @@
 rl)%0A        
- 
-   
 self.set_sta
@@ -736,87 +736,8 @@
 204)
-%0A        else:%0A            self._error(404, 'Image not found at the given URL')
 %0A%0A  

Purge should always be attempted