<s> """<STR_LIT>""" <EOL> from docutils import nodes , utils <EOL> from docutils . parsers . rst import roles <EOL> def ticket_role ( name , rawtext , text , lineno , inliner , options = None , content = None ) : <EOL> if options is None : <EOL> options = { } <EOL> try : <EOL> num = int ( text . replace ( '<STR_LIT:#>' , '<STR_LIT>' ) ) <EOL> except ValueError : <EOL> msg = inliner . reporter . error ( <EOL> "<STR_LIT>" % text ) <EOL> prb = inliner . problematic ( rawtext , rawtext , msg ) <EOL> return [ prb ] , [ msg ] <EOL> url_pattern = inliner . document . settings . env . app . config . ticket_url <EOL> if url_pattern is None : <EOL> msg = inliner . reporter . warning ( <EOL> "<STR_LIT>" ) <EOL> prb = inliner . problematic ( rawtext , rawtext , msg ) <EOL> return [ prb ] , [ msg ] <EOL> url = url_pattern % num <EOL> roles . set_classes ( options ) <EOL> node = nodes . reference ( rawtext , '<STR_LIT:#>' + utils . unescape ( text ) , refuri = url , ** options ) <EOL> return [ node ] , [ ] <EOL> def setup ( app ) : <EOL> app . add_config_value ( '<STR_LIT>' , None , '<STR_LIT>' ) <EOL> app . add_role ( '<STR_LIT>' , ticket_role ) </s>
