def _add_member_documentation( self, section, shape, name=None, is_top_level_param=False, is_required=False, **kwargs ): py_type = py_type_name(shape.type_name) if is_top_level_param: type_section = section.add_new_section("param-type") type_section.write(":type %s: %s" % (name, py_type)) end_type_section = type_section.add_new_section("end-param-type") end_type_section.style.new_line() name_section = section.add_new_section("param-name") name_section.write(":param %s: " % name) else: name_section = section.add_new_section("param-name") name_section.write("- ") if name is not None: name_section.style.bold("%s " % name) type_section = section.add_new_section("param-type") type_section.style.italics("(%s) -- " % py_type) if is_required: is_required_section = section.add_new_section("is-required") is_required_section.style.indent() is_required_section.style.bold("[REQUIRED] ") if shape.documentation: documentation_section = section.add_new_section("param-documentation") documentation_section.style.indent() documentation_section.include_doc_string(shape.documentation) end_param_section = section.add_new_section("end-param") end_param_section.style.new_paragraph()
def _add_member_documentation(self, section, shape, name=None, is_top_level_param=False, is_required=False, **kwargs): py_type = self._get_special_py_type_name(shape) if py_type is None: py_type = py_type_name(shape.type_name) if is_top_level_param: type_section = section.add_new_section('param-type') type_section.write(':type %s: %s' % (name, py_type)) end_type_section = type_section.add_new_section('end-param-type') end_type_section.style.new_line() name_section = section.add_new_section('param-name') name_section.write(':param %s: ' % name) else: name_section = section.add_new_section('param-name') name_section.write('- ') if name is not None: name_section.style.bold('%s ' % name) type_section = section.add_new_section('param-type') self._document_non_top_level_param_type(type_section, shape) if is_required: is_required_section = section.add_new_section('is-required') is_required_section.style.indent() is_required_section.style.bold('[REQUIRED] ') if shape.documentation: documentation_section = section.add_new_section( 'param-documentation') documentation_section.style.indent() documentation_section.include_doc_string(shape.documentation) self._add_special_trait_documentation(documentation_section, shape) end_param_section = section.add_new_section('end-param') end_param_section.style.new_paragraph()
def _add_attributes(self, section): service_model = self._resource.meta.client.meta.service_model attributes = {} if self._resource.meta.resource_model.shape: shape = service_model.shape_for(self._resource.meta.resource_model.shape) attributes = self._resource.meta.resource_model.get_attributes(shape) section = section.add_new_section("attributes") attribute_list = [] if attributes: add_resource_type_overview( section=section, resource_type="Attributes", description=( "Attributes provide access" " to the properties of a resource. Attributes are lazy-" "loaded the first time one is accessed via the" " :py:meth:`load` method." ), intro_link="identifiers_attributes_intro", ) self.member_map["attributes"] = attribute_list for attr_name in sorted(attributes): _, attr_shape = attributes[attr_name] attribute_section = section.add_new_section(attr_name) attribute_list.append(attr_name) attribute_section.style.start_sphinx_py_attr(attr_name) attr_type = "*(%s)* " % py_type_name(attr_shape.type_name) attribute_section.write(attr_type) attribute_section.include_doc_string(attr_shape.documentation)
def _add_attributes(self, section): service_model = self._resource.meta.client.meta.service_model attributes = {} if self._resource.meta.resource_model.shape: shape = service_model.shape_for( self._resource.meta.resource_model.shape) attributes = self._resource.meta.resource_model.get_attributes( shape) section = section.add_new_section('attributes') attribute_list = [] if attributes: add_resource_type_overview( section=section, resource_type='Attributes', description=( 'Attributes provide access' ' to the properties of a resource. Attributes are lazy-' 'loaded the first time one is accessed via the' ' :py:meth:`load` method.'), intro_link='identifiers_attributes_intro') self.member_map['attributes'] = attribute_list for attr_name, (_, attr_shape) in attributes.items(): attribute_section = section.add_new_section(attr_name) attribute_list.append(attr_name) attribute_section.style.start_sphinx_py_attr(attr_name) attr_type = '*(%s)* ' % py_type_name(attr_shape.type_name) attribute_section.write(attr_type) attribute_section.include_doc_string(attr_shape.documentation)
def _add_member_documentation(self, section, shape, name=None, is_top_level_param=False, is_required=False, **kwargs): py_type = py_type_name(shape.type_name) if is_top_level_param: type_section = section.add_new_section('param-type') type_section.write(':type %s: %s' % (name, py_type)) end_type_section = type_section.add_new_section('end-param-type') end_type_section.style.new_line() name_section = section.add_new_section('param-name') name_section.write(':param %s: ' % name) else: name_section = section.add_new_section('param-name') name_section.write('- ') if name is not None: name_section.style.bold('%s ' % name) type_section = section.add_new_section('param-type') type_section.style.italics('(%s) -- ' % py_type) if is_required: is_required_section = section.add_new_section('is-required') is_required_section.style.indent() is_required_section.style.bold('[REQUIRED] ') if shape.documentation: documentation_section = section.add_new_section( 'param-documentation') documentation_section.style.indent() documentation_section.include_doc_string(shape.documentation) end_param_section = section.add_new_section('end-param') end_param_section.style.new_paragraph()
def _document_non_top_level_param_type(self, type_section, shape): special_py_type = self._get_special_py_type_name(shape) py_type = py_type_name(shape.type_name) type_format = '(%s) -- ' if special_py_type is not None: # Special type can reference a linked class. # Italicizing it blows away the link. type_section.write(type_format % special_py_type) else: type_section.style.italics(type_format % py_type)
def _add_member_documentation(self, section, shape, name=None, **kwargs): py_type = py_type_name(shape.type_name) name_section = section.add_new_section("param-name") name_section.write("- ") if name is not None: name_section.style.bold("%s " % name) type_section = section.add_new_section("param-type") type_section.style.italics("(%s) -- " % py_type) documentation_section = section.add_new_section("param-documentation") if shape.documentation: documentation_section.style.indent() documentation_section.include_doc_string(shape.documentation) section.style.new_paragraph()
def _add_member_documentation(self, section, shape, name=None, **kwargs): py_type = py_type_name(shape.type_name) name_section = section.add_new_section('param-name') name_section.write('- ') if name is not None: name_section.style.bold('%s ' % name) type_section = section.add_new_section('param-type') type_section.style.italics('(%s) -- ' % py_type) documentation_section = section.add_new_section('param-documentation') if shape.documentation: documentation_section.style.indent() documentation_section.include_doc_string(shape.documentation) section.style.new_paragraph()
def _add_member_documentation(self, section, shape, name=None, is_top_level_param=False, is_required=False, **kwargs): py_type = self._get_special_py_type_name(shape) if py_type is None: py_type = py_type_name(shape.type_name) if is_top_level_param: type_section = section.add_new_section('param-type') type_section.write(':type %s: %s' % (name, py_type)) end_type_section = type_section.add_new_section('end-param-type') end_type_section.style.new_line() name_section = section.add_new_section('param-name') name_section.write(':param %s: ' % name) else: name_section = section.add_new_section('param-name') name_section.write('- ') if name is not None: name_section.style.bold('%s ' % name) type_section = section.add_new_section('param-type') self._document_non_top_level_param_type(type_section, shape) if is_required: is_required_section = section.add_new_section('is-required') is_required_section.style.indent() is_required_section.style.bold('[REQUIRED] ') if shape.documentation: documentation_section = section.add_new_section( 'param-documentation') documentation_section.style.indent() if getattr(shape, 'is_tagged_union', False): tagged_union_docs = section.add_new_section( 'param-tagged-union-docs' ) note = ( '.. note::' ' This is a Tagged Union structure. Only one of the ' ' following top level keys can be set: %s. ' ) tagged_union_members_str = ', '.join( ['``%s``' % key for key in shape.members.keys()] ) tagged_union_docs.write(note % (tagged_union_members_str)) documentation_section.include_doc_string(shape.documentation) self._add_special_trait_documentation(documentation_section, shape) end_param_section = section.add_new_section('end-param') end_param_section.style.new_paragraph()
def _add_member_documentation(self, section, shape, name=None, **kwargs): py_type = py_type_name(shape.type_name) name_section = section.add_new_section('param-name') name_section.write('- ') if name is not None: name_section.style.bold('%s ' % name) type_section = section.add_new_section('param-type') if self._context.get('streaming_shape') == shape: type_section.write('(:class:`.StreamingBody`) -- ') else: type_section.style.italics('(%s) -- ' % py_type) documentation_section = section.add_new_section('param-documentation') if shape.documentation: documentation_section.style.indent() documentation_section.include_doc_string(shape.documentation) section.style.new_paragraph()
def test_blob(self): self.assertEqual('bytes', py_type_name('blob'))
def test_float(self): self.assertEqual('float', py_type_name('float'))
def test_integer(self): self.assertEqual('integer', py_type_name('integer'))
def test_double(self): self.assertEqual('float', py_type_name('double'))
def test_long(self): self.assertEqual('integer', py_type_name('long'))
def document_attribute(section, attr_name, attr_model, include_signature=True): if include_signature: section.style.start_sphinx_py_attr(attr_name) attr_type = '*(%s)* ' % py_type_name(attr_model.type_name) section.write(attr_type) section.include_doc_string(attr_model.documentation)
def test_timestamp(self): self.assertEqual('datetime', py_type_name('timestamp'))
def test_list(self): self.assertEqual('list', py_type_name('list'))
def test_string(self): self.assertEqual('string', py_type_name('string'))
def test_structure(self): self.assertEqual('dict', py_type_name('structure'))
def test_map(self): self.assertEqual('dict', py_type_name('map'))
def test_character(self): self.assertEqual('string', py_type_name('character'))