示例#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