Exemplo n.º 1
0
 def _checkRGB(self, rgbstr):
    checkParamsType([(rgbstr, [basestring])])
    if isinstance(rgbstr, unicode):
       rgbstr = rgbstr.encode('utf-8')
    checkParamsLimit([(rgbstr, ['len(x)==6'])])
    if not self.RGB_PATTERN.match(rgbstr):
       raise BaeValueError("invalid RGB color", rgbstr)
Exemplo n.º 2
0
 def setCompositeCanvas(self, canvas_width, canvas_height):
    checkParamsType([(canvas_width, [int])])
    checkParamsLimit([(canvas_width, ['0<=x<=10000'])])
    checkParamsType([(canvas_height, [int])])
    checkParamsLimit([(canvas_height, ['0<=x<=10000'])])
    self.__composite_canvas_width = canvas_width
    self.__composite_canvas_height = canvas_height
Exemplo n.º 3
0
 def setCompositeCanvas(self, canvas_width, canvas_height):
     checkParamsType([(canvas_width, [int])])
     checkParamsLimit([(canvas_width, ['0<=x<=10000'])])
     checkParamsType([(canvas_height, [int])])
     checkParamsLimit([(canvas_height, ['0<=x<=10000'])])
     self.__composite_canvas_width = canvas_width
     self.__composite_canvas_height = canvas_height
Exemplo n.º 4
0
 def setAnnotatePos(self, x_offset, y_offset):
     checkParamsType([(x_offset, [int])])
     checkParamsLimit([(x_offset, ['x>=0'])])
     checkParamsType([(y_offset, [int])])
     checkParamsLimit([(y_offset, ['x>=0'])])
     self.__operations['x_offset'] = x_offset
     self.__operations['y_offset'] = y_offset
Exemplo n.º 5
0
 def setSource(self, image_source):
    checkParamsType([(image_source, [basestring])])
    if isinstance(image_source, unicode):
       image_source = image_source.encode('utf-8')
    checkParamsLimit([(image_source, ['0<len(x)<=2048'])])
    if self._isUrl(image_source):
       self.__args['src'] = image_source
Exemplo n.º 6
0
 def setCompositePos(self, x_offset, y_offset, img_key = 0):
    checkParamsType([(x_offset, [int])])
    checkParamsType([(y_offset, [int])])
    if img_key >= len(self.__strudata['req_data_source']):
       raise BaeValueError("invalid img_key, image %d isn't exist"%img_key)   
    self.__strudata['req_data_source'][img_key]['operations']['x_offset'] = x_offset
    self.__strudata['req_data_source'][img_key]['operations']['y_offset'] = y_offset
Exemplo n.º 7
0
 def setCropping(self, x, y, width, height):
    checkParamsType([(x, [int]), (y, [int]), (height, [int]), (width, [int])])
    checkParamsLimit([(x, ['0<=x<=10000']), (y, ['0<=x<=10000']), (height, ['0<=x<=10000']), (width, ['0<=x<=10000'])])
    self.__args['cut_x'] = x
    self.__args['cut_y'] = y
    self.__args['cut_h'] = height
    self.__args['cut_w'] = width
Exemplo n.º 8
0
 def setSource(self, image_source):
     checkParamsType([(image_source, [basestring])])
     if isinstance(image_source, unicode):
         image_source = image_source.encode('utf-8')
     checkParamsLimit([(image_source, ['0<len(x)<=2048'])])
     if self._isUrl(image_source):
         self.__args['src'] = image_source
Exemplo n.º 9
0
 def setAnnotatePos(self, x_offset, y_offset):
    checkParamsType([(x_offset, [int])])
    checkParamsLimit([(x_offset, ['x>=0'])])
    checkParamsType([(y_offset, [int])])
    checkParamsLimit([(y_offset, ['x>=0'])])
    self.__operations['x_offset'] = x_offset
    self.__operations['y_offset'] = y_offset
