<s> import os <EOL> import boto3 <EOL> from botocore . exceptions import DataNotFoundError <EOL> from botocore . docs . service import ServiceDocumenter as BaseServiceDocumenter <EOL> from botocore . docs . bcdoc . restdoc import DocumentStructure <EOL> from boto3 . utils import ServiceContext <EOL> from boto3 . docs . client import Boto3ClientDocumenter <EOL> from boto3 . docs . resource import ResourceDocumenter <EOL> from boto3 . docs . resource import ServiceResourceDocumenter <EOL> class ServiceDocumenter ( BaseServiceDocumenter ) : <EOL> EXAMPLE_PATH = os . path . join ( os . path . dirname ( boto3 . __file__ ) , '<STR_LIT>' ) <EOL> def __init__ ( self , service_name , session ) : <EOL> self . _service_name = service_name <EOL> self . _boto3_session = session <EOL> self . _session = session . _session <EOL> self . _client = self . _boto3_session . client ( service_name ) <EOL> self . _service_resource = None <EOL> if self . _service_name in self . _boto3_session . get_available_resources ( ) : <EOL> self . _service_resource = self . _boto3_session . resource ( service_name ) <EOL> self . sections = [ <EOL> '<STR_LIT:title>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> def document_service ( self ) : <EOL> """<STR_LIT>""" <EOL> doc_structure = DocumentStructure ( <EOL> self . _service_name , section_names = self . sections , <EOL> target = '<STR_LIT:html>' ) <EOL> self . title ( doc_structure . get_section ( '<STR_LIT:title>' ) ) <EOL> self . table_of_contents ( doc_structure . get_section ( '<STR_LIT>' ) ) <EOL> self . client_api ( doc_structure . get_section ( '<STR_LIT>' ) ) <EOL> self . paginator_api ( doc_structure . get_section ( '<STR_LIT>' ) ) <EOL> self . waiter_api ( doc_structure . get_section ( '<STR_LIT>' ) ) <EOL> if self . _service_resource : <EOL> self . _document_service_resource ( <EOL> doc_structure . get_section ( '<STR_LIT>' ) ) <EOL> self . _document_resources ( doc_structure . get_section ( '<STR_LIT>' ) ) <EOL> self . _document_examples ( doc_structure . get_section ( '<STR_LIT>' ) ) <EOL> return doc_structure . flush_structure ( ) <EOL> def client_api ( self , section ) : <EOL> examples = None <EOL> try : <EOL> examples = self . get_examples ( self . _service_name ) <EOL> except DataNotFoundError : <EOL> pass <EOL> Boto3ClientDocumenter ( self . _client , examples ) . document_client ( section ) <EOL> def _document_service_resource ( self , section ) : <EOL> ServiceResourceDocumenter ( <EOL> self . _service_resource , self . _session ) . document_resource ( <EOL> section ) <EOL> def _document_resources ( self , section ) : <EOL> temp_identifier_value = '<STR_LIT:foo>' <EOL> loader = self . _session . get_component ( '<STR_LIT>' ) <EOL> json_resource_model = loader . load_service_model ( <EOL> self . _service_name , '<STR_LIT>' ) <EOL> service_model = self . _service_resource . meta . client . meta . service_model <EOL> for resource_name in json_resource_model [ '<STR_LIT>' ] : <EOL> resource_model = json_resource_model [ '<STR_LIT>' ] [ resource_name ] <EOL> resource_cls = self . _boto3_session . resource_factory . load_from_definition ( <EOL> resource_name = resource_name , <EOL> single_resource_json_definition = resource_model , <EOL> service_context = ServiceContext ( <EOL> service_name = self . _service_name , <EOL> resource_json_definitions = json_resource_model [ <EOL> '<STR_LIT>' ] , <EOL> service_model = service_model , <EOL> service_waiter_model = None <EOL> ) <EOL> ) <EOL> identifiers = resource_cls . meta . resource_model . identifiers <EOL> args = [ ] <EOL> for _ in identifiers : <EOL> args . append ( temp_identifier_value ) <EOL> resource = resource_cls ( * args , client = self . _client ) <EOL> ResourceDocumenter ( <EOL> resource , self . _session ) . document_resource ( <EOL> section . add_new_section ( resource . meta . resource_model . name ) ) <EOL> def _get_example_file ( self ) : <EOL> return os . path . realpath ( <EOL> os . path . join ( self . EXAMPLE_PATH , <EOL> self . _service_name + '<STR_LIT>' ) ) <EOL> def _document_examples ( self , section ) : <EOL> examples_file = self . _get_example_file ( ) <EOL> if os . path . isfile ( examples_file ) : <EOL> section . style . h2 ( '<STR_LIT>' ) <EOL> section . style . new_line ( ) <EOL> section . write ( "<STR_LIT>" ) <EOL> section . style . new_line ( ) <EOL> section . style . new_line ( ) <EOL> with open ( examples_file , '<STR_LIT:r>' ) as f : <EOL> section . write ( f . read ( ) ) </s>
