All pastes #291779 Raw Edit

Untitled

public python v1 · immutable
#291779 ·published 2006-12-25 18:54 UTC
rendered paste body
import re,sys, urllib, osNames   = ['"', ''', '&', '<', '>', ' ', '¡', '¤', '¢', '£', '¥', '¦', '§', '¨', '©', 'ª', '«', '¬', '­', '®', '™', '¯', '°', '±', '²', '³', '´', 'µ', '¶', '·', '¸', '¹', 'º', '»', '¼', '½', '¾', '¿', '×', '÷', 'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'Þ', 'ß', 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ð', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'þ', 'ÿ', 'Œ', 'œ', 'Š', 'š', 'Ÿ', 'ˆ', '˜', ' ', ' ', ' ', '‌', '‍', '‎', '‏', '–', '—', '‘', '’', '‚', '“', '”', '„', '†', '‡', '…', '‰', '‹', '›', '€']Numbers = ['"', ''', '&', '<', '>', ' ', '¡', '¤', '¢', '£', '¥', '¦', '§', '¨', '©', 'ª', '«', '¬', '­', '®', '™', '¯', '°', '±', '²', '³', '´', 'µ', '¶', '·', '¸', '¹', 'º', '»', '¼', '½', '¾', '¿', '×', '÷', 'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'Þ', 'ß', 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ð', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'þ', 'ÿ', 'Œ', 'œ', 'Š', 'š', 'Ÿ', 'ˆ', '˜', ' ', ' ', ' ', '‌', '‍', '‎', '‏', '–', '—', '‘', '’', '‚', '“', '”', '„', '†', '‡', '…', '‰', '‹', '›', '€']def ConvertTypes(string, convertTo='Names'):    for names_with, numbers_with in zip(Names, Numbers):        if convertTo == 'Names':            if numbers_with in string: string = string.replace(numbers_with,names_with.replace(' ',''))        elif convertTo == 'Numbers':            if names_with in string: string = string.replace(names_with,numbers_with.replace(' ',''))        else: return 'Dumbass! Follow the options!'    return stringdef ConvertNumCodes(string):    for i in re.compile(r"&#[0-9]{1,4};").findall(string):        string = string.replace(i,'%c'%(int(i.replace('&#','').replace(';',''))))    return string# Test runs# =========toNums  = 'Ò, Ó, Õ, Ø, Í, È'toNames = 'Ò, Ó, Õ, Ø, Í, È'print '================================================================'print ''print 'Convert from alpha codes to numeric codes:'print '------------------------------------------\n'print 'from: ' + toNumsConverted = ConvertTypes(toNums,convertTo='Numbers')print 'To:   ' + Convertedprint ''print '================================================================'print ''print 'Convert from numeric codes to alpha codes:'print '------------------------------------------\n'print 'From: ' + toNamesConverted = ConvertTypes(toNames,convertTo='Names')print 'To:   ' + Convertedprint ''print '================================================================'print ''print 'Convert numeric codes to characters:'print '------------------------------------\n'print 'From: ' + toNamesCharacters = ConvertNumCodes(toNames)print 'To: ' + Charactersprint ''print '================================================================'