Exemplo n.º 10
0
 def _checkRGB(self, rgbstr):
     checkParamsType([(rgbstr, [basestring])])
     if isinstance(rgbstr, unicode):
         rgbstr = rgbstr.encode('utf-8')
     checkParamsLimit([(rgbstr, ['len(x)==6'])])
     if not self.RGB_PATTERN.match(rgbstr):
         raise BaeValueError("invalid RGB color", rgbstr)
Exemplo n.º 11
0
 def setCompositeOpacity(self, opacity, img_key=0):
     checkParamsType([(opacity, [int, float])])
     checkParamsLimit([(opacity, ['0.0<=x<=1.0'])])
     if img_key >= len(self.__strudata['req_data_source']):
         raise BaeValueError("invalid img_key, image %d isn't exist" %
                             img_key)
     self.__strudata['req_data_source'][img_key]['operations'][
         'opacity'] = opacity
Exemplo n.º 12
0
 def setCompositeAnchor(self, anchor, img_key=0):
     checkParamsType([(anchor, [int])])
     checkParamsLimit([(anchor, ['0<=x<=8'])])
     if img_key >= len(self.__strudata['req_data_source']):
         raise BaeValueError("invalid img_key, image %d isn't exist" %
                             img_key)
     self.__strudata['req_data_source'][img_key]['operations'][
         'anchor_point'] = anchor
Exemplo n.º 13
0
 def setCropping(self, x, y, width, height):
     checkParamsType([(x, [int]), (y, [int]), (height, [int]),
                      (width, [int])])
     checkParamsLimit([(x, ['0<=x<=10000']), (y, ['0<=x<=10000']),
                       (height, ['0<=x<=10000']), (width, ['0<=x<=10000'])])
     self.__args['cut_x'] = x
     self.__args['cut_y'] = y
     self.__args['cut_h'] = height
     self.__args['cut_w'] = width
Exemplo n.º 14
0
 def generateVCode(self, vcode_len=4, vcode_pattern=0):
     checkParamsType([(vcode_len, [int])])
     checkParamsLimit([(vcode_len, ['4<=x<=5'])])
     checkParamsType([(vcode_pattern, [int])])
     checkParamsLimit([(vcode_pattern, ['0<=x<=3'])])
     self.__args = {}
     self.__args['vcservice'] = 0
     self.__args['len'] = vcode_len
     self.__args['setno'] = vcode_pattern
     return self._common_process(self.__args)
Exemplo n.º 15
0
 def setCompositePos(self, x_offset, y_offset, img_key=0):
     checkParamsType([(x_offset, [int])])
     checkParamsType([(y_offset, [int])])
     if img_key >= len(self.__strudata['req_data_source']):
         raise BaeValueError("invalid img_key, image %d isn't exist" %
                             img_key)
     self.__strudata['req_data_source'][img_key]['operations'][
         'x_offset'] = x_offset
     self.__strudata['req_data_source'][img_key]['operations'][
         'y_offset'] = y_offset
Exemplo n.º 16
0
 def setTranscoding(self, image_type, quality=60):
     types = {'gif': 2, 'jpg': 1, 'png': 3, 'webp': 4}
     checkParamsType([(image_type, [basestring]), (quality, [int])])
     checkParamsLimit([(quality, ['0<=x<=100'])])
     try:
         self.__args['imgtype'] = types[image_type]
     except KeyError:
         raise BaeParamError('Invalid Image Type[%s]' % image_type)
     if image_type in ['gif', 'jpg']:
         self.__args['quality'] = quality
Exemplo n.º 17
0
 def generateVCode(self, vcode_len = 4, vcode_pattern = 0):
    checkParamsType([(vcode_len, [int])])
    checkParamsLimit([(vcode_len, ['4<=x<=5'])])
    checkParamsType([(vcode_pattern, [int])])
    checkParamsLimit([(vcode_pattern, ['0<=x<=3'])])
    self.__args = {}
    self.__args['vcservice'] = 0
    self.__args['len'] = vcode_len
    self.__args['setno'] = vcode_pattern
    return self._common_process(self.__args)
