def _print_client(client, html=False): """ Given a BaseClient instance will print out each registered attribute. Parameters ---------- client : `sunpy.net.base_client.BaseClient` The instance class to print for. html : bool Will return a html table instead. Returns ------- `str` String with the client. """ width = -1 if html else get_width() class_name = f"{client.__module__+'.' or ''}{client.__class__.__name__}" attrs = client.register_values() lines = [] t = Table(names=["Attr Type", "Name", "Description"], dtype=["U80", "U80", "U80"]) for client_key in attrs.keys(): for name, desc in attrs[client_key]: t.add_row((client_key.__name__, name, desc)) lines = [class_name, dedent(client.__doc__.partition("\n\n")[0])] if html: lines = [f"<p>{line}</p>" for line in lines] lines.extend( t.pformat_all(show_dtype=False, max_width=width, align="<", html=html)) return '\n'.join(lines)
def _print_client(client, html=False, visible_entries=None): """ Given a BaseClient instance will print out each registered attribute. Parameters ---------- client : BaseClient The instance class to print for. html : bool Will return a html table instead. Returns ------- `str` String with the client. """ width = -1 if html else get_width() class_name = f"{client.__module__+'.' or ''}{client.__class__.__name__}" attrs = client.register_values() lines = [] t = Table(names=["Attr Type", "Name", "Description"], dtype=["U80", "U80", "U80"]) for client_key in attrs.keys(): # Work around for * attrs having one length. if len(attrs[client_key]) == 1 and attrs[client_key][0] == "*": t.add_row((client_key.__name__, "All", "All valid values")) continue for name, desc in attrs[client_key]: t.add_row((client_key.__name__, name, desc)) lines = [class_name, dedent(client.__doc__.partition("\n\n")[0])] if html: lines = [f"<p>{line}</p>" for line in lines] lines.extend(t.pformat_all(max_lines=visible_entries, show_dtype=False, max_width=width, align="<", html=html)) return '\n'.join(lines)
def _print_clients(self, html=False) -> str: width = -1 if html else get_width() t = Table(names=["Client", "Description"], dtype=["U80", "U120"]) lines = ["sunpy.net.Fido", dedent(self.__doc__)] if html: lines = [f"<p>{line}</p>" for line in lines] for key in BaseClient._registry.keys(): t.add_row((key.__name__, dedent( key.__doc__.partition("\n\n")[0].replace("\n ", " ")))) lines.extend(t.pformat_all(show_dtype=False, max_width=width, align="<", html=html)) return '\n'.join(lines)
def _print_attrs(attr, html=False): """ Given a Attr class will print out each registered attribute. Parameters ---------- attr : `sunpy.net.attr.Attr` The attr class/type to print for. html : bool Will return a html table instead. Returns ------- `str` String with the registered attributes. """ class_name = f"{attr.__module__+'.' or ''}{attr.__name__}" attrs = attr._attr_registry[attr] sorted_attrs = make_tuple() # Only sort the attrs if any have been registered if attrs.name: sorted_attrs = _ATTR_TUPLE(*zip(*sorted(zip(*attrs)))) names = sorted_attrs.name clients = sorted_attrs.client names_long = sorted_attrs.name_long descs = sorted_attrs.desc descs = [x[:77] + '...' if len(x) > 80 else x for x in descs] lines = [] t = Table(names=["Attribute Name", "Client", "Full Name", "Description"], dtype=["U80", "U80", "U80", "U80"]) for name, client, name_long, desc in zip(names, clients, names_long, descs): t.add_row((name, client, name_long, desc)) lines.insert(0, class_name) # If the attr lacks a __doc__ this will error and prevent this from returning anything. try: lines.insert(1, dedent(attr.__doc__.partition("\n\n")[0]) + "\n") except AttributeError: pass if html: lines = [f"<p>{line}</p>" for line in lines] width = -1 if html else get_width() lines.extend( t.pformat_all(show_dtype=False, max_width=width, align="<", html=html)) return '\n'.join(lines)
def _print_attrs(attr, html=False): """ Given a Attr class will print out each registered attribute. Parameters ---------- attr : `sunpy.net.attr.Attr` The attr class/type to print for. html : bool Will return a html table instead. Returns ------- `str` String with the registered attributes. """ attrs = attr._attr_registry[attr] # Only sort the attrs if any have been registered sorted_attrs = _ATTR_TUPLE(*zip(*sorted(zip( *attrs)))) if attrs.name else make_tuple() *other_row_data, descs = sorted_attrs descs = [(dsc[:77] + '...') if len(dsc) > 80 else dsc for dsc in descs] table = Table( names=["Attribute Name", "Client", "Full Name", "Description"], dtype=["U80", "U80", "U80", "U80"], data=[*other_row_data, descs]) class_name = f"{(attr.__module__ + '.') or ''}{attr.__name__}" lines = [class_name] # If the attr lacks a __doc__ this will error and prevent this from returning anything. try: lines.append(dedent(attr.__doc__.partition("\n\n")[0]) + "\n") except AttributeError: pass format_line = "<p>{}</p>" if html else "{}" width = -1 if html else get_width() lines = [ *[format_line.format(line) for line in lines], *table.pformat_all( show_dtype=False, max_width=width, align="<", html=html) ] return '\n'.join(lines)