<s> """<STR_LIT>""" <EOL> __docformat__ = '<STR_LIT>' <EOL> import re <EOL> import codecs <EOL> import sys <EOL> from docutils import nodes <EOL> from docutils . parsers . rst . languages import en as _fallback_language_module <EOL> if sys . version_info < ( <NUM_LIT:2> , <NUM_LIT:5> ) : <EOL> from docutils . _compat import __import__ <EOL> _directive_registry = { <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT:code>' : ( '<STR_LIT:body>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT:error>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT:body>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT:body>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT:body>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT:body>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT:body>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT:body>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT:body>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT:body>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT:body>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT:body>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT:body>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT:image>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT:html>' , '<STR_LIT:Meta>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT:replace>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT:class>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT:title>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT:date>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , } <EOL> """<STR_LIT>""" <EOL> _directives = { } <EOL> """<STR_LIT>""" <EOL> def directive ( directive_name , language_module , document ) : <EOL> """<STR_LIT>""" <EOL> normname = directive_name . lower ( ) <EOL> messages = [ ] <EOL> msg_text = [ ] <EOL> if normname in _directives : <EOL> return _directives [ normname ] , messages <EOL> canonicalname = None <EOL> try : <EOL> canonicalname = language_module . directives [ normname ] <EOL> except AttributeError , error : <EOL> msg_text . append ( '<STR_LIT>' <EOL> '<STR_LIT>' % ( language_module , error ) ) <EOL> except KeyError : <EOL> msg_text . append ( '<STR_LIT>' <EOL> % ( directive_name , language_module . __name__ ) ) <EOL> if not canonicalname : <EOL> try : <EOL> canonicalname = _fallback_language_module . directives [ normname ] <EOL> msg_text . append ( '<STR_LIT>' <EOL> % directive_name ) <EOL> except KeyError : <EOL> msg_text . append ( '<STR_LIT>' <EOL> % directive_name ) <EOL> canonicalname = normname <EOL> if msg_text : <EOL> message = document . reporter . info ( <EOL> '<STR_LIT:\n>' . join ( msg_text ) , line = document . current_line ) <EOL> messages . append ( message ) <EOL> try : <EOL> modulename , classname = _directive_registry [ canonicalname ] <EOL> except KeyError : <EOL> return None , messages <EOL> try : <EOL> module = __import__ ( modulename , globals ( ) , locals ( ) , level = <NUM_LIT:1> ) <EOL> except ImportError , detail : <EOL> messages . append ( document . reporter . error ( <EOL> '<STR_LIT>' <EOL> % ( modulename , directive_name , detail ) , <EOL> line = document . current_line ) ) <EOL> return None , messages <EOL> try : <EOL> directive = getattr ( module , classname ) <EOL> _directives [ normname ] = directive <EOL> except AttributeError : <EOL> messages . append ( document . reporter . error ( <EOL> '<STR_LIT>' <EOL> % ( classname , modulename , directive_name ) , <EOL> line = document . current_line ) ) <EOL> return None , messages <EOL> return directive , messages <EOL> def register_directive ( name , directive ) : <EOL> """<STR_LIT>""" <EOL> _directives [ name ] = directive <EOL> def flag ( argument ) : <EOL> """<STR_LIT>""" <EOL> if argument and argument . strip ( ) : <EOL> raise ValueError ( '<STR_LIT>' % argument ) <EOL> else : <EOL> return None <EOL> def unchanged_required ( argument ) : <EOL> """<STR_LIT>""" <EOL> if argument is None : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> else : <EOL> return argument <EOL> def unchanged ( argument ) : <EOL> """<STR_LIT>""" <EOL> if argument is None : <EOL> return u'<STR_LIT>' <EOL> else : <EOL> return argument <EOL> def path ( argument ) : <EOL> """<STR_LIT>""" <EOL> if argument is None : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> else : <EOL> path = '<STR_LIT>' . join ( [ s . strip ( ) for s in argument . splitlines ( ) ] ) <EOL> return path <EOL> def uri ( argument ) : <EOL> """<STR_LIT>""" <EOL> if argument is None : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> else : <EOL> uri = '<STR_LIT>' . join ( argument . split ( ) ) <EOL> return uri <EOL> def nonnegative_int ( argument ) : <EOL> """<STR_LIT>""" <EOL> value = int ( argument ) <EOL> if value < <NUM_LIT:0> : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> return value <EOL> def percentage ( argument ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> argument = argument . rstrip ( '<STR_LIT>' ) <EOL> except AttributeError : <EOL> pass <EOL> return nonnegative_int ( argument ) <EOL> length_units = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> def get_measure ( argument , units ) : <EOL> """<STR_LIT>""" <EOL> match = re . match ( r'<STR_LIT>' % '<STR_LIT:|>' . join ( units ) , argument ) <EOL> try : <EOL> float ( match . group ( <NUM_LIT:1> ) ) <EOL> except ( AttributeError , ValueError ) : <EOL> raise ValueError ( <EOL> '<STR_LIT>' <EOL> % '<STR_LIT:U+0020>' . join ( [ '<STR_LIT>' % i for i in units ] ) ) <EOL> return match . group ( <NUM_LIT:1> ) + match . group ( <NUM_LIT:2> ) <EOL> def length_or_unitless ( argument ) : <EOL> return get_measure ( argument , length_units + [ '<STR_LIT>' ] ) <EOL> def length_or_percentage_or_unitless ( argument , default = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return get_measure ( argument , length_units + [ '<STR_LIT:%>' ] ) <EOL> except ValueError : <EOL> try : <EOL> return get_measure ( argument , [ '<STR_LIT>' ] ) + default <EOL> except ValueError : <EOL> return get_measure ( argument , length_units + [ '<STR_LIT:%>' ] ) <EOL> def class_option ( argument ) : <EOL> """<STR_LIT>""" <EOL> if argument is None : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> names = argument . split ( ) <EOL> class_names = [ ] <EOL> for name in names : <EOL> class_name = nodes . make_id ( name ) <EOL> if not class_name : <EOL> raise ValueError ( '<STR_LIT>' % name ) <EOL> class_names . append ( class_name ) <EOL> return class_names <EOL> unicode_pattern = re . compile ( <EOL> r'<STR_LIT>' , re . IGNORECASE ) <EOL> def unicode_code ( code ) : <EOL> r"""<STR_LIT>""" <EOL> try : <EOL> if code . isdigit ( ) : <EOL> return unichr ( int ( code ) ) <EOL> else : <EOL> match = unicode_pattern . match ( code ) <EOL> if match : <EOL> value = match . group ( <NUM_LIT:1> ) or match . group ( <NUM_LIT:2> ) <EOL> return unichr ( int ( value , <NUM_LIT:16> ) ) <EOL> else : <EOL> return code <EOL> except OverflowError , detail : <EOL> raise ValueError ( '<STR_LIT>' % detail ) <EOL> def single_char_or_unicode ( argument ) : <EOL> """<STR_LIT>""" <EOL> char = unicode_code ( argument ) <EOL> if len ( char ) > <NUM_LIT:1> : <EOL> raise ValueError ( '<STR_LIT>' <EOL> '<STR_LIT>' % char ) <EOL> return char <EOL> def single_char_or_whitespace_or_unicode ( argument ) : <EOL> """<STR_LIT>""" <EOL> if argument == '<STR_LIT>' : <EOL> char = '<STR_LIT:\t>' <EOL> elif argument == '<STR_LIT>' : <EOL> char = '<STR_LIT:U+0020>' <EOL> else : <EOL> char = single_char_or_unicode ( argument ) <EOL> return char <EOL> def positive_int ( argument ) : <EOL> """<STR_LIT>""" <EOL> value = int ( argument ) <EOL> if value < <NUM_LIT:1> : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> return value <EOL> def positive_int_list ( argument ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT:U+002C>' in argument : <EOL> entries = argument . split ( '<STR_LIT:U+002C>' ) <EOL> else : <EOL> entries = argument . split ( ) <EOL> return [ positive_int ( entry ) for entry in entries ] <EOL> def encoding ( argument ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> codecs . lookup ( argument ) <EOL> except LookupError : <EOL> raise ValueError ( '<STR_LIT>' % argument ) <EOL> return argument <EOL> def choice ( argument , values ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> value = argument . lower ( ) . strip ( ) <EOL> except AttributeError : <EOL> raise ValueError ( '<STR_LIT>' <EOL> % format_values ( values ) ) <EOL> if value in values : <EOL> return value <EOL> else : <EOL> raise ValueError ( '<STR_LIT>' <EOL> % ( argument , format_values ( values ) ) ) <EOL> def format_values ( values ) : <EOL> return '<STR_LIT>' % ( '<STR_LIT:U+002CU+0020>' . join ( [ '<STR_LIT>' % s for s in values [ : - <NUM_LIT:1> ] ] ) , <EOL> values [ - <NUM_LIT:1> ] ) </s>
