import base64 from Custom import CustomBase import API class base64urlencode (CustomBase): stack = None def __init__(self, stack): self.stack = stack # __init__ def help(self): # This needs the language files in %userprofile%\taRpnCalcSG\customFunctions.translations\ API.showPopup('Custom function', API.t(API.programName+'.CustomFunctions.base64urlencode.btnHLP'), font=('Courier',API.helpFontSize)) # help def calculate(self): if self.stack.inputMode != 'TEXT': # This needs the language files in %userprofile%\taRpnCalcSG\customFunctions.translations\ API.toast(API.t(API.programName+'.CustomFunctions.onlySupportedInTEXT')) return if self.stack.finishEntry() == -1: return # abort here because data in input line is invalid if self.stack.size() < 1: # This needs the language files in %userprofile%\taRpnCalcSG\customFunctions.translations\ API.toast(API.t(API.programName+'.CustomFunctions.argumentsNeeded', count=1)) return x = str(self.stack.getRegister(0)) b64 = base64.urlsafe_b64encode(x.encode('utf-8')) self.stack.pop(1) self.stack.push(b64.decode('utf-8')) # calculate # base64urlencode