<s> import sys <EOL> import re <EOL> def cleancss ( text ) : <EOL> text = re . compile ( '<STR_LIT>' ) . sub ( '<STR_LIT:U+0020>' , text ) <EOL> text = re . compile ( '<STR_LIT>' ) . sub ( '<STR_LIT>' , text ) <EOL> text = re . compile ( '<STR_LIT>' ) . sub ( '<STR_LIT>' , text ) <EOL> text = re . compile ( '<STR_LIT>' ) . sub ( '<STR_LIT>' , text ) <EOL> text = re . compile ( '<STR_LIT>' ) . sub ( '<STR_LIT>' , text ) <EOL> return text <EOL> def cleanhtml ( text ) : <EOL> text = text . lower ( ) <EOL> r = re . compile ( '<STR_LIT>' , re . DOTALL ) <EOL> scripts = r . findall ( text ) <EOL> text = r . sub ( '<STR_LIT>' , text ) <EOL> r = re . compile ( '<STR_LIT>' , re . DOTALL ) <EOL> styles = r . findall ( text ) <EOL> text = r . sub ( '<STR_LIT>' , text ) <EOL> text = re . compile ( <EOL> '<STR_LIT>' ) . sub ( '<STR_LIT>' , text ) <EOL> text = text . replace ( '<STR_LIT:\n>' , '<STR_LIT:U+0020>' ) <EOL> text = text . replace ( '<STR_LIT:>>' , '<STR_LIT>' ) <EOL> text = text . replace ( '<STR_LIT:<>' , '<STR_LIT>' ) <EOL> text = re . compile ( '<STR_LIT>' ) . sub ( '<STR_LIT:\n>' , text ) <EOL> lines = text . split ( '<STR_LIT:\n>' ) <EOL> ( indent , newlines ) = ( <NUM_LIT:0> , [ ] ) <EOL> for line in lines : <EOL> if line [ : <NUM_LIT:2> ] == '<STR_LIT>' : indent = indent - <NUM_LIT:1> <EOL> newlines . append ( indent * '<STR_LIT:U+0020>' + line ) <EOL> if not line [ : <NUM_LIT:2> ] == '<STR_LIT>' and line [ - <NUM_LIT:1> : ] == '<STR_LIT:>>' and not line [ - <NUM_LIT:2> : ] in [ '<STR_LIT>' , '<STR_LIT>' ] : indent = indent + <NUM_LIT:1> <EOL> text = '<STR_LIT:\n>' . join ( newlines ) <EOL> text = re . compile ( <EOL> '<STR_LIT>' ) . sub ( '<STR_LIT>' , text ) <EOL> text = re . compile ( '<STR_LIT>' ) . sub ( '<STR_LIT>' , text ) <EOL> text = re . compile ( '<STR_LIT>' ) . sub ( '<STR_LIT>' , text ) <EOL> text = re . compile ( '<STR_LIT>' ) . sub ( '<STR_LIT>' , text ) <EOL> text = re . compile ( '<STR_LIT>' ) . sub ( '<STR_LIT>' , text ) <EOL> text = re . compile ( '<STR_LIT>' ) . sub ( '<STR_LIT>' , text ) <EOL> text = re . compile ( '<STR_LIT>' ) . sub ( '<STR_LIT>' , text ) <EOL> text = re . compile ( '<STR_LIT>' ) . sub ( '<STR_LIT:\n>' , text ) <EOL> for script in scripts : <EOL> text = text . replace ( '<STR_LIT>' , script , <NUM_LIT:1> ) <EOL> for style in styles : <EOL> text = text . replace ( '<STR_LIT>' , cleancss ( style ) , <NUM_LIT:1> ) <EOL> return text <EOL> def read_file ( filename ) : <EOL> f = open ( filename , '<STR_LIT:r>' ) <EOL> try : <EOL> return f . read ( ) <EOL> finally : <EOL> f . close ( ) <EOL> file = sys . argv [ <NUM_LIT:1> ] <EOL> if file [ - <NUM_LIT:4> : ] == '<STR_LIT>' : <EOL> print cleancss ( read_file ( file ) ) <EOL> if file [ - <NUM_LIT:5> : ] == '<STR_LIT>' : <EOL> print cleanhtml ( read_file ( file ) ) </s>
