
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


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'))

        self.context.modules.storage.remove(imageurl)
        self.context.modules.result_storage.remove(imageurl)
        self.set_status(204)

    @gen.coroutine
    def execute_image_operations(self):
        pass

Purge should always be attempted
Purge should always be attempted

Since the original is very volatile (in memcache), its absence shouldn't
prevent the thumbnails from being purged.

Furthermore, knowing whether the item was there beforehand isn't
very useful.

Change-Id: I014df0bce00983031b9dec9d48126c25b1688a77

  
  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.storage.remove(imageurl)
-             self.context.modules.result_storage.remove(imageurl)
+         self.context.modules.result_storage.remove(imageurl)
-             self.set_status(204)
+         self.set_status(204)
-         else:
-             self._error(404, 'Image not found at the given URL')
  
      @gen.coroutine
      def execute_image_operations(self):
          pass
  
Purge should always be attempted
## Code Before:

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

## Instruction:
Purge should always be attempted
## Code After:

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'))

        self.context.modules.storage.remove(imageurl)
        self.context.modules.result_storage.remove(imageurl)
        self.set_status(204)

    @gen.coroutine
    def execute_image_operations(self):
        pass
