random script dump
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.4 KiB

#!/usr/bin/env python
import argparse
import sys
class Domain(object):
def __init__(self, domain):
if sys.version_info[0] < 3:
domain = domain.decode('utf-8').encode('utf-8')
idna = domain.decode('utf-8').encode('idna')
self.ascii = idna
self.utf_8 = idna.decode('idna').encode('utf-8')
idna = bytes(domain, 'idna')
self.ascii = idna.decode('ascii')
self.utf_8 = idna.decode('idna')
if self.ascii == self.utf_8:
self.type = 'ascii'
self.utf_8 = None
if self.utf_8 == domain:
self.type = 'unicode'
self.type = 'punycode'
def display(self):
print('INPUT: \x1B[1m{}\x1B[0m\nASCII: \x1B[1m{}\x1B[0m'
.format(self.type, self.ascii))
if self.utf_8 is not None:
print('UTF-8: \x1B[1m{}\x1B[0m'.format(self.utf_8))
def parse_arguments():
"""Parse and store arguments."""
desc = 'A simple punycode to unicode and back converter.'
parser = argparse.ArgumentParser(description=desc)
parser.add_argument('domain', help='domain name to convert')
# Store the supplied args
return parser.parse_args()
def main(main_sysargs):
args = parse_arguments()
domain = Domain(args.domain)
if __name__ == '__main__':