Exemplo n.º 18
0
 def setTranscoding(self, image_type, quality = 60):
    types = {'gif': 2, 'jpg': 1, 'png': 3, 'webp': 4}
    checkParamsType([(image_type, [basestring]), (quality, [int])])
    checkParamsLimit([(quality, ['0<=x<=100'])])
    try:
       self.__args['imgtype'] = types[image_type]
    except KeyError:
       raise BaeParamError('Invalid Image Type[%s]'%image_type)
    if image_type in ['gif', 'jpg']:
       self.__args['quality'] = quality
Exemplo n.º 19
0
 def setAnnotateOpacity(self, opacity):
    checkParamsType([(opacity, [int, float])])
    checkParamsLimit([(opacity, ['0.0<=x<=1.0'])])
    if opacity == 1:
       opacity = '00'
    elif opacity == 0:
       opacity = 'ff'
    else:
       opacity = hex(int(math.ceil(255 - opacity*255)))
       opacity = opacity.replace('0x', '')
    opacity = opacity.upper()
    self.__operations['opacity'] = opacity
Exemplo n.º 20
0
 def setAnnotateOpacity(self, opacity):
     checkParamsType([(opacity, [int, float])])
     checkParamsLimit([(opacity, ['0.0<=x<=1.0'])])
     if opacity == 1:
         opacity = '00'
     elif opacity == 0:
         opacity = 'ff'
     else:
         opacity = hex(int(math.ceil(255 - opacity * 255)))
         opacity = opacity.replace('0x', '')
     opacity = opacity.upper()
     self.__operations['opacity'] = opacity
Exemplo n.º 21
0
 def verifyVCode(self, vcode_input, vcode_secret):
    checkParamsType([(vcode_input, [basestring])])
    if isinstance(vcode_input, unicode):
       vcode_input = vcode_input.encode('utf-8')
    checkParamsLimit([(vcode_input, ['4<=len(x)<=5'])])
    checkParamsType([(vcode_secret, [basestring])])
    if isinstance(vcode_secret, unicode):
       vcode_secret = vcode_secret.encode('utf-8')
    self.__args = {}
    self.__args['vcservice'] = 1
    self.__args['input'] = vcode_input
    self.__args['vcode'] = vcode_secret
    return self._common_process(self.__args)
Exemplo n.º 22
0
 def __init__(self, access_key, secret_key, host, image_source = "http://", debug = False):
    self.__args = {}
    self.__args['src'] = image_source
    self.__ak = access_key 
    self.__sk = secret_key
    self.__host = host
    checkParamsType([(self.__ak, [basestring]), (self.__sk, [basestring]), (debug, [bool]), (self.__args['src'], [basestring]), (self.__host, [basestring])])
    checkParamsLimit([(image_source, ['0<=len(x)<=2048'])])
    if not self.__ak or not self.__sk or not self.__host:
       raise BaeConstructError("Invalid ak, sk, or image host")
    self.__requestId = 0
    self._debug = debug
    self.__strudata = None
Exemplo n.º 23
0
 def verifyVCode(self, vcode_input, vcode_secret):
     checkParamsType([(vcode_input, [basestring])])
     if isinstance(vcode_input, unicode):
         vcode_input = vcode_input.encode('utf-8')
     checkParamsLimit([(vcode_input, ['4<=len(x)<=5'])])
     checkParamsType([(vcode_secret, [basestring])])
     if isinstance(vcode_secret, unicode):
         vcode_secret = vcode_secret.encode('utf-8')
     self.__args = {}
     self.__args['vcservice'] = 1
     self.__args['input'] = vcode_input
     self.__args['vcode'] = vcode_secret
     return self._common_process(self.__args)
Exemplo n.º 24
0
 def setCompositeSource(self, image_source):
    checkParamsType([(image_source, [basestring])])
    if isinstance(image_source, unicode):
       image_source = image_source.encode('utf-8')
    checkParamsLimit([(image_source, ['0<=len(x)<=2048'])])
    t = {'http_reqpack': {},
         'source_data_type': '1',
         'operations': {},
        }
    if self._isUrl(image_source):
       t['sourcemethod'] = 'GET'
       t['source_url'] = image_source 
       self.__strudata['req_data_source'].append(t)
    else: pass
Exemplo n.º 25
0
 def setZooming(self, zooming_type, value, height_value = 0):
    checkParamsType([(zooming_type, [int]), (value, [int]), (height_value, [int])])
    checkParamsLimit([(zooming_type, ['1<=x<=4'])])
    if zooming_type == BaeImage.ZOOMING_TYPE_HEIGHT:
       checkParamsLimit([(value, ['0<=x<=10000'])])
       self.__args['size'] = 'b0_' + str(value)
    elif zooming_type == BaeImage.ZOOMING_TYPE_WIDTH:
       checkParamsLimit([(value, ['0<=x<=10000'])])
       self.__args['size'] = 'b' + str(value) + '_0'
    elif zooming_type == BaeImage.ZOOMING_TYPE_PIXELS:
       checkParamsLimit([(value, ['0<=x<=100000000'])])
       self.__args['size'] = 'p' + str(value)
    elif zooming_type == BaeImage.ZOOMING_TYPE_UNRATIO:
       checkParamsLimit([(value, ['0<=x<=10000'])]) 
       checkParamsLimit([(height_value, ['0<=x<=10000'])])
       self.__args['size'] = 'u' + str(value) + '_' + str(height_value)
Exemplo n.º 26
0
 def setCompositeSource(self, image_source):
     checkParamsType([(image_source, [basestring])])
     if isinstance(image_source, unicode):
         image_source = image_source.encode('utf-8')
     checkParamsLimit([(image_source, ['0<=len(x)<=2048'])])
     t = {
         'http_reqpack': {},
         'source_data_type': '1',
         'operations': {},
     }
     if self._isUrl(image_source):
         t['sourcemethod'] = 'GET'
         t['source_url'] = image_source
         self.__strudata['req_data_source'].append(t)
     else:
         pass
Exemplo n.º 27
0
 def setZooming(self, zooming_type, value, height_value=0):
     checkParamsType([(zooming_type, [int]), (value, [int]),
                      (height_value, [int])])
     checkParamsLimit([(zooming_type, ['1<=x<=4'])])
     if zooming_type == BaeImage.ZOOMING_TYPE_HEIGHT:
         checkParamsLimit([(value, ['0<=x<=10000'])])
         self.__args['size'] = 'b0_' + str(value)
     elif zooming_type == BaeImage.ZOOMING_TYPE_WIDTH:
         checkParamsLimit([(value, ['0<=x<=10000'])])
         self.__args['size'] = 'b' + str(value) + '_0'
     elif zooming_type == BaeImage.ZOOMING_TYPE_PIXELS:
         checkParamsLimit([(value, ['0<=x<=100000000'])])
         self.__args['size'] = 'p' + str(value)
     elif zooming_type == BaeImage.ZOOMING_TYPE_UNRATIO:
         checkParamsLimit([(value, ['0<=x<=10000'])])
         checkParamsLimit([(height_value, ['0<=x<=10000'])])
         self.__args['size'] = 'u' + str(value) + '_' + str(height_value)
Exemplo n.º 28
0
    def __init__(self, cache_id, memcache_addr, user, password):
        checkParamsType([(memcache_addr, [basestring]), (user, [basestring]), (password, [basestring]), (cache_id, [basestring])])
       
        self._ak = user
        self._sk = password
        self._appid = cache_id
 
        self.nsh = nshead.CNsHead()
        self.lastcmd, self.lastkey = None, None
        self.lasterrno, self.lasterrmsg = 0, None
    
        self._servers = [] 
        for server in memcache_addr.split(";"):
            try:
                host, port = server.split(':')
                self._servers.append((host, int(port)))
            except:
                raise BaeMemcacheParamsError("Invalid memcache_addr")
        self._index = 0
        self._sock = None
Exemplo n.º 29
0
 def __init__(self,
              access_key,
              secret_key,
              host,
              image_source="http://",
              debug=False):
     self.__args = {}
     self.__args['src'] = image_source
     self.__ak = access_key
     self.__sk = secret_key
     self.__host = host
     checkParamsType([(self.__ak, [basestring]), (self.__sk, [basestring]),
                      (debug, [bool]), (self.__args['src'], [basestring]),
                      (self.__host, [basestring])])
     checkParamsLimit([(image_source, ['0<=len(x)<=2048'])])
     if not self.__ak or not self.__sk or not self.__host:
         raise BaeConstructError("Invalid ak, sk, or image host")
     self.__requestId = 0
     self._debug = debug
     self.__strudata = None
