Best Python code snippet using localstack_python
index.js
Source:index.js
1function formatNumber(n) {2 const str = n.toString();3 return str[1] ? str : `0${str}`;4}5export function formatTime(date) {6 const year = date.getFullYear();7 const month = date.getMonth() + 1;8 const day = date.getDate();9 const hour = date.getHours();10 const minute = date.getMinutes();11 const second = date.getSeconds();12 const t1 = [year, month, day].map(formatNumber).join("/");13 const t2 = [hour, minute, second].map(formatNumber).join(":");14 return `${t1} ${t2}`;15}16export function objToUrlParam(obj) {17 if (typeof obj != "object") {18 return "";19 }20 let keys = Object.keys(obj);21 let str = "";22 keys.forEach((item, index) => {23 if (index > 0) {24 str += "&";25 }26 str += `${item}=${obj[item]}`;27 });28 return str;29}30function base64_encode(str) {31 // ç¼ç ï¼é
åencodeURIComponent使ç¨32 var c1, c2, c3;33 var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";34 var i = 0,35 len = str.length,36 strin = "";37 while (i < len) {38 c1 = str.charCodeAt(i++) & 0xff;39 if (i == len) {40 strin += base64EncodeChars.charAt(c1 >> 2);41 strin += base64EncodeChars.charAt((c1 & 0x3) << 4);42 strin += "==";43 break;44 }45 c2 = str.charCodeAt(i++);46 if (i == len) {47 strin += base64EncodeChars.charAt(c1 >> 2);48 strin += base64EncodeChars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xf0) >> 4));49 strin += base64EncodeChars.charAt((c2 & 0xf) << 2);50 strin += "=";51 break;52 }53 c3 = str.charCodeAt(i++);54 strin += base64EncodeChars.charAt(c1 >> 2);55 strin += base64EncodeChars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xf0) >> 4));56 strin += base64EncodeChars.charAt(((c2 & 0xf) << 2) | ((c3 & 0xc0) >> 6));57 strin += base64EncodeChars.charAt(c3 & 0x3f);58 }59 return encodeURIComponent(strin);60}61function base64_decode(input) {62 input = decodeURIComponent(input);63 // 解ç ï¼é
ådecodeURIComponent使ç¨64 var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";65 var output = "";66 var chr1, chr2, chr3;67 var enc1, enc2, enc3, enc4;68 var i = 0;69 input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");70 while (i < input.length) {71 enc1 = base64EncodeChars.indexOf(input.charAt(i++));72 enc2 = base64EncodeChars.indexOf(input.charAt(i++));73 enc3 = base64EncodeChars.indexOf(input.charAt(i++));74 enc4 = base64EncodeChars.indexOf(input.charAt(i++));75 chr1 = (enc1 << 2) | (enc2 >> 4);76 chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);77 chr3 = ((enc3 & 3) << 6) | enc4;78 output = output + String.fromCharCode(chr1);79 if (enc3 != 64) {80 output = output + String.fromCharCode(chr2);81 }82 if (enc4 != 64) {83 output = output + String.fromCharCode(chr3);84 }85 }86 return utf8_decode(output);87}88function utf8_decode(utftext) {89 // utf-8解ç 90 var string = "";91 let i = 0;92 let c = 0;93 let c1 = 0;94 let c2 = 0;95 while (i < utftext.length) {96 c = utftext.charCodeAt(i);97 if (c < 128) {98 string += String.fromCharCode(c);99 i++;100 } else if (c > 191 && c < 224) {101 c1 = utftext.charCodeAt(i + 1);102 string += String.fromCharCode(((c & 31) << 6) | (c1 & 63));103 i += 2;104 } else {105 c1 = utftext.charCodeAt(i + 1);106 c2 = utftext.charCodeAt(i + 2);107 string += String.fromCharCode(((c & 15) << 12) | ((c1 & 63) << 6) | (c2 & 63));108 i += 3;109 }110 }111 return string;112}113export default {114 formatNumber,115 formatTime,116 objToUrlParam,117 utf8_decode,118 base64_decode,119 base64_encode...
base64.js
Source:base64.js
1/* Copyright (C) 1999 Masanao Izumo <iz@onicos.co.jp> & 2006 Ma Bingyao <andot@ujn.edu.cn>2 * Version: 1.223 * LastModified: May 9, 20064 * This library is free. You can redistribute it and/or modify it.5 */67/*8 * Interfaces:9 * b64 = base64encode(data);10 * data = base64decode(b64);11 */121314var base64EncodeChars = [15 "A", "B", "C", "D", "E", "F", "G", "H",16 "I", "J", "K", "L", "M", "N", "O", "P",17 "Q", "R", "S", "T", "U", "V", "W", "X",18 "Y", "Z", "a", "b", "c", "d", "e", "f",19 "g", "h", "i", "j", "k", "l", "m", "n",20 "o", "p", "q", "r", "s", "t", "u", "v",21 "w", "x", "y", "z", "0", "1", "2", "3",22 "4", "5", "6", "7", "8", "9", "+", "/"23];2425var base64DecodeChars = [26 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,27 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,28 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,29 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,30 -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,31 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,32 -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,33 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -134];3536function base64encode(str) {37 var out, i, j, len;38 var c1, c2, c3;3940 len = str.length;41 i = j = 0;42 out = [];43 while (i < len) {44 c1 = str.charCodeAt(i++) & 0xff;45 if (i == len)46 {47 out[j++] = base64EncodeChars[c1 >> 2];48 out[j++] = base64EncodeChars[(c1 & 0x3) << 4];49 out[j++] = "==";50 break;51 }52 c2 = str.charCodeAt(i++) & 0xff;53 if (i == len)54 {55 out[j++] = base64EncodeChars[c1 >> 2];56 out[j++] = base64EncodeChars[((c1 & 0x03) << 4) | ((c2 & 0xf0) >> 4)];57 out[j++] = base64EncodeChars[(c2 & 0x0f) << 2];58 out[j++] = "=";59 break;60 }61 c3 = str.charCodeAt(i++) & 0xff;62 out[j++] = base64EncodeChars[c1 >> 2];63 out[j++] = base64EncodeChars[((c1 & 0x03) << 4) | ((c2 & 0xf0) >> 4)];64 out[j++] = base64EncodeChars[((c2 & 0x0f) << 2) | ((c3 & 0xc0) >> 6)];65 out[j++] = base64EncodeChars[c3 & 0x3f];66 }67 return out.join('');68}6970function base64decode(str) {71 var c1, c2, c3, c4;72 var i, j, len, out;7374 len = str.length;75 i = j = 0;76 out = [];77 while (i < len) {78 /* c1 */79 do {80 c1 = base64DecodeChars[str.charCodeAt(i++) & 0xff];81 } while (i < len && c1 == -1);82 if (c1 == -1) break;8384 /* c2 */85 do {86 c2 = base64DecodeChars[str.charCodeAt(i++) & 0xff];87 } while (i < len && c2 == -1);88 if (c2 == -1) break;8990 out[j++] = String.fromCharCode((c1 << 2) | ((c2 & 0x30) >> 4));9192 /* c3 */93 do {94 c3 = str.charCodeAt(i++) & 0xff;95 if (c3 == 61) return out.join('');96 c3 = base64DecodeChars[c3];97 } while (i < len && c3 == -1);98 if (c3 == -1) break;99100 out[j++] = String.fromCharCode(((c2 & 0x0f) << 4) | ((c3 & 0x3c) >> 2));101102 /* c4 */103 do {104 c4 = str.charCodeAt(i++) & 0xff;105 if (c4 == 61) return out.join('');106 c4 = base64DecodeChars[c4];107 } while (i < len && c4 == -1);108 if (c4 == -1) break;109 out[j++] = String.fromCharCode(((c3 & 0x03) << 6) | c4);110 }111 return out.join('');
...
Base64Encode.py
Source:Base64Encode.py
1# -*- coding: utf-8 -*-2###############################################################################3#4# Base64Encode5# Returns the specified text or file as a Base64 encoded string.6#7# Python versions 2.6, 2.7, 3.x8#9# Copyright 2014, Temboo Inc.10#11# Licensed under the Apache License, Version 2.0 (the "License");12# you may not use this file except in compliance with the License.13# You may obtain a copy of the License at14#15# http://www.apache.org/licenses/LICENSE-2.016#17# Unless required by applicable law or agreed to in writing,18# software distributed under the License is distributed on an19# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,20# either express or implied. See the License for the specific21# language governing permissions and limitations under the License.22#23#24###############################################################################25from temboo.core.choreography import Choreography26from temboo.core.choreography import InputSet27from temboo.core.choreography import ResultSet28from temboo.core.choreography import ChoreographyExecution29import json30class Base64Encode(Choreography):31 def __init__(self, temboo_session):32 """33 Create a new instance of the Base64Encode Choreo. A TembooSession object, containing a valid34 set of Temboo credentials, must be supplied.35 """36 super(Base64Encode, self).__init__(temboo_session, '/Library/Utilities/Encoding/Base64Encode')37 def new_input_set(self):38 return Base64EncodeInputSet()39 def _make_result_set(self, result, path):40 return Base64EncodeResultSet(result, path)41 def _make_execution(self, session, exec_id, path):42 return Base64EncodeChoreographyExecution(session, exec_id, path)43class Base64EncodeInputSet(InputSet):44 """45 An InputSet with methods appropriate for specifying the inputs to the Base64Encode46 Choreo. The InputSet object is used to specify input parameters when executing this Choreo.47 """48 def set_Text(self, value):49 """50 Set the value of the Text input for this Choreo. ((conditional, string) The text that should be Base64 encoded. Required unless providing a value for the URL input.)51 """52 super(Base64EncodeInputSet, self)._set_input('Text', value)53 def set_URL(self, value):54 """55 Set the value of the URL input for this Choreo. ((conditional, string) A URL to a hosted file that should be Base64 encoded. Required unless providing a value for the Text input.)56 """57 super(Base64EncodeInputSet, self)._set_input('URL', value)58class Base64EncodeResultSet(ResultSet):59 """60 A ResultSet with methods tailored to the values returned by the Base64Encode Choreo.61 The ResultSet object is used to retrieve the results of a Choreo execution.62 """63 def getJSONFromString(self, str):64 return json.loads(str)65 def get_Base64EncodedText(self):66 """67 Retrieve the value for the "Base64EncodedText" output from this Choreo execution. ((string) The Base64 encoded text.)68 """69 return self._output.get('Base64EncodedText', None)70class Base64EncodeChoreographyExecution(ChoreographyExecution):71 def _make_result_set(self, response, path):...
test_encoding.py
Source:test_encoding.py
1# -*- coding: utf-8 -*-2from tests.helpers import *3from CTFd.utils.encoding import base64encode, base64decode, hexdecode, hexencode4import string5import six6def test_hexencode():7 value = '303132333435363738396162636465666768696a6b6c6d6e6f7071727374757677' \8 '78797a4142434445464748494a4b4c4d4e4f505152535455565758595a21222324' \9 '25262728292a2b2c2d2e2f3a3b3c3d3e3f405b5c5d5e5f607b7c7d7e20090a0d0b0c'10 if six.PY3:11 value = value.encode('utf-8')12 assert hexencode(string.printable) == value13def test_hexdecode():14 saved = '303132333435363738396162636465666768696a6b6c6d6e6f7071727374757677' \15 '78797a4142434445464748494a4b4c4d4e4f505152535455565758595a21222324' \16 '25262728292a2b2c2d2e2f3a3b3c3d3e3f405b5c5d5e5f607b7c7d7e20090a0d0b0c'17 assert hexdecode(saved) == string.printable.encode('utf-8')18def test_base64encode():19 """The base64encode wrapper works properly"""20 if six.PY2:21 assert base64encode('abc123') == 'YWJjMTIz'22 assert base64encode(unicode('abc123')) == 'YWJjMTIz'23 assert base64encode(unicode('"test@mailinator.com".DGxeoA.lCssU3M2QuBfohO-FtdgDQLKbU4')24 ) == 'InRlc3RAbWFpbGluYXRvci5jb20iLkRHeGVvQS5sQ3NzVTNNMlF1QmZvaE8tRnRkZ0RRTEtiVTQ'25 assert base64encode('user+user@ctfd.io') == 'dXNlcit1c2VyQGN0ZmQuaW8'26 assert base64encode('ð') == '8J-Yhg'27 else:28 assert base64encode('abc123') == 'YWJjMTIz'29 assert base64encode(30 '"test@mailinator.com".DGxeoA.lCssU3M2QuBfohO-FtdgDQLKbU4') == 'InRlc3RAbWFpbGluYXRvci5jb20iLkRHeGVvQS5sQ3NzVTNNMlF1QmZvaE8tRnRkZ0RRTEtiVTQ'31 assert base64encode('user+user@ctfd.io') == 'dXNlcit1c2VyQGN0ZmQuaW8'32 assert base64encode('ð') == '8J-Yhg'33def test_base64decode():34 """The base64decode wrapper works properly"""35 if six.PY2:36 assert base64decode('YWJjMTIz') == 'abc123'37 assert base64decode(unicode('YWJjMTIz')) == 'abc123'38 assert base64decode(unicode('InRlc3RAbWFpbGluYXRvci5jb20iLkRHeGVvQS5sQ3NzVTNNMlF1QmZvaE8tRnRkZ0RRTEtiVTQ')39 ) == '"test@mailinator.com".DGxeoA.lCssU3M2QuBfohO-FtdgDQLKbU4'40 assert base64decode('8J-Yhg') == 'ð'41 else:42 assert base64decode('YWJjMTIz') == 'abc123'43 assert base64decode(44 'InRlc3RAbWFpbGluYXRvci5jb20iLkRHeGVvQS5sQ3NzVTNNMlF1QmZvaE8tRnRkZ0RRTEtiVTQ') == '"test@mailinator.com".DGxeoA.lCssU3M2QuBfohO-FtdgDQLKbU4'45 assert base64decode('dXNlcit1c2VyQGN0ZmQuaW8') == 'user+user@ctfd.io'...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!