Example #1
0
 def validate_options(opts):
     opts = Image._normalize_options(opts)
     if opts["mode"] not in Image.MODES:
         raise errors.ModeError("Invalid mode: %s" % opts["mode"])
     elif opts["filter"] not in Image.FILTERS:
         raise errors.FilterError("Invalid filter: %s" % opts["filter"])
     elif opts["format"] and opts["format"] not in Image.FORMATS:
         raise errors.FormatError("Invalid format: %s" % opts["format"])
     elif opts["position"] not in Image.POSITIONS \
             and not opts["pil"]["position"]:
         raise errors.PositionError("Invalid position: %s" %
                                    opts["position"])
     elif not Image._isint(opts["background"], 16) \
             or len(opts["background"]) not in [3, 4, 6, 8]:
         raise errors.BackgroundError("Invalid background: %s" %
                                      opts["background"])
     elif opts["optimize"] and not Image._isint(opts["optimize"]):
         raise errors.OptimizeError("Invalid optimize: %s",
                                    str(opts["optimize"]))
     elif opts["quality"] != "keep" and \
         (not Image._isint(opts["quality"]) or
          int(opts["quality"]) > 100 or
          int(opts["quality"]) < 0):
         raise errors.QualityError("Invalid quality: %s",
                                   str(opts["quality"]))
     elif opts["preserve_exif"] and not Image._isint(opts["preserve_exif"]):
         raise errors.PreserveExifError("Invalid preserve_exif: %s" %
                                        str(opts["preserve_exif"]))
     elif opts["progressive"] and not Image._isint(opts["progressive"]):
         raise errors.ProgressiveError("Invalid progressive: %s",
                                       str(opts["progressive"]))
     elif (not Image._isint(opts["retain"]) or int(opts["retain"]) > 100
           or int(opts["retain"]) < 0):
         raise errors.RetainError("Invalid retain: %s" %
                                  str(opts["retain"]))
Example #2
0
 def validate_options(opts):
     opts = Image._normalize_options(opts)
     if opts["mode"] not in Image.MODES:
         raise errors.ModeError("Invalid mode: %s" % opts["mode"])
     elif opts["filter"] not in Image.FILTERS:
         raise errors.FilterError("Invalid filter: %s" % opts["filter"])
     elif opts["format"] and opts["format"] not in Image.FORMATS:
         raise errors.FormatError("Invalid format: %s" % opts["format"])
     elif opts["position"] not in Image.POSITIONS \
             and not opts["pil"]["position"]:
         raise errors.PositionError("Invalid position: %s" %
                                    opts["position"])
     elif not Image._isint(opts["background"], 16) \
             or len(opts["background"]) not in [3, 4, 6, 8]:
         raise errors.BackgroundError("Invalid background: %s" %
                                      opts["background"])
     elif not Image._isint(opts["quality"]) \
             or int(opts["quality"]) > 100 or int(opts["quality"]) < 0:
         raise errors.QualityError("Invalid quality: %s",
                                   str(opts["quality"]))