Exemplo n.º 30
0
 def setAnnotateFont(self, name, size, color):
     checkParamsType([(name, [int])])
     checkParamsLimit([(name, ['0<=x<=4'])])
     checkParamsType([(size, [int])])
     checkParamsLimit([(size, ['0<=x<=100'])])
     checkParamsType([(color, [basestring])])
     if isinstance(color, unicode):
         color = color.encode('utf-8')
     self._checkRGB(color)
     self.__operations['font_name'] = name
     self.__operations['font_size'] = size
     self.__operations['font_color'] = color
Exemplo n.º 31
0
 def setAnnotateFont(self, name, size, color):    
    checkParamsType([(name, [int])])
    checkParamsLimit([(name, ['0<=x<=4'])])
    checkParamsType([(size, [int])])
    checkParamsLimit([(size, ['0<=x<=100'])])
    checkParamsType([(color, [basestring])])
    if isinstance(color, unicode):
       color = color.encode('utf-8')
    self._checkRGB(color)
    self.__operations['font_name'] = name
    self.__operations['font_size'] = size
    self.__operations['font_color'] = color
Exemplo n.º 32
0
 def setRotation(self, degree):
     checkParamsType([(degree, [int])])
     checkParamsLimit([(degree, ['0<=x<=360'])])
     self.__args['rotate'] = degree
Exemplo n.º 33
0
 def setAnnotateOutputCode(self, output_code):
    checkParamsType([(output_code, [int])])
    checkParamsLimit([(output_code, ['0<=x<=4'])])
    self.__operations['desttype'] = output_code
Exemplo n.º 34
0
 def setCompositeOpacity(self, opacity, img_key = 0):
    checkParamsType([(opacity, [int, float])])
    checkParamsLimit([(opacity, ['0.0<=x<=1.0'])])
    if img_key >= len(self.__strudata['req_data_source']):
       raise BaeValueError("invalid img_key, image %d isn't exist"%img_key)   
    self.__strudata['req_data_source'][img_key]['operations']['opacity'] = opacity
Exemplo n.º 35
0
 def setQRCodeMargin(self, margin):
     checkParamsType([(margin, [int])])
     checkParamsLimit([(margin, ['1<=x<=100'])])
     self.__operations['margin'] = margin
Exemplo n.º 36
0
 def setQRCodeSize(self, size):
     checkParamsType([(size, [int])])
     checkParamsLimit([(size, ['0<x<=100'])])
     self.__operations['size'] = size
Exemplo n.º 37
0
 def setCompositeQuality(self, quality):
     checkParamsType([(quality, [int])])
     checkParamsLimit([(quality, ['0<=x<=100'])])
     self.__composite_quality = quality
Exemplo n.º 38
0
 def setQRCodeMargin(self, margin):          
    checkParamsType([(margin, [int])])
    checkParamsLimit([(margin, ['1<=x<=100'])])
    self.__operations['margin'] = margin
Exemplo n.º 39
0
 def setRotation(self, degree):
    checkParamsType([(degree, [int])])
    checkParamsLimit([(degree, ['0<=x<=360'])])
    self.__args['rotate'] = degree
Exemplo n.º 40
0
 def setQuality(self, quality=60):
     checkParamsType([(quality, [int])])
     checkParamsLimit([(quality, ['0<=x<=100'])])
     self.__args['quality'] = quality
Exemplo n.º 41
0
 def setHue(self, hue):
    checkParamsType([(hue, [int])])
    checkParamsLimit([(hue, ['1<=x<=100'])])
    self.__args['hue'] = hue
Exemplo n.º 42
0
 def setSaturation(self, saturation):
     checkParamsType([(saturation, [int])])
     checkParamsLimit([(saturation, ['1<=x<=100'])])
     self.__args['saturation'] = saturation
