How to use is_base64 method in localstack

Best Python code snippet using localstack_python

create_source_request_body.py

Source:create_source_request_body.py Github

copy

Full Screen

...103 :type topic: str104 """105 self._topic = topic106 @property107 def is_base64(self):108 """Gets the is_base64 of this CreateSourceRequestBody.109 是否payload使用base64,0-是 1-否110 :return: The is_base64 of this CreateSourceRequestBody.111 :rtype: int112 """113 return self._is_base64114 @is_base64.setter115 def is_base64(self, is_base64):116 """Sets the is_base64 of this CreateSourceRequestBody.117 是否payload使用base64,0-是 1-否118 :param is_base64: The is_base64 of this CreateSourceRequestBody.119 :type is_base64: int120 """121 self._is_base64 = is_base64122 @property123 def contain_device_info(self):124 """Gets the contain_device_info of this CreateSourceRequestBody.125 是否包含设备信息是否包含设备信息,0-是 1-否126 :return: The contain_device_info of this CreateSourceRequestBody.127 :rtype: int128 """129 return self._contain_device_info...

Full Screen

Full Screen

image_utils.py

Source:image_utils.py Github

copy

Full Screen

1#!/usr/bin/python2import sys3import cv24import numpy5import base646import utils7import logger8import config9log = logger.get_logger(__name__)10conf = config.get_config()11# variables12detect_objects_debug = False13current_index = 114# return a cv2 image object from a binary image15def import_image(data,is_base64=False):16 if is_base64: data = base64.b64decode(data)17 image = numpy.asarray(bytearray(data), dtype="uint8")18 image = cv2.imdecode(image, cv2.IMREAD_COLOR)19 return image20# return a binary image from a cv2 object21def export_image(image,is_base64=False):22 r, buffer = cv2.imencode(".png",image)23 data = buffer.tostring()24 if is_base64: data = base64.b64encode(data)25 return data26# normalize an image27def normalize(image,hist=True,blur=False):28 if image is None: return image29 normalized = image30 normalized = cv2.cvtColor(normalized, cv2.COLOR_BGR2GRAY)31 if hist: normalized = cv2.equalizeHist(normalized)32 if blur: normalied = cv2.GaussianBlur(normalized, (21, 21), 0)33 return normalized34# detect movement between two images35def detect_movement(sensor,images,is_base64=False):36 max = 037 index = None38 for i in range(len(images)-1):39 # normalize the images40 i1 = normalize(import_image(images[i],is_base64=is_base64),hist=False)41 i2 = normalize(import_image(images[i+1],is_base64=is_base64),hist=False)42 if i1 is None or i2 is None: continue43 # calculate height and width44 i1_height, i1_width = i1.shape[:2]45 i2_height, i2_width = i2.shape[:2]46 if i1_height != i2_height or i1_width != i2_width: 47 # if they have difference sizes, the image is invalid, ignore it48 continue49 # calculate the difference50 delta = cv2.absdiff(i1,i2)51 # calculate the threshold52 delta = cv2.threshold(delta, 25, 255, cv2.THRESH_BINARY)[1]53 # return the percentage of change54 percentage = cv2.countNonZero(delta)*100/(i1_height*i1_width)55 if percentage > max: 56 max = percentage57 index = i58 if index is None: return None59 image = import_image(images[index],is_base64=is_base64)60 return [max,image]61# detect objects in a given image62def detect_objects(sensor,image,is_base64=False):63 # read the image64 image = import_image(image,is_base64=is_base64)65 if image is None: return None66 # normalize the image67 normalized = normalize(image)68 # for each detection feature69 for feature in sensor["object_detection"]:70 # load the cascade file71 filename = conf["constants"]["base_dir"]+"/"+feature["filename"]72 if not utils.file_exists(filename):73 log.error("Unable to load the detection object XML at "+filename)74 return None75 cascade = cv2.CascadeClassifier(filename)76 # perform the detection77 objects = cascade.detectMultiScale(78 normalized,79 scaleFactor=feature["scale_factor"],80 minNeighbors=feature["min_neighbors"],81 minSize=(feature["min_size"],feature["min_size"]),82 maxSize=(feature["max_size"],feature["max_size"]),83 flags = cv2.cv.CV_HAAR_SCALE_IMAGE84 )85 # nothing found, go to the next object86 if len(objects) == 0: continue87 # return the number of objects detected88 else:89 # found draw a rectangle around each object90 for (x, y, w, h) in objects:91 cv2.rectangle(image, (x, y), (x+w, y+h), (0, 255, 0), 2)92 # prepare the alert text93 text = str(len(objects))+" "+utils.lang(feature["display_name"])94 # prepare the image95 image = export_image(image,is_base64=is_base64)96 return [text,image]97 # nothing found, return None98 return None99# save an image into a temporary folder100def save_tmp_image(prefix,image):101 global current_index102 if not conf["constants"]["image_detection_save_on_disk"]: return103 # keep a maximum number of images104 if current_index > conf["constants"]["image_detection_max_saved_images"]: current_index = 1105 filename = conf["constants"]["tmp_dir"]+"/"+prefix+"_"+str(current_index)+".png"106 cv2.imwrite(filename,image)107 current_index = current_index +1...

Full Screen

Full Screen

digest.py

Source:digest.py Github

copy

Full Screen

1#! /usr/bin/env python32# -*- coding: utf-8 -*-3"""4消息摘要算法相关代码5"""6import base647import hashlib8import hmac9def gen_md5_32_hexdigest(s):10 """11 # 获取字符串的MD5值12 :param s:13 :return:14 """15 m = hashlib.md5()16 m.update(s.encode('utf-8'))17 return m.hexdigest()18def gen_sha1_hexdigest(s):19 return hashlib.sha1(s.encode('utf-8')).hexdigest()20def gen_sha512_hexdigest(s):21 return hashlib.sha512(s.encode('utf-8')).hexdigest()22def _sign_shax_digest(algorithm, secret: str, s: str, is_base64=False):23 """24 签名字符串25 :param algorithm: 签名算法26 :param secret: 密码27 :param s: 输入字符串28 :param is_base64: 是否输出Base6429 :return:30 """31 hashed = hmac.new(secret.encode('utf-8'), s.encode('utf-8'), algorithm)32 if is_base64:33 return base64.b64encode(hashed.digest()).decode().rstrip('\n')34 else:35 return hashed.hexdigest()36def sign_sha1_digest(secret, s, is_base64=False):37 return _sign_shax_digest(hashlib.sha1, secret, s, is_base64)38def sign_sha224_digest(secret, s, is_base64=False):39 return _sign_shax_digest(hashlib.sha224, secret, s, is_base64)40def sign_sha256_digest(secret, s, is_base64=False):41 return _sign_shax_digest(hashlib.sha256, secret, s, is_base64)42def sign_sha384_digest(secret, s, is_base64=False):43 return _sign_shax_digest(hashlib.sha384, secret, s, is_base64)44def sign_sha512_digest(secret, s, is_base64=False):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful