Пример #1
0
def reverse_lookup(enum, value, version=None):
    mnemonic = None

    if not version:
        version = get_version()

    for entry in data.get(enum.name, []):
        if entry['_version'] > version:
            break
        lookup = dict((entry[k], k) for k in entry)
        mnemonic = getattr(enum, lookup.get(value))

    return mnemonic
Пример #2
0
def reverse_lookup(enum, value, version=None):
    mnemonic = None

    if not version:
        version = get_version()

    for entry in data.get(enum.name, []):
        if entry['_version'] > version:
            break
        lookup = dict((entry[k], k) for k in entry)
        mnemonic = getattr(enum, lookup.get(value))

    return mnemonic
Пример #3
0
def lookup(mnemonic, enum=None, version=None, throw=True):
    if enum:
        mnemonic = enum.cast(mnemonic)

    if not version:
        version = get_version()

    value = None

    for entry in data.get(mnemonic.enum.name, []):
        if entry['_version'] > version:
            break
        value = entry.get(mnemonic.name)

    if value is None and throw:
        template = "Enumeration '{enum}' cannot map mnemonic '{mnemonic}'"
        template = formattable(template)
        enum = mnemonic.enum.name
        mnemonic = mnemonic.name
        raise PystaciaException(template.format(enum=enum, mnemonic=mnemonic))

    return value
Пример #4
0
def lookup(mnemonic, enum=None, version=None, throw=True):
    if enum:
        mnemonic = enum.cast(mnemonic)

    if not version:
        version = get_version()

    value = None

    for entry in data.get(mnemonic.enum.name, []):
        if entry['_version'] > version:
            break
        value = entry.get(mnemonic.name)

    if value is None and throw:
        template = "Enumeration '{enum}' cannot map mnemonic '{mnemonic}'"
        template = formattable(template)
        enum = mnemonic.enum.name
        mnemonic = mnemonic.name
        raise PystaciaException(template.format(enum=enum, mnemonic=mnemonic))

    return value
Пример #5
0
 def test_version(self):
     self.assertIsInstance(get_version(), (tuple, type(None)))
     self.assertIsInstance(get_version_str(), string_types)
Пример #6
0
 def test_version(self):
     self.assertIsInstance(get_version(), (tuple, type(None)))
     self.assertIsInstance(get_version_str(), string_types)