#!/usr/bin/python

"""
unsafe character:

in a regex (escape with \):
    . ^ $ * + - ? ( ) [ ] { } \ |
   
"""

def asciiTable():
    table = """
Space ! " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ?
    @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _
    ` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~ Del
"""
    print "from ascii : ", table
    return table.replace('\n',' ').split(" ")

def cookieUnsafeTable():
    table = """( ) < > @ , ; : \ " { } Space"""
    print "cookie need to escape : ", table
    return table.split(' ')


def urlUnsafeTable():
    table = """
    & $ + , / . ; : = ? @ #
    Space < > [ ] | \ ^ %
"""
    print "url need escape ", table
    return table.replace('\n',' ').split(' ')

def xmlSafeTable():
    table = """ " ' < > &"""
    print "xml need escape these : ",table
    return table.split(' ')

def regexSafeTable():
    table """    . ^ $ * + - ? ( ) [ ] { } \ |"""
    print "regex need escape", table
    return table.split(' ')

ascii = asciiTable()
cookie = cookieUnsafeTable()
url = urlUnsafeTable()
xml = xmlSafeTable()
regex = regexSafeTable()

safe = [ sym 
        for sym in ascii
        if not sym in cookie  
        if not sym in url
        if not sym in xml
        if not sym in regex
      ]

print safe , "are safe to use universally", "that make", len(safe),"symbol"

