def _InferenceAPI_dumper(dumper: yaml.Dumper, api: InferenceAPI) -> yaml.Node: return dumper.represent_dict({ "route": api.route, "doc": api.doc, "input": api.input.__class__.__name__, "output": api.output.__class__.__name__, })
def yaml_representer(dumper: yaml.Dumper, instance): output = [] if instance.comments is not None and len(instance.comments) > 0: output.append(('comments', instance.comments)) if instance.additional_urls is not None and len( instance.additional_urls) > 0: output.append(('additional_urls', instance.additional_urls)) return dumper.represent_dict(output)
def _represent_root_certificate_entry(dumper: yaml.Dumper, entry: RootCertificateRecord) -> yaml.Node: # TODO(AD): this seems to maintain order for fields because dicts in Python 3.6 keep the order - it "should not be # relied upon" but let's rely on it anyway for now final_dict = { 'subject_name': entry.subject_name, 'fingerprint': entry.hex_fingerprint, } return dumper.represent_dict(final_dict.items())
def repr_odict(dumper: Dumper, data: ODict) -> str: """A YAML Representer for cfn-flip's ODict objects. ODicts are a variation on OrderedDicts for that library. Since the Diff command makes extensive use of ODicts, they can end up in diff output and the PyYaml library doesn't otherwise calls the dicts like !!ODict, which looks weird. We can just treat them like normal dicts when we serialize them, though. :param dumper: The Dumper that is being used to serialize this object :param data: The ODict object to serialize :return: The serialized ODict """ return dumper.represent_dict(data)
def _get_string_node( self, dumper: yaml.Dumper, value: Union["_Function", str], tag: str ) -> yaml.Node: """Get a PyYAML node for a function that returns a string. Lots of the intrinsic functions take a single string as the argument, which we echo directly into the output. However, in CloudFormation, this string could be a reference to another function rather than a literal string, and that needs to be handled specially. """ if isinstance(value, _Function): return dumper.represent_dict({f"Fn::{tag}": value}) else: # TODO be able to control the scalar output, perhaps # TODO use represent_string instead, perhaps return dumper.represent_scalar(f"!{tag}", value, style="")
def _represent_trust_store(dumper: yaml.Dumper, store: TrustStore) -> yaml.Node: # Always sort the certificates alphabetically so it is easy to diff the list sorted_trusted_certs = sorted(store.trusted_certificates, key=attrgetter('subject_name', 'hex_fingerprint')) sorted_blocked_certs = sorted(store.blocked_certificates, key=attrgetter('subject_name', 'hex_fingerprint')) # TODO(AD): this seems to maintain order for fields because dicts in Python 3.6 keep the order - it "should not be # relied upon" but let's rely on it anyway for now final_dict = { 'platform': store.platform.name, 'version': store.version, 'url': store.url, 'date_fetched': store.date_fetched, 'trusted_certificates_count': store.trusted_certificates_count, 'trusted_certificates': sorted_trusted_certs, 'blocked_certificates_count': store.blocked_certificates_count, 'blocked_certificates': sorted_blocked_certs, } return dumper.represent_dict(final_dict.items())
def _ModelInfo_dumper(dumper: yaml.Dumper, info: ModelInfo) -> yaml.Node: return dumper.represent_dict(info.to_dict())
def dict_representer(dumper: yaml.Dumper, data: OrderedDict): return dumper.represent_dict(data.items())
def yaml_representer(dumper: yaml.Dumper, additional_url): return dumper.represent_dict(additional_url)
def yaml_representer(dumper: yaml.Dumper, instance_list): return dumper.represent_dict(instance_list)
def kgobject_representer(dumper: yaml.Dumper, data: Object): return dumper.represent_dict(data)
def _yaml_represent_raw_bson_document(dumper: yaml.Dumper, data: RawBSONDocument) -> dict: dict_data = _convert_bson_doc(data) return dumper.represent_dict(dict_data)