<s> """<STR_LIT>""" <EOL> import re <EOL> import sys <EOL> split_path_re = re . compile ( r'<STR_LIT>' ) <EOL> doctype_lookup_re = re . compile ( r'''<STR_LIT>''' ) <EOL> tag_re = re . compile ( r'<STR_LIT>' ) <EOL> xml_decl_re = re . compile ( r'<STR_LIT>' , re . I ) <EOL> class ClassNotFound ( ValueError ) : <EOL> """<STR_LIT>""" <EOL> class OptionError ( Exception ) : <EOL> pass <EOL> def get_choice_opt ( options , optname , allowed , default = None , normcase = False ) : <EOL> string = options . get ( optname , default ) <EOL> if normcase : <EOL> string = string . lower ( ) <EOL> if string not in allowed : <EOL> raise OptionError ( '<STR_LIT>' % <EOL> ( optname , '<STR_LIT:U+002CU+0020>' . join ( map ( str , allowed ) ) ) ) <EOL> return string <EOL> def get_bool_opt ( options , optname , default = None ) : <EOL> string = options . get ( optname , default ) <EOL> if isinstance ( string , bool ) : <EOL> return string <EOL> elif isinstance ( string , int ) : <EOL> return bool ( string ) <EOL> elif not isinstance ( string , string_types ) : <EOL> raise OptionError ( '<STR_LIT>' <EOL> '<STR_LIT>' % ( <EOL> string , optname ) ) <EOL> elif string . lower ( ) in ( '<STR_LIT:1>' , '<STR_LIT:yes>' , '<STR_LIT:true>' , '<STR_LIT>' ) : <EOL> return True <EOL> elif string . lower ( ) in ( '<STR_LIT:0>' , '<STR_LIT>' , '<STR_LIT:false>' , '<STR_LIT>' ) : <EOL> return False <EOL> else : <EOL> raise OptionError ( '<STR_LIT>' <EOL> '<STR_LIT>' % ( <EOL> string , optname ) ) <EOL> def get_int_opt ( options , optname , default = None ) : <EOL> string = options . get ( optname , default ) <EOL> try : <EOL> return int ( string ) <EOL> except TypeError : <EOL> raise OptionError ( '<STR_LIT>' <EOL> '<STR_LIT>' % ( <EOL> string , optname ) ) <EOL> except ValueError : <EOL> raise OptionError ( '<STR_LIT>' <EOL> '<STR_LIT>' % ( <EOL> string , optname ) ) <EOL> def get_list_opt ( options , optname , default = None ) : <EOL> val = options . get ( optname , default ) <EOL> if isinstance ( val , string_types ) : <EOL> return val . split ( ) <EOL> elif isinstance ( val , ( list , tuple ) ) : <EOL> return list ( val ) <EOL> else : <EOL> raise OptionError ( '<STR_LIT>' <EOL> '<STR_LIT>' % ( <EOL> val , optname ) ) <EOL> def docstring_headline ( obj ) : <EOL> if not obj . __doc__ : <EOL> return '<STR_LIT>' <EOL> res = [ ] <EOL> for line in obj . __doc__ . strip ( ) . splitlines ( ) : <EOL> if line . strip ( ) : <EOL> res . append ( "<STR_LIT:U+0020>" + line . strip ( ) ) <EOL> else : <EOL> break <EOL> return '<STR_LIT>' . join ( res ) . lstrip ( ) <EOL> def make_analysator ( f ) : <EOL> """<STR_LIT>""" <EOL> def text_analyse ( text ) : <EOL> try : <EOL> rv = f ( text ) <EOL> except Exception : <EOL> return <NUM_LIT:0.0> <EOL> if not rv : <EOL> return <NUM_LIT:0.0> <EOL> try : <EOL> return min ( <NUM_LIT:1.0> , max ( <NUM_LIT:0.0> , float ( rv ) ) ) <EOL> except ( ValueError , TypeError ) : <EOL> return <NUM_LIT:0.0> <EOL> text_analyse . __doc__ = f . __doc__ <EOL> return staticmethod ( text_analyse ) <EOL> def shebang_matches ( text , regex ) : <EOL> """<STR_LIT>""" <EOL> index = text . find ( '<STR_LIT:\n>' ) <EOL> if index >= <NUM_LIT:0> : <EOL> first_line = text [ : index ] . lower ( ) <EOL> else : <EOL> first_line = text . lower ( ) <EOL> if first_line . startswith ( '<STR_LIT>' ) : <EOL> try : <EOL> found = [ x for x in split_path_re . split ( first_line [ <NUM_LIT:2> : ] . strip ( ) ) <EOL> if x and not x . startswith ( '<STR_LIT:->' ) ] [ - <NUM_LIT:1> ] <EOL> except IndexError : <EOL> return False <EOL> regex = re . compile ( '<STR_LIT>' % regex , re . IGNORECASE ) <EOL> if regex . search ( found ) is not None : <EOL> return True <EOL> return False <EOL> def doctype_matches ( text , regex ) : <EOL> """<STR_LIT>""" <EOL> m = doctype_lookup_re . match ( text ) <EOL> if m is None : <EOL> return False <EOL> doctype = m . group ( <NUM_LIT:2> ) <EOL> return re . compile ( regex , re . I ) . match ( doctype . strip ( ) ) is not None <EOL> def html_doctype_matches ( text ) : <EOL> """<STR_LIT>""" <EOL> return doctype_matches ( text , r'<STR_LIT:html>' ) <EOL> _looks_like_xml_cache = { } <EOL> def looks_like_xml ( text ) : <EOL> """<STR_LIT>""" <EOL> if xml_decl_re . match ( text ) : <EOL> return True <EOL> key = hash ( text ) <EOL> try : <EOL> return _looks_like_xml_cache [ key ] <EOL> except KeyError : <EOL> m = doctype_lookup_re . match ( text ) <EOL> if m is not None : <EOL> return True <EOL> rv = tag_re . search ( text [ : <NUM_LIT:1000> ] ) is not None <EOL> _looks_like_xml_cache [ key ] = rv <EOL> return rv <EOL> def _surrogatepair ( c ) : <EOL> return ( <NUM_LIT> + ( c >> <NUM_LIT:10> ) , ( <NUM_LIT> + ( c & <NUM_LIT> ) ) ) <EOL> def unirange ( a , b ) : <EOL> """<STR_LIT>""" <EOL> if b < a : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if a < <NUM_LIT> or b < <NUM_LIT> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if sys . maxunicode > <NUM_LIT> : <EOL> return u'<STR_LIT>' % ( unichr ( a ) , unichr ( b ) ) <EOL> else : <EOL> ah , al = _surrogatepair ( a ) <EOL> bh , bl = _surrogatepair ( b ) <EOL> if ah == bh : <EOL> return u'<STR_LIT>' % ( unichr ( ah ) , unichr ( al ) , unichr ( bl ) ) <EOL> else : <EOL> buf = [ ] <EOL> buf . append ( u'<STR_LIT>' % <EOL> ( unichr ( ah ) , unichr ( al ) , <EOL> ah == bh and unichr ( bl ) or unichr ( <NUM_LIT> ) ) ) <EOL> if ah - bh > <NUM_LIT:1> : <EOL> buf . append ( u'<STR_LIT>' % <EOL> unichr ( ah + <NUM_LIT:1> ) , unichr ( bh - <NUM_LIT:1> ) , unichr ( <NUM_LIT> ) , unichr ( <NUM_LIT> ) ) <EOL> if ah != bh : <EOL> buf . append ( u'<STR_LIT>' % <EOL> ( unichr ( bh ) , unichr ( <NUM_LIT> ) , unichr ( bl ) ) ) <EOL> return u'<STR_LIT>' + u'<STR_LIT:|>' . join ( buf ) + u'<STR_LIT:)>' <EOL> def format_lines ( var_name , seq , raw = False , indent_level = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> lines = [ ] <EOL> base_indent = '<STR_LIT:U+0020>' * indent_level * <NUM_LIT:4> <EOL> inner_indent = '<STR_LIT:U+0020>' * ( indent_level + <NUM_LIT:1> ) * <NUM_LIT:4> <EOL> lines . append ( base_indent + var_name + '<STR_LIT>' ) <EOL> if raw : <EOL> for i in seq : <EOL> lines . append ( inner_indent + i + '<STR_LIT:U+002C>' ) <EOL> else : <EOL> for i in seq : <EOL> r = repr ( i + '<STR_LIT:">' ) <EOL> lines . append ( inner_indent + r [ : - <NUM_LIT:2> ] + r [ - <NUM_LIT:1> ] + '<STR_LIT:U+002C>' ) <EOL> lines . append ( base_indent + '<STR_LIT:)>' ) <EOL> return '<STR_LIT:\n>' . join ( lines ) <EOL> def duplicates_removed ( it , already_seen = ( ) ) : <EOL> """<STR_LIT>""" <EOL> lst = [ ] <EOL> seen = set ( ) <EOL> for i in it : <EOL> if i in seen or i in already_seen : <EOL> continue <EOL> lst . append ( i ) <EOL> seen . add ( i ) <EOL> return lst <EOL> class Future ( object ) : <EOL> """<STR_LIT>""" <EOL> def get ( self ) : <EOL> raise NotImplementedError <EOL> def guess_decode ( text ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> text = text . decode ( '<STR_LIT:utf-8>' ) <EOL> return text , '<STR_LIT:utf-8>' <EOL> except UnicodeDecodeError : <EOL> try : <EOL> import locale <EOL> prefencoding = locale . getpreferredencoding ( ) <EOL> text = text . decode ( ) <EOL> return text , prefencoding <EOL> except ( UnicodeDecodeError , LookupError ) : <EOL> text = text . decode ( '<STR_LIT>' ) <EOL> return text , '<STR_LIT>' <EOL> def guess_decode_from_terminal ( text , term ) : <EOL> """<STR_LIT>""" <EOL> if getattr ( term , '<STR_LIT>' , None ) : <EOL> try : <EOL> text = text . decode ( term . encoding ) <EOL> except UnicodeDecodeError : <EOL> pass <EOL> else : <EOL> return text , term . encoding <EOL> return guess_decode ( text ) <EOL> def terminal_encoding ( term ) : <EOL> """<STR_LIT>""" <EOL> if getattr ( term , '<STR_LIT>' , None ) : <EOL> return term . encoding <EOL> import locale <EOL> return locale . getpreferredencoding ( ) <EOL> if sys . version_info < ( <NUM_LIT:3> , <NUM_LIT:0> ) : <EOL> unichr = unichr <EOL> xrange = xrange <EOL> string_types = ( str , unicode ) <EOL> text_type = unicode <EOL> u_prefix = '<STR_LIT:u>' <EOL> iteritems = dict . iteritems <EOL> itervalues = dict . itervalues <EOL> import StringIO <EOL> import cStringIO <EOL> StringIO = StringIO . StringIO <EOL> BytesIO = cStringIO . StringIO <EOL> else : <EOL> unichr = chr <EOL> xrange = range <EOL> string_types = ( str , ) <EOL> text_type = str <EOL> u_prefix = '<STR_LIT>' <EOL> iteritems = dict . items <EOL> itervalues = dict . values <EOL> from io import StringIO , BytesIO , TextIOWrapper <EOL> class UnclosingTextIOWrapper ( TextIOWrapper ) : <EOL> def close ( self ) : <EOL> pass <EOL> def add_metaclass ( metaclass ) : <EOL> """<STR_LIT>""" <EOL> def wrapper ( cls ) : <EOL> orig_vars = cls . __dict__ . copy ( ) <EOL> orig_vars . pop ( '<STR_LIT>' , None ) <EOL> orig_vars . pop ( '<STR_LIT>' , None ) <EOL> for slots_var in orig_vars . get ( '<STR_LIT>' , ( ) ) : <EOL> orig_vars . pop ( slots_var ) <EOL> return metaclass ( cls . __name__ , cls . __bases__ , orig_vars ) <EOL> return wrapper </s>
