예제 #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)
예제 #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
예제 #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
예제 #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
예제 #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
예제 #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
예제 #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
예제 #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
예제 #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
예제 #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)
예제 #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
예제 #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
예제 #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
예제 #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)
예제 #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
예제 #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
예제 #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)
예제 #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
예제 #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
예제 #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
예제 #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)
예제 #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
예제 #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)
예제 #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
예제 #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)
예제 #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
예제 #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)
예제 #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
예제 #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
예제 #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
예제 #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
예제 #32
0
 def setRotation(self, degree):
     checkParamsType([(degree, [int])])
     checkParamsLimit([(degree, ['0<=x<=360'])])
     self.__args['rotate'] = degree
예제 #33
0
 def setAnnotateOutputCode(self, output_code):
    checkParamsType([(output_code, [int])])
    checkParamsLimit([(output_code, ['0<=x<=4'])])
    self.__operations['desttype'] = output_code
예제 #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
예제 #35
0
 def setQRCodeMargin(self, margin):
     checkParamsType([(margin, [int])])
     checkParamsLimit([(margin, ['1<=x<=100'])])
     self.__operations['margin'] = margin
예제 #36
0
 def setQRCodeSize(self, size):
     checkParamsType([(size, [int])])
     checkParamsLimit([(size, ['0<x<=100'])])
     self.__operations['size'] = size
예제 #37
0
 def setCompositeQuality(self, quality):
     checkParamsType([(quality, [int])])
     checkParamsLimit([(quality, ['0<=x<=100'])])
     self.__composite_quality = quality
예제 #38
0
 def setQRCodeMargin(self, margin):          
    checkParamsType([(margin, [int])])
    checkParamsLimit([(margin, ['1<=x<=100'])])
    self.__operations['margin'] = margin
예제 #39
0
 def setRotation(self, degree):
    checkParamsType([(degree, [int])])
    checkParamsLimit([(degree, ['0<=x<=360'])])
    self.__args['rotate'] = degree
예제 #40
0
 def setQuality(self, quality=60):
     checkParamsType([(quality, [int])])
     checkParamsLimit([(quality, ['0<=x<=100'])])
     self.__args['quality'] = quality
예제 #41
0
 def setHue(self, hue):
    checkParamsType([(hue, [int])])
    checkParamsLimit([(hue, ['1<=x<=100'])])
    self.__args['hue'] = hue
예제 #42
0
 def setSaturation(self, saturation):
     checkParamsType([(saturation, [int])])
     checkParamsLimit([(saturation, ['1<=x<=100'])])
     self.__args['saturation'] = saturation
예제 #43
0
 def setLightness(self, lightness):
    checkParamsType([(lightness, [int])])
    checkParamsLimit([(lightness, ['x>=1'])])
    self.__args['lightness'] = lightness
예제 #44
0
 def setCompositeOutputCode(self, output_code):
     checkParamsType([(output_code, [int])])
     checkParamsLimit([(output_code, ['0<=x<4'])])
     self.__composite_desttype = output_code
예제 #45
0
 def setQRCodeLevel(self, level):          
    checkParamsType([(level, [int])])
    checkParamsLimit([(level, ['1<=x<=4'])])
    self.__operations['level'] = level
예제 #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)
예제 #47
0
 def setAnnotateOutputCode(self, output_code):
     checkParamsType([(output_code, [int])])
     checkParamsLimit([(output_code, ['0<=x<=4'])])
     self.__operations['desttype'] = output_code
예제 #48
0
 def setQRCodeVersion(self, version):
     checkParamsType([(version, [int])])
     checkParamsLimit([(version, ['0<=x<=30'])])
     self.__operations['version'] = version
예제 #49
0
 def setAnnotateQuality(self, quality):
     checkParamsType([(quality, [int])])
     checkParamsLimit([(quality, ['0<=x<=100'])])
     self.__operations['quality'] = quality
예제 #50
0
 def setQRCodeLevel(self, level):
     checkParamsType([(level, [int])])
     checkParamsLimit([(level, ['1<=x<=4'])])
     self.__operations['level'] = level
예제 #51
0
 def setQRCodeSize(self, size):          
    checkParamsType([(size, [int])])
    checkParamsLimit([(size, ['0<x<=100'])])
    self.__operations['size'] = size
예제 #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
예제 #53
0
 def setQRCodeVersion(self, version):          
    checkParamsType([(version, [int])])
    checkParamsLimit([(version, ['0<=x<=30'])])
    self.__operations['version'] = version
예제 #54
0
 def setAnnotateQuality(self, quality):
    checkParamsType([(quality, [int])])
    checkParamsLimit([(quality, ['0<=x<=100'])])
    self.__operations['quality'] = quality
예제 #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) 
예제 #56
0
 def setCompositeQuality(self, quality):
    checkParamsType([(quality, [int])])
    checkParamsLimit([(quality, ['0<=x<=100'])])
    self.__composite_quality = quality
예제 #57
0
 def setCompositeOutputCode(self, output_code):
    checkParamsType([(output_code, [int])])
    checkParamsLimit([(output_code, ['0<=x<4'])])
    self.__composite_desttype = output_code
예제 #58
0
 def setHue(self, hue):
     checkParamsType([(hue, [int])])
     checkParamsLimit([(hue, ['1<=x<=100'])])
     self.__args['hue'] = hue
예제 #59
0
 def setContrast(self, contrast):
    checkParamsType([(contrast, [int])])
    checkParamsLimit([(contrast, ['0<=x<=1'])])
    self.__args['contrast'] = contrast