/usr/lib/python3/dist-packages/asdf/versioning.py is in python3-asdf 1.2.1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | # Licensed under a 3-clause BSD style license - see LICENSE.rst
# -*- coding: utf-8 -*-
"""
This module deals with things that change between different versions
of the ASDF spec.
"""
from __future__ import absolute_import, division, unicode_literals, print_function
import six
import yaml
if getattr(yaml, '__with_libyaml__', None): # pragma: no cover
_yaml_base_loader = yaml.CSafeLoader
else: # pragma: no cover
_yaml_base_loader = yaml.SafeLoader
from .extern import semver
from . import generic_io
from . import resolver
from . import util
_version_map = {}
def get_version_map(version):
version_map = _version_map.get(version)
if version_map is None:
version_map_path = resolver.DEFAULT_URL_MAPPING[0][1].replace(
'{url_suffix}', 'asdf/version_map-{0}'.format(version))
try:
with generic_io.get_file(version_map_path, 'r') as fd:
version_map = yaml.load(
fd, Loader=_yaml_base_loader)
except:
version_string = version_to_string(version)
raise ValueError(
"Could not load version map for version {0}".format(version_string))
_version_map[version] = version_map
return version_map
def version_to_string(ver):
if isinstance(ver, six.string_types):
return ver
elif isinstance(ver, dict):
return semver.format_version(**ver)
elif isinstance(ver, (tuple, list)):
return semver.format_version(*ver)
else:
raise TypeError("Bad type for version {0}".format(ver))
default_version = semver.parse('1.0.0')
supported_versions = [
'1.0.0'
]
class VersionedMixin(object):
_version = default_version
_version_string = version_to_string(default_version)
@property
def version(self):
return self._version
@version.setter
def version(self, version):
if version_to_string(version) not in supported_versions:
human_versions = util.human_list(
[version_to_string(x) for x in supported_versions])
raise ValueError(
"asdf only understands how to handle ASDF versions {0}. "
"Got '{1}'".format(
human_versions,
version_to_string(version)))
self._version = version
self._version_string = version_to_string(version)
@property
def version_string(self):
return self._version_string
@property
def version_map(self):
try:
version_map = get_version_map(self.version_string)
except ValueError:
raise ValueError(
"Don't have information about version {0}".format(
self.version_string))
return version_map
|