Exemplo n.º 43
0
 def setLightness(self, lightness):
    checkParamsType([(lightness, [int])])
    checkParamsLimit([(lightness, ['x>=1'])])
    self.__args['lightness'] = lightness
Exemplo n.º 44
0
 def setCompositeOutputCode(self, output_code):
     checkParamsType([(output_code, [int])])
     checkParamsLimit([(output_code, ['0<=x<4'])])
     self.__composite_desttype = output_code
Exemplo n.º 45
0
 def setQRCodeLevel(self, level):          
    checkParamsType([(level, [int])])
    checkParamsLimit([(level, ['1<=x<=4'])])
    self.__operations['level'] = level
Exemplo n.º 46
0
 def setQRCodeText(self, text):
     checkParamsType([(text, [basestring])])
     if isinstance(text, unicode):
         text = text.encode('utf-8')
     checkParamsLimit([(text, ['1<=len(x)<=500'])])
     self.__source_data['data1'] = base64.b64encode(text)
Exemplo n.º 47
0
 def setAnnotateOutputCode(self, output_code):
     checkParamsType([(output_code, [int])])
     checkParamsLimit([(output_code, ['0<=x<=4'])])
     self.__operations['desttype'] = output_code
Exemplo n.º 48
0
 def setQRCodeVersion(self, version):
     checkParamsType([(version, [int])])
     checkParamsLimit([(version, ['0<=x<=30'])])
     self.__operations['version'] = version
Exemplo n.º 49
0
 def setAnnotateQuality(self, quality):
     checkParamsType([(quality, [int])])
     checkParamsLimit([(quality, ['0<=x<=100'])])
     self.__operations['quality'] = quality
Exemplo n.º 50
0
 def setQRCodeLevel(self, level):
     checkParamsType([(level, [int])])
     checkParamsLimit([(level, ['1<=x<=4'])])
     self.__operations['level'] = level
Exemplo n.º 51
0
 def setQRCodeSize(self, size):          
    checkParamsType([(size, [int])])
    checkParamsLimit([(size, ['0<x<=100'])])
    self.__operations['size'] = size
Exemplo n.º 52
0
 def setCompositeAnchor(self, anchor, img_key = 0):
    checkParamsType([(anchor, [int])])
    checkParamsLimit([(anchor, ['0<=x<=8'])])
    if img_key >= len(self.__strudata['req_data_source']):
       raise BaeValueError("invalid img_key, image %d isn't exist"%img_key)   
    self.__strudata['req_data_source'][img_key]['operations']['anchor_point'] = anchor
Exemplo n.º 53
0
 def setQRCodeVersion(self, version):          
    checkParamsType([(version, [int])])
    checkParamsLimit([(version, ['0<=x<=30'])])
    self.__operations['version'] = version
Exemplo n.º 54
0
 def setAnnotateQuality(self, quality):
    checkParamsType([(quality, [int])])
    checkParamsLimit([(quality, ['0<=x<=100'])])
    self.__operations['quality'] = quality
Exemplo n.º 55
0
 def setQRCodeText(self, text):
    checkParamsType([(text, [basestring])])
    if isinstance(text, unicode):
       text = text.encode('utf-8')
    checkParamsLimit([(text, ['1<=len(x)<=500'])])
    self.__source_data['data1'] = base64.b64encode(text) 
Exemplo n.º 56
0
 def setCompositeQuality(self, quality):
    checkParamsType([(quality, [int])])
    checkParamsLimit([(quality, ['0<=x<=100'])])
    self.__composite_quality = quality
Exemplo n.º 57
0
 def setCompositeOutputCode(self, output_code):
    checkParamsType([(output_code, [int])])
    checkParamsLimit([(output_code, ['0<=x<4'])])
    self.__composite_desttype = output_code
Exemplo n.º 58
0
 def setHue(self, hue):
     checkParamsType([(hue, [int])])
     checkParamsLimit([(hue, ['1<=x<=100'])])
     self.__args['hue'] = hue
Exemplo n.º 59
0
 def setContrast(self, contrast):
    checkParamsType([(contrast, [int])])
    checkParamsLimit([(contrast, ['0<=x<=1'])])
    self.__args['contrast'] = contrast