def to_python(self, value): """ db to code; int to Version """ if isinstance(value, Version): return value if isinstance(value, str): return Version(value) if value is None: return None return Version(Version.int_to_string(value))
def get_name_and_version_from_key(key): """ given a string representing some QOntology key, splits it into its constituent parts: a name and a version note that the version in the key can be underspecified (for example, "1.10" should match "1.10.0" :param key: :return: """ match = re.match("^(.*)_(\d+\.\d+\.\d+|\d+\.\d+|\d+)$", key) # not the most elegant regex, but you get the point if not match: msg = "'{0}' is an invalid key; it should be of the format 'name_version'".format( key) raise QError(msg) name, underspecified_version = match.groups() version = Version(underspecified_version).fully_specified() return name, version