<s> import cgi <EOL> import six <EOL> import re <EOL> from six . moves import html_entities <EOL> from six . moves . urllib . parse import quote , unquote <EOL> __all__ = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> default_encoding = '<STR_LIT>' <EOL> def html_quote ( v , encoding = None ) : <EOL> r"""<STR_LIT>""" <EOL> encoding = encoding or default_encoding <EOL> if v is None : <EOL> return '<STR_LIT>' <EOL> elif isinstance ( v , six . binary_type ) : <EOL> return cgi . escape ( v , <NUM_LIT:1> ) <EOL> elif isinstance ( v , six . text_type ) : <EOL> if six . PY3 : <EOL> return cgi . escape ( v , <NUM_LIT:1> ) <EOL> else : <EOL> return cgi . escape ( v . encode ( encoding ) , <NUM_LIT:1> ) <EOL> else : <EOL> if six . PY3 : <EOL> return cgi . escape ( six . text_type ( v ) , <NUM_LIT:1> ) <EOL> else : <EOL> return cgi . escape ( six . text_type ( v ) . encode ( encoding ) , <NUM_LIT:1> ) <EOL> _unquote_re = re . compile ( r'<STR_LIT>' ) <EOL> def _entity_subber ( match , name2c = html_entities . name2codepoint ) : <EOL> code = name2c . get ( match . group ( <NUM_LIT:1> ) ) <EOL> if code : <EOL> return six . unichr ( code ) <EOL> else : <EOL> return match . group ( <NUM_LIT:0> ) <EOL> def html_unquote ( s , encoding = None ) : <EOL> r"""<STR_LIT>""" <EOL> if isinstance ( s , six . binary_type ) : <EOL> s = s . decode ( encoding or default_encoding ) <EOL> return _unquote_re . sub ( _entity_subber , s ) <EOL> def strip_html ( s ) : <EOL> s = re . sub ( '<STR_LIT>' , '<STR_LIT>' , s ) <EOL> s = html_unquote ( s ) <EOL> return s <EOL> def no_quote ( s ) : <EOL> """<STR_LIT>""" <EOL> return s <EOL> _comment_quote_re = re . compile ( r'<STR_LIT>' ) <EOL> _bad_chars_re = re . compile ( '<STR_LIT>' ) <EOL> def comment_quote ( s ) : <EOL> """<STR_LIT>""" <EOL> comment = str ( s ) <EOL> comment = _comment_quote_re . sub ( '<STR_LIT>' , comment ) <EOL> return comment <EOL> url_quote = quote <EOL> url_unquote = unquote <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> import doctest <EOL> doctest . testmod ( ) </s>
