File: reference.py

package info (click to toggle)
python-asdf 4.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 7,032 kB
  • sloc: python: 24,068; makefile: 123
file content (23 lines) | stat: -rw-r--r-- 711 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from asdf.extension import Converter


class ReferenceConverter(Converter):
    tags = []
    types = ["asdf.reference.Reference"]

    def to_yaml_tree(self, obj, tag, ctx):
        from asdf.generic_io import relative_uri

        base_uri = None
        if ctx._blocks._write_fd is not None and ctx._blocks._write_fd.uri is not None:
            base_uri = ctx._blocks._write_fd.uri
        elif ctx.url is not None:
            base_uri = ctx.url
        uri = relative_uri(base_uri, obj._uri) if base_uri is not None else obj._uri
        return {"$ref": uri}

    def from_yaml_tree(self, node, tag, ctx):
        raise NotImplementedError()

    def select_tag(self, obj, tags, ctx):
        return None