| 34 | |
| 35 | |
| 36 | class ClientDocumenter: |
| 37 | _CLIENT_METHODS_FILTERS = [ |
| 38 | _allowlist_generate_presigned_url, |
| 39 | ] |
| 40 | |
| 41 | def __init__(self, client, root_docs_path, shared_examples=None): |
| 42 | self._client = client |
| 43 | self._client_class_name = self._client.__class__.__name__ |
| 44 | self._root_docs_path = root_docs_path |
| 45 | self._shared_examples = shared_examples |
| 46 | if self._shared_examples is None: |
| 47 | self._shared_examples = {} |
| 48 | self._service_name = self._client.meta.service_model.service_name |
| 49 | |
| 50 | def document_client(self, section): |
| 51 | """Documents a client and its methods |
| 52 | |
| 53 | :param section: The section to write to. |
| 54 | """ |
| 55 | self._add_title(section) |
| 56 | self._add_class_signature(section) |
| 57 | client_methods = self._get_client_methods() |
| 58 | self._add_client_intro(section, client_methods) |
| 59 | self._add_client_methods(client_methods) |
| 60 | |
| 61 | def _get_client_methods(self): |
| 62 | client_methods = get_instance_public_methods(self._client) |
| 63 | return self._filter_client_methods(client_methods) |
| 64 | |
| 65 | def _filter_client_methods(self, client_methods): |
| 66 | filtered_methods = {} |
| 67 | for method_name, method in client_methods.items(): |
| 68 | include = self._filter_client_method( |
| 69 | method=method, |
| 70 | method_name=method_name, |
| 71 | service_name=self._service_name, |
| 72 | ) |
| 73 | if include: |
| 74 | filtered_methods[method_name] = method |
| 75 | return filtered_methods |
| 76 | |
| 77 | def _filter_client_method(self, **kwargs): |
| 78 | for filter in self._CLIENT_METHODS_FILTERS: |
| 79 | filter_include = filter(**kwargs) |
| 80 | if filter_include is not None: |
| 81 | return filter_include |
| 82 | return True |
| 83 | |
| 84 | def _add_title(self, section): |
| 85 | section.style.h2('Client') |
| 86 | |
| 87 | def _add_client_intro(self, section, client_methods): |
| 88 | section = section.add_new_section('intro') |
| 89 | # Write out the top level description for the client. |
| 90 | official_service_name = get_official_service_name( |
| 91 | self._client.meta.service_model |
| 92 | ) |
| 93 | section.write( |
no outgoing calls