def generate(self,<EOL>secret,<EOL>type='<STR_LIT>',<EOL>account='<STR_LIT>',<EOL>issuer=None,<EOL>algo='<STR_LIT>',<EOL>digits=<NUM_LIT:6>,<EOL>init_counter=None):
args = {}<EOL>uri = '<STR_LIT>'<EOL>try:<EOL><INDENT>a = binascii.unhexlify(secret)<EOL>args[SECRET] = base64.b32encode(a).decode('<STR_LIT:ascii>')<EOL><DEDENT>except binascii.Error as ex:<EOL><INDENT>raise ValueError(str(ex))<EOL><DEDENT>except Exception as ex:<EOL><INDENT>print(ex)<EOL>raise ValueError('<STR_LIT>')<EOL><DEDENT>if type not in [TOTP, HOTP]:<EOL><INDENT>raise ValueError('<STR_LIT>',<EOL>type)<EOL><DEDENT>if type != TOTP:<EOL><INDENT>args['<STR_LIT:type>'] = type<EOL><DEDENT>if algo not in ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>raise ValueError('<STR_LIT>',<EOL>algo)<EOL><DEDENT>if algo != '<STR_LIT>':<EOL><INDENT>args['<STR_LIT>'] = algo<EOL><DEDENT>if init_counter is not None:<EOL><INDENT>if type != HOTP:<EOL><INDENT>raise ValueError('<STR_LIT>',<EOL>'<STR_LIT>')<EOL><DEDENT>if int(init_counter) < <NUM_LIT:0>:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>args[COUNTER] = int(init_counter)<EOL><DEDENT>digits = int(digits)<EOL>if digits != <NUM_LIT:6> and digits != <NUM_LIT:8>:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if digits != <NUM_LIT:6>:<EOL><INDENT>args[DIGITS] = digits<EOL><DEDENT>args[PERIOD] = <NUM_LIT:30><EOL>account = quote(account)<EOL>if issuer is not None:<EOL><INDENT>account = quote(issuer) + '<STR_LIT::>' + account<EOL>args[ISSUER] = issuer<EOL><DEDENT>uri = uri.format(type, account, urlencode(args).replace("<STR_LIT:+>", "<STR_LIT>"))<EOL>return uri<EOL>
https://github.com/google/google-authenticator/wiki/Key-Uri-Format