<s> """<STR_LIT>""" <EOL> from __future__ import with_statement <EOL> import os <EOL> import re <EOL> from flask import abort <EOL> from jinja2 import Markup <EOL> from docutils . core import publish_parts <EOL> config_parser_re = re . compile ( r"<STR_LIT>" , re . M ) <EOL> class rstDocument ( object ) : <EOL> def __init__ ( self , file_path ) : <EOL> self . file_path = file_path <EOL> self . file_name = "<STR_LIT:.>" . join ( os . path . basename ( self . file_path ) . split ( "<STR_LIT:.>" ) [ : - <NUM_LIT:1> ] ) <EOL> self . _config = None <EOL> self . _rst = None <EOL> if not os . path . isfile ( self . file_path ) : <EOL> abort ( <NUM_LIT> ) <EOL> with open ( self . file_path ) as f : <EOL> self . raw = f . read ( ) <EOL> @ property <EOL> def config ( self ) : <EOL> if not isinstance ( self . _config , dict ) : <EOL> self . _config = { } <EOL> for m in config_parser_re . finditer ( self . raw ) : <EOL> self . _config [ m . group ( <NUM_LIT:1> ) ] = eval ( m . group ( <NUM_LIT:2> ) ) <EOL> self . _config . setdefault ( '<STR_LIT>' , False ) <EOL> return self . _config <EOL> @ property <EOL> def rst ( self ) : <EOL> if not isinstance ( self . _rst , dict ) : <EOL> settings = { <EOL> '<STR_LIT>' : <NUM_LIT:2> <EOL> } <EOL> self . _rst = publish_parts ( source = self . raw , writer_name = '<STR_LIT>' , <EOL> settings_overrides = settings ) <EOL> return self . _rst <EOL> @ property <EOL> def title ( self ) : <EOL> return Markup ( self . rst [ '<STR_LIT:title>' ] ) . striptags ( ) <EOL> @ property <EOL> def body ( self ) : <EOL> return Markup ( self . rst [ '<STR_LIT>' ] ) <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( self . file_name ) </s>
