Пример #1
0
    def create_from_raw(cls, img_data, name=None, caption=None, size=None):

        # create the images.Image() object
        image = images.Image(img_data)

        # create the blob
        blob = create_blob_from_image(image)

        # need this for local. blob key, eventual consistency, issue.
        if utils.is_local():
            time.sleep(0.250)

        # get the blob key
        blob_key = files.blobstore.get_blob_key(blob)

        # get a rough size
        bytes_ = -1
        if isinstance(size, int) and size > 0:
            bytes_ = size

        # return the img instance
        return cls(
            blob_key=blob_key,
            url=images.get_serving_url(blob_key),
            width=image.width,
            height=image.height,
            format=cls.get_format_string(image.format),
        )
Пример #2
0
    def make_cropped_copy(self, crop_args, format=None, quality=85):
        cls = self.__class__
        image = self.image
        image.crop(*crop_args)

        # create the image
        new_image_data = image.execute_transforms(
            output_encoding=format or cls.get_format_from_string(self.format), quality=quality
        )

        # create the blob
        new_image = images.Image(new_image_data)
        blob = create_blob_from_image(new_image)
        blob_key = files.blobstore.get_blob_key(blob)
        # need this for local. blob key, eventual consistency, issue.
        if utils.is_local():
            time.sleep(1)

        return cls(
            blob_key=blob_key,
            url=images.get_serving_url(blob_key),
            width=new_image.width,
            height=new_image.height,
            format=cls.get_format_string(new_image.format),
        )
Пример #3
0
 def log_exception(self, ex):
   lines = ''.join(traceback.format_exception(*sys.exc_info()))
   if isinstance(ex, urlfetch.DownloadError) or \
     isinstance(ex, DeadlineExceededError) or \
     isinstance(ex, taskqueue.TransientError):
     utils.log.warn(lines)
   else:
     utils.log.error(lines)
     if not utils.is_local() and not utils.is_debug():
       mail.send_mail(
         sender=u'*****@*****.**',
         to=u'*****@*****.**',
         subject=u'Caught Exception',
         body